Enum prometheus_client::metrics::MetricType
source · pub enum MetricType {
Counter,
Gauge,
Histogram,
Info,
Unknown,
}
Expand description
OpenMetrics metric type.
Variants§
Implementations§
source§impl MetricType
impl MetricType
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the given metric type’s str representation.
Examples found in repository?
src/encoding/text.rs (line 59)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
pub fn encode<W>(writer: &mut W, registry: &Registry) -> Result<(), std::fmt::Error>
where
W: Write,
{
for (desc, metric) in registry.iter() {
writer.write_str("# HELP ")?;
writer.write_str(desc.name())?;
if let Some(unit) = desc.unit() {
writer.write_str("_")?;
writer.write_str(unit.as_str())?;
}
writer.write_str(" ")?;
writer.write_str(desc.help())?;
writer.write_str("\n")?;
writer.write_str("# TYPE ")?;
writer.write_str(desc.name())?;
if let Some(unit) = desc.unit() {
writer.write_str("_")?;
writer.write_str(unit.as_str())?;
}
writer.write_str(" ")?;
writer.write_str(EncodeMetric::metric_type(metric.as_ref()).as_str())?;
writer.write_str("\n")?;
if let Some(unit) = desc.unit() {
writer.write_str("# UNIT ")?;
writer.write_str(desc.name())?;
writer.write_str("_")?;
writer.write_str(unit.as_str())?;
writer.write_str(" ")?;
writer.write_str(unit.as_str())?;
writer.write_str("\n")?;
}
let encoder = MetricEncoder {
writer,
name: desc.name(),
unit: desc.unit(),
const_labels: desc.labels(),
family_labels: None,
}
.into();
EncodeMetric::encode(metric.as_ref(), encoder)?;
}
writer.write_str("# EOF\n")?;
Ok(())
}
Trait Implementations§
source§impl Clone for MetricType
impl Clone for MetricType
source§fn clone(&self) -> MetricType
fn clone(&self) -> MetricType
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more