metrics-rs / metrics

A metrics ecosystem for Rust.
MIT License
1.08k stars 148 forks source link

Question: How to use metrics for u64 or f32 #406

Closed mh-trimble closed 10 months ago

mh-trimble commented 10 months ago

Hi I am fairly new to rust and was porting an internal service, one of the goals I've set for myself was to do report some system metrics to datadog, using https://github.com/sevco/metrics-datadog-exporter-rs.

Some of the metrics from https://docs.rs/self-meter/latest/self_meter/ are process cpu usage f32 and process memory usage u64 which don't implement the IntoF64 trait.

47  |                         gauge!("process.cpu_usage", report.process_cpu_usage);
    |                         ----------------------------^^^^^^^^^^^^^^^^^^^^^^^^-
    |                         |                           |
    |                         |                           the trait `IntoF64` is not implemented for `f32`
    |                         required by a bound introduced by this call
    = help: the trait `IntoF64` is implemented for `f64`
note: required by a bound in `metrics::Gauge::set`

So how would I go about to report these?

mh-trimble commented 10 months ago

Playing around with it and trying to write a meaningful questions I came up with the solution myself:

I think for u64 I can use a counter, for some reason I was thinking u64 being an unsigned f32 (insert picard facepalming here).

And for the f32 case I can use Into::<f64>::into(report.process_cpu_usage).