Function prometheus_http_query::functions::histogram_quantile
source · [−]pub fn histogram_quantile(quantile: f64, vector: InstantVector) -> InstantVector
Expand description
Apply the PromQL histogram_quantile
function.
use prometheus_http_query::{Client, Selector, RangeVector};
use prometheus_http_query::functions::{histogram_quantile, rate};
use std::convert::TryInto;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), prometheus_http_query::Error> {
let client = Client::default();
let vector: RangeVector = Selector::new()
.metric("prometheus_http_request_duration_seconds_bucket")
.with("job", "prometheus")
.with("handler", "/metrics")
.range("1m")?
.try_into()?;
let q = histogram_quantile(0.9, rate(vector));
let response = client.query(q, None, None).await?;
let value = response.as_instant()
.unwrap()
.get(0)
.unwrap()
.sample()
.value();
assert!(value.is_normal());
Ok(())
}