Function prometheus_http_query::query
source · pub fn query(
host: &str,
query: impl ToString
) -> Result<InstantQueryBuilder, Error>
Expand description
Execute an instant query.
This is just a convenience function for one-off requests, see Client::query.
use prometheus_http_query::{Error, query};
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Error> {
let q = "sum(prometheus_http_requests_total)";
let response = query("http://localhost:9090", q)?.timeout(1000).get().await?;
assert!(response.data().as_vector().is_some());
// Or make a POST request.
let response = query("http://localhost:9090", q)?.timeout(1000).post().await?;
assert!(response.data().as_vector().is_some());
Ok(())
}