Struct prometheus_http_query::Client [−][src]
pub struct Client { /* fields omitted */ }
Expand description
A client used to execute queries. It uses a reqwest::Client internally that manages connections for us.
Implementations
Create a Client that connects to a Prometheus instance at the given FQDN/domain and port, using either HTTP or HTTPS.
Note that possible errors regarding domain name resolution or connection establishment will only be propagated from the underlying reqwest::Client when a query is executed.
use prometheus_http_query::{Client, Scheme}; let client = Client::new(Scheme::Http, "localhost", 9090);
Perform an instant query using a crate::RangeVector or crate::InstantVector.
use prometheus_http_query::{Client, Scheme, InstantVector, Selector, Aggregate, Error}; use prometheus_http_query::aggregations::sum; use std::convert::TryInto; fn main() -> Result<(), Error> { let client = Client::new(Scheme::Http, "localhost", 9090); let v: InstantVector = Selector::new() .metric("node_cpu_seconds_total")? .try_into()?; let s = sum(v, Some(Aggregate::By(&["cpu"]))); let response = tokio_test::block_on( async { client.query(s, None, None).await }); assert!(response.is_ok()); Ok(()) }
pub async fn query_range(
&self,
vector: impl Display,
start: i64,
end: i64,
step: &str,
timeout: Option<&str>
) -> Result<Response, Error>
Find time series by series selectors.
use prometheus_http_query::{Client, Scheme, Selector, Error}; fn main() -> Result<(), Error> { let client = Client::new(Scheme::Http, "localhost", 9090); let s1 = Selector::new() .with("handler", "/api/v1/query"); let s2 = Selector::new() .with("job", "node") .regex_match("mode", ".+"); let set = vec![s1, s2]; let response = tokio_test::block_on( async { client.series(&set, None, None).await }); assert!(response.is_ok()); Ok(()) }
Retrieve all label names (or use Selectors to select time series to read label names from).
use prometheus_http_query::{Client, Scheme, Selector, Error}; fn main() -> Result<(), Error> { let client = Client::new(Scheme::Http, "localhost", 9090); // To retrieve a list of all labels: let response = tokio_test::block_on( async { client.labels(None, None, None).await }); assert!(response.is_ok()); // To retrieve a list of labels that appear in specific time series, use Selectors: let s1 = Selector::new() .with("handler", "/api/v1/query"); let s2 = Selector::new() .with("job", "node") .regex_match("mode", ".+"); let set = Some(vec![s1, s2]); let response = tokio_test::block_on( async { client.labels(set, None, None).await }); assert!(response.is_ok()); Ok(()) }
Retrieve all label values for a label name (or use Selectors to select the time series to read label values from)
use prometheus_http_query::{Client, Scheme, Selector, Error}; fn main() -> Result<(), Error> { let client = Client::new(Scheme::Http, "localhost", 9090); // To retrieve a list of all label values for a specific label name: let response = tokio_test::block_on( async { client.label_values("job", None, None, None).await }); assert!(response.is_ok()); // To retrieve a list of label values of labels in specific time series instead: let s1 = Selector::new() .regex_match("instance", ".+"); let set = Some(vec![s1]); let response = tokio_test::block_on( async { client.label_values("job", set, None, None).await }); assert!(response.is_ok()); Ok(()) }
Query the current state of target discovery.
use prometheus_http_query::{Client, Scheme, Error, TargetState}; use std::convert::TryInto; fn main() -> Result<(), Error> { let client = Client::new(Scheme::Http, "localhost", 9090); let response = tokio_test::block_on( async { client.targets(None).await }); assert!(response.is_ok()); // Filter targets by type: let response = tokio_test::block_on( async { client.targets(Some(TargetState::Active)).await }); assert!(response.is_ok()); Ok(()) }
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client