Skip to content

itchyny/mackerel-plugin-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mackerel-plugin-rs

CI Status crates.io MIT License

ー Mackerel plugin helper library for Rust ー

Plugin samples

Plugins using this library.

Example

use mackerel_plugin::*;
use std::collections::HashMap;

struct DicePlugin {}

impl Plugin for DicePlugin {
    fn fetch_metrics(&self) -> Result<HashMap<String, f64>, String> {
        Ok(HashMap::from([
            ("dice.d6".to_owned(), (rand::random::<u64>() % 6 + 1) as f64),
            ("dice.d20".to_owned(), (rand::random::<u64>() % 20 + 1) as f64),
        ]))
    }

    fn graph_definition(&self) -> Vec<Graph> {
        vec![
            graph! {
                name: "dice",
                label: "My Dice",
                unit: "integer",
                metrics: [
                    { name: "d6", label: "Die 6" },
                    { name: "d20", label: "Die 20" },
                ],
            },
        ]
    }
}

fn main() {
    if let Err(err) = (DicePlugin {}).run() {
        eprintln!("mackerel-plugin-dice: {}", err);
        std::process::exit(1);
    }
}

Author

itchyny (https://github.com/itchyny)

License

This software is released under the MIT License, see LICENSE.