28 releases

0.8.3 Apr 8, 2024
0.8.2 Dec 30, 2023
0.7.1 Oct 29, 2023
0.6.6 Apr 17, 2023
0.3.0 Jul 10, 2021

#4 in #reqwest

Download history 10042/week @ 2023-12-25 14745/week @ 2024-01-01 20349/week @ 2024-01-08 20904/week @ 2024-01-15 21760/week @ 2024-01-22 20906/week @ 2024-01-29 16760/week @ 2024-02-05 14850/week @ 2024-02-12 15277/week @ 2024-02-19 17315/week @ 2024-02-26 12821/week @ 2024-03-04 15066/week @ 2024-03-11 14974/week @ 2024-03-18 16435/week @ 2024-03-25 13139/week @ 2024-04-01 8373/week @ 2024-04-08

53,841 downloads per month
Used in 10 crates (3 directly)

MIT license

150KB
3K SLoC

prometheus-http-query

This crate provides an interface to the Prometheus HTTP API and leverage Rust's type system in the process where applicable.

Example

use prometheus_http_query::{Client, Error, Selector, RuleKind};

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Error> {
    let client = Client::default();

    // Evaluate a PromQL query.
    let q = "topk by (code) (5, prometheus_http_requests_total)";
    let response = client.query(q).get().await?;
    assert!(response.data().as_vector().is_some());

    // Retrieve active alerts.
    let alerts = client.alerts().await;
    assert!(alerts.is_ok());

    // Retrieve recording rules.
    let recording_rules = client.rules().kind(RuleKind::Recording).get().await;
    assert!(recording_rules.is_ok());

    // Retrieve a list of time series that match certain labels sets ("series selectors").
    let select1 = Selector::new()
        .eq("handler", "/api/v1/query");

    let select2 = Selector::new()
        .eq("job", "node")
        .regex_eq("mode", ".+");

    let time_series = client.series(&[select1, select2]).get().await;
    assert!(time_series.is_ok());

    Ok(())
}

Compatibility

This library is generally compatible with Prometheus versions starting from v2.30. Individual client methods might fail with older versions as newer versions of Prometheus server support additional methods and query parameters. Run Prometheus server version >= 2.46 to ensure maximum compatibility.

Tests

In order to run all tests a Prometheus server must be running at http://localhost:9090. No special configuration is required at this point, simply run: cargo test

Contributing

Please do not hesitate to file issues in order to report bugs, ask questions or make suggestions. You are also welcome to tackle open issues if there are any.

If you are looking to submit code, please make sure that the tests pass successfully.

Dependencies

~5–20MB
~301K SLoC