Skip to content

Parsing and creating monitoring check performance data from and for monitoring engines

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

benjamingroeber/perfdata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Perfdata (Performance Data)

Github Tag Crates.io GH Actions Status Documentation

This library was created to fit basic needs for parsing and creating Performance Data commonly used by check commands from monitoring engines like Icinga2 or Nagios.

I'm using this in close-to-production software, but would generally consider this library still in a pre-stable stage, since it's still evolving.

Usage

Usually you will want to create performance data in check commands called by monitoring engines, after executing the command from the data collected.

// simple label with a value
let perfdata = Perfdata::unit("label", 23);

// with warn, crit, min and max thresholds
let with_thresholds = Perfdata::unit("thresholds", 42)
    .with_warn(ThresholdRange::inside(33,50))
    .with_crit(ThresholdRange::above(50))
    .with_min(0)
    .with_max(100);

// check thresholds
if with_thresholds.is_warn() {
    println("{} in warning threshold", with_threshold.label())
}
if with_thresholds.is_crit() {
    println("{} in critical threshold", with_threshold.label())
}
   

Perfdata can be created with several units of measurements. And will be formatted to the spec of the Nagios Plugin Development Guidelines.

// This will be formatted as 'seconds_label'=10s
Perfdata::seconds("seconds_label", 10);

// This will be formatted as 'percent_label'=50%
Perfdata::percent("percent_label", 50);

// This will be formatted as 'bytes_label'=23b
Perfdata::bytes("bytes_label", 23);

// This will be formatted as 'counter'=10c;@20:30;30;0;100
Perfdata::counter("counter", 10)
  .with_warn(ThresholdRange::inside(20,30))
  .with_crit(ThresholdRange::above_pos(30))
  .with_min(0)
  .with_max(100);

Multiple Perfdata points can be combined into a PerfdataSet, which provides some utilities for usage in monitoring checks, most notably the MonitoringStatus enum.

// PerfdataSets can be built from iterators over Perfdata
let mut pds: PerfdataSet = [Perfdata::unit("this is fine", 42), Perfdata::percent("this is also fine")].iter().collect();
let critical = Perfdata::unit(100).with_crit(ThresholdRange::above(50));

// Additional perfdata can be added
pds.add(critical);

// This is MonitoringStatus::Critical
let status = pds.status;()

// Exit with code 2, interpreted by most monitoring engines as "critical" check result
std::process::exit(status.exit_code());

This library provides also a basic parser, for dealing with perfdata generated by one of the myriad of check commands for common monitoring engines.

let input = "'some perf'=42;@75:80;80";
let perfdata = Perfdata::try_from(input).unwrap();

Usually more than one Performance Datapoint are generated in a space delimited list. These can be parsed using PerfdataSet::try_from();

let input = "'some perf'=42;66;75;0;100; 'foo'=23 bar=10"
let pds = PerfdataSet::try_from(input).unwrap();

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Parsing and creating monitoring check performance data from and for monitoring engines

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Languages