pub struct MetricsReader<'a> { /* private fields */ }Expand description
The VSC (Varnish Shared Counter) is a way for outside programs to access Varnish statistics in a
non-blocking way. The main way to access those counters traditionally is with varnishstat,
but the API is generic and allows you to track, filter and read any counter that varnishd
(and vmods) are exposing.
use varnish::MetricsReaderBuilder;
fn main() {
let mut reader = MetricsReaderBuilder::new().build().unwrap_or_else(|e| {
eprintln!("Error: {e}");
std::process::exit(1);
});
reader.update();
for stat in reader.stats().values() {
println!("{}: {}", stat.name, stat.get_raw_value());
}
}Implementations§
Source§impl MetricsReader<'_>
impl MetricsReader<'_>
Sourcepub fn stats(&self) -> &HashMap<usize, Metric<'_>>
pub fn stats(&self) -> &HashMap<usize, Metric<'_>>
Return a statistic set
Names are not necessarily unique, so instead, statistics are tracked using usize handle
that can help you track which ones (dis)appeared during a MetricsReader::update() call.
The C API guarantees we can access all the Stat in the HashMap, until the next update
call, so the rust API mirrors this here.
Sourcepub fn update(&mut self) -> (Vec<usize>, Vec<usize>)
pub fn update(&mut self) -> (Vec<usize>, Vec<usize>)
Update the list of Stat we have access to
You must call this function at least once to get access to any data (otherwise you’ll just
get an empty HashMap).
The two returned Vecs list the added and deleted keys in the HashMap, in case you need
to keep track of them at an individual level.
(if a key appears in both Vecs, the statistic got replaced).