mackerel_plugin_uptime/
lib.rs1use mackerel_plugin::{graph, Graph, Plugin};
2use std::collections::HashMap;
3
4pub struct UptimePlugin {}
5
6impl Plugin for UptimePlugin {
7 fn fetch_metrics(&self) -> Result<HashMap<String, f64>, String> {
8 Ok(HashMap::from([(
9 "uptime.uptime".to_owned(),
10 uptime_lib::get()
11 .map_err(|err| err.to_string())?
12 .as_secs_f64(),
13 )]))
14 }
15
16 fn graph_definition(&self) -> Vec<Graph> {
17 vec![graph! {
18 name: "uptime",
19 label: "Uptime",
20 unit: "seconds",
21 metrics: [
22 { name: "uptime", label: "uptime" },
23 ],
24 }]
25 }
26}