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§

DataSource
Represents a prometheus data source that works over an http(s) host:port endpoint potentially behind a /prometheus_prefix/
DataSourceBuilder
A Builder struct to create the DataSource
InstantQuery
An instant query to send to Prometheus
MatrixResult
MatrixResult contains Prometheus Range Vectors
RangeQuery
A range query to send to Prometheus
Response
A Prometheus Response returned by an HTTP query.
VectorResult
VectorResult contains Prometheus Instant Vectors

Enums§

DataSourceError
A simple Error type to understand different errors.
Query
A query to the Prometheus HTTP API
ResponseData
Available ResponseData formats documentation: https://prometheus.io/docs/prometheus/latest/querying/api/#expression-query-result-formats