pub struct ScientificEncoder;Expand description
A Prometheus text-format encoder that renders counter values in scientific
notation ({:.10E}) and appends a trailing comma after the last label.
This matches the output format produced by Kafka’s JMX-to-Prometheus exporters, making it useful for dashboards that expect that convention.
§Example
use prometheus::Opts;
use prometheus::core::Collector;
use prometheus_extensions::{AggregateCounter, ScientificEncoder};
let counter = AggregateCounter::new(
Opts::new("bytes_in", "Bytes received"),
&["topic"],
).unwrap();
counter.with_label_values(&["events"]).inc_by(4.6384186519e10);
let families = counter.collect();
let encoder = ScientificEncoder::new();
let mut buf = Vec::new();
encoder.encode(&families, &mut buf).unwrap();
let output = String::from_utf8(buf).unwrap();
assert!(output.contains("bytes_in{topic=\"events\",}"));
assert!(output.contains("E10"));Implementations§
Trait Implementations§
Source§impl Default for ScientificEncoder
impl Default for ScientificEncoder
Source§fn default() -> ScientificEncoder
fn default() -> ScientificEncoder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ScientificEncoder
impl RefUnwindSafe for ScientificEncoder
impl Send for ScientificEncoder
impl Sync for ScientificEncoder
impl Unpin for ScientificEncoder
impl UnsafeUnpin for ScientificEncoder
impl UnwindSafe for ScientificEncoder
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