Expand description
Configuration support for the dipstick metrics library.
This provides a configuration Fragment for the spirit family of libraries. It
configures the „backend“ part of the library ‒ the part that sends the metrics somewhere, like
to statsd or a file.
§Examples
use dipstick::{stats_all, InputScope};
use serde::Deserialize;
use spirit::{Empty, Pipeline, Spirit};
use spirit::prelude::*;
use spirit_dipstick::{Config as MetricsConfig, Monitor};
#[derive(Debug, Default, Deserialize)]
struct Cfg {
metrics: MetricsConfig,
}
impl Cfg {
fn metrics(&self) -> &MetricsConfig {
&self.metrics
}
}
const CFG: &str = r#"
[metrics]
prefix = "example" # If omitted, the name of the application is used
flush-period = "5s" # Dump metric statistics every 5 seconds
backends = [
{ type = "file", filename = "/tmp/metrics.txt" },
{ type = "stdout" },
]
"#;
fn main() {
let root = Monitor::new();
Spirit::<Empty, Cfg>::new()
.config_defaults(CFG)
.with(
Pipeline::new("metrics")
.extract_cfg(Cfg::metrics)
.install(root.installer(stats_all)),
)
.run(move |_| {
let counter = root.counter("looped");
counter.count(1);
Ok(())
});
}Structs§
- Backends
- An intermediate resource produced by
Config. - Config
- The
Fragmentto configuredipsticks backends. - Monitor
- An inner node in a metrics tree.
- Monitor
Installer - The
Installerof backends into theMonitor. - Uninstaller
- An uninstall handle for backends.