Function prometheus_http_query::functions::day_of_week
source · [−]pub fn day_of_week(vector: InstantVector) -> InstantVectorExpand description
Apply the PromQL day_of_week function.
use prometheus_http_query::{Client, Selector, InstantVector};
use prometheus_http_query::functions::{day_of_week, timestamp};
use std::convert::TryInto;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), prometheus_http_query::Error> {
let client = Client::default();
let vector: InstantVector = Selector::new()
.metric("up")
.with("job", "prometheus")
.try_into()?;
let q = day_of_week(timestamp(vector));
let response = client.query(q, None, None).await?;
let value = response.as_instant()
.unwrap()
.get(0)
.unwrap()
.sample()
.value();
assert!((0.0..=6.0).contains(&value));
Ok(())
}