Function prometheus_wire::parser::try_read_sample [−][src]
pub fn try_read_sample(line: &str) -> Option<SampleData>
Tries to parse a &str
line as a sample and returns SampleData
containg the metric name, labels and value if it succeeds.
Examples:
use prometheus_wire::parser::{SampleData, LabelList, try_read_sample}; use std::collections::HashMap; let line = r#"http_requests_total{method="post",code="200"} 1.5e3 1395066363000"#; let opt_metric = try_read_sample(line); let mut map = HashMap::new(); map.insert(String::from("method"), String::from("post")); map.insert(String::from("code"), String::from("200")); assert_eq!( opt_metric, Some(SampleData::new( String::from("http_requests_total"), LabelList::from_map(map), 1500.0, Some(1395066363000)) )); let metric = opt_metric.unwrap(); assert_eq!(metric.labels.get_string("method"), Some(&String::from("post"))); assert_eq!(metric.labels.get_number("code"), Some(200.0)); assert_eq!(try_read_sample("# test"), None);