Skip to main content

MetricsReader

Struct MetricsReader 

Source
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<'_>

Source

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.

Source

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).

Trait Implementations§

Source§

impl<'a> Debug for MetricsReader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for MetricsReader<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> !Send for MetricsReader<'a>

§

impl<'a> !Sync for MetricsReader<'a>

§

impl<'a> Freeze for MetricsReader<'a>

§

impl<'a> RefUnwindSafe for MetricsReader<'a>

§

impl<'a> Unpin for MetricsReader<'a>

§

impl<'a> UnsafeUnpin for MetricsReader<'a>

§

impl<'a> UnwindSafe for MetricsReader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.