pub struct Level { /* private fields */ }
Expand description
A counter of fluctuating resources accepting positive and negative values.
Can be used as a stateful Gauge
or as a Counter
of possibly decreasing amounts.
- Size of messages in a queue
- Strawberries on a conveyor belt If aggregated, minimum and maximum scores will track the sum of values, not the collected values themselves.
Implementations§
source§impl Level
impl Level
sourcepub fn adjust<V: ToPrimitive>(&self, count: V)
pub fn adjust<V: ToPrimitive>(&self, count: V)
Record a positive or negative value count
Examples found in repository?
examples/basics.rs (line 28)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
fn main() {
// for this demo, print metric values to the console
let app_metrics = Stream::write_to(io::stdout()).metrics();
// metrics can be predefined by type and name
let counter = app_metrics.counter("counter_a");
let level = app_metrics.level("level_a");
let timer = app_metrics.timer("timer_b");
// metrics can also be declared and used ad-hoc (use output.cache() if this happens often)
app_metrics.counter("just_once").count(4);
// metric names can be prepended with a common prefix
let prefixed_metrics = app_metrics.named("subsystem");
let event = prefixed_metrics.marker("event_c");
let gauge = prefixed_metrics.gauge("gauge_d");
// each kind of metric has a different method name to prevent errors
counter.count(11);
level.adjust(-4);
level.adjust(5);
gauge.value(22);
gauge.value(-24);
event.mark();
// time can be measured multiple equivalent ways:
// in microseconds (used internally)
timer.interval_us(35573);
// using the time! macro
time!(timer, sleep(Duration::from_millis(5)));
// using a closure
timer.time(|| sleep(Duration::from_millis(5)));
// using a "time handle"
let start_time = timer.start();
sleep(Duration::from_millis(5));
timer.stop(start_time);
}
Methods from Deref<Target = InputMetric>§
sourcepub fn write(&self, value: MetricValue, labels: Labels)
pub fn write(&self, value: MetricValue, labels: Labels)
Collect a new value for this metric.
Trait Implementations§
source§impl From<InputMetric> for Level
impl From<InputMetric> for Level
source§fn from(metric: InputMetric) -> Level
fn from(metric: InputMetric) -> Level
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for Level
impl !RefUnwindSafe for Level
impl Send for Level
impl Sync for Level
impl Unpin for Level
impl !UnwindSafe for Level
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more