Crate prometheus_http_api
source · [−]Expand description
Prometheus HTTP API
This crate provides data structures to interact with the prometheus HTTP API endpoints. The
crate allows constructing prometheus data sources with DataSourceBuilder.
A Query must be provided to the prometheus data source via the
DataSourceBuilder::with_query() that acceps either a
InstantQuery or a RangeQuery, for these types, build-like methods
are provided for the optional parameters.
Simple Usage
To gather the data from <http://localhost:9090/api/v1/query?query=up>
use prometheus_http_api::{
DataSourceBuilder, InstantQuery, Query,
};
#[tokio::main]
async fn main() {
let query = Query::Instant(InstantQuery::new("up"));
let request = DataSourceBuilder::new("localhost:9090")
.with_query(query)
.build()
.unwrap();
let res_json = request.get().await;
tracing::info!("{:?}", res_json);
}Structs
Represents a prometheus data source that works over an http(s) host:port endpoint potentially behind a /prometheus_prefix/
A Builder struct to create the DataSource
An instant query to send to Prometheus
MatrixResult contains Prometheus Range Vectors
A range query to send to Prometheus
VectorResult contains Prometheus Instant Vectors
Enums
A simple Error type to understand different errors.
A query to the Prometheus HTTP API
Available ResponseData formats documentation:
https://prometheus.io/docs/prometheus/latest/querying/api/#expression-query-result-formats