Struct dipstick::ObserveWhen
source · pub struct ObserveWhen<'a, T, F> { /* private fields */ }
Expand description
When to observe a recurring task.
Implementations§
source§impl<'a, T, F> ObserveWhen<'a, T, F>where
F: Fn(Instant) -> MetricValue + Send + Sync + 'static,
T: InputScope + WithAttributes + Send + Sync,
impl<'a, T, F> ObserveWhen<'a, T, F>where
F: Fn(Instant) -> MetricValue + Send + Sync + 'static,
T: InputScope + WithAttributes + Send + Sync,
sourcepub fn on_flush(self) -> OnFlushCancel
pub fn on_flush(self) -> OnFlushCancel
Observe the metric’s value upon flushing the scope.
Examples found in repository?
examples/observer.rs (line 26)
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
fn main() {
let metrics = AtomicBucket::new().named("process");
metrics.drain(Stream::write_to_stdout());
metrics.flush_every(Duration::from_secs(3));
let uptime = metrics.gauge("uptime");
metrics.observe(uptime, |_| 6).on_flush();
// record number of threads in pool every second
let scheduled = metrics
.observe(metrics.gauge("threads"), thread_count)
.every(Duration::from_secs(1));
// "heartbeat" metric
let on_flush = metrics
.observe(metrics.marker("heartbeat"), |_| 1)
.on_flush();
for _ in 0..1000 {
std::thread::sleep(Duration::from_millis(40));
}
on_flush.cancel();
scheduled.cancel();
}
sourcepub fn every(self, period: Duration) -> CancelHandle
pub fn every(self, period: Duration) -> CancelHandle
Observe the metric’s value periodically.
Examples found in repository?
examples/observer.rs (line 31)
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
fn main() {
let metrics = AtomicBucket::new().named("process");
metrics.drain(Stream::write_to_stdout());
metrics.flush_every(Duration::from_secs(3));
let uptime = metrics.gauge("uptime");
metrics.observe(uptime, |_| 6).on_flush();
// record number of threads in pool every second
let scheduled = metrics
.observe(metrics.gauge("threads"), thread_count)
.every(Duration::from_secs(1));
// "heartbeat" metric
let on_flush = metrics
.observe(metrics.marker("heartbeat"), |_| 1)
.on_flush();
for _ in 0..1000 {
std::thread::sleep(Duration::from_millis(40));
}
on_flush.cancel();
scheduled.cancel();
}
Auto Trait Implementations§
impl<'a, T, F> Freeze for ObserveWhen<'a, T, F>
impl<'a, T, F> !RefUnwindSafe for ObserveWhen<'a, T, F>
impl<'a, T, F> Send for ObserveWhen<'a, T, F>
impl<'a, T, F> Sync for ObserveWhen<'a, T, F>
impl<'a, T, F> Unpin for ObserveWhen<'a, T, F>
impl<'a, T, F> !UnwindSafe for ObserveWhen<'a, T, F>
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