#prometheus #http-api #query #endpoint #data #docs #interact

prometheus-http-api

API to interact with Prometheus HTTP API

1 unstable release

0.2.0 Apr 27, 2022

#494 in HTTP client

Download history 1/week @ 2024-02-19 108/week @ 2024-02-26 96/week @ 2024-03-04 56/week @ 2024-03-11 47/week @ 2024-03-18

307 downloads per month

Apache-2.0

27KB
424 lines

prometheus-http-api-rs 0.2.0

A simple library to pull data from prometheus using its API

Rust Crates.io Documentation

Upcoming docs crate documentation.

Usage

Add dependency in Cargo.toml:

[dependencies]
prometheus-http-api = "0.2.0"

Use prometheus_http_api

use prometheus_http_api::*;

#[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);
}

License

TODO

To be addressed soon

  • Missing fallback to POST, some queries can grow paths the GET params limits.
  • Missing Instant support, currently we only support epochs as params.
  • Querying metadata: /api/v1/series or /api/v1/labels /api/v1/label/<label_name>/values
  • Target state /api/v1/targets
  • AlertManagers /api/v1/alertmanagers
  • Status Config /api/v1/status/config
  • Status flags /api/v1/status/flags
  • Runtime info /api/v1/status/runtimeinfo, available since prometheus v2.2
  • Build info /api/v1/status/buildinfo, available since prometheus v2.14
  • TSDB metrics /api/v1/status/tsdb, available since prometheus v2.14
  • WAL Replay status /api/v1/status/walreplay available since prometheus v2.15

Not stable endpoints:

  • Querying exemplars /api/v1/query_exemplars (experimental)
  • Rules /api/v1/rules (doesn't have stability guarantees from prometheus v1)
  • Alerts /api/v1/alerts (doesn't have stability guarantees from prometheus v1)
  • Target Metadata /api/v1/targets/metadata (experimental)
  • Metric Metadata /api/v1/metadata(experimental)

Admin endpoints

Since prometheus v2.18, require -web.enable-admin-api

  • Snapshots /api/v1/admin/tsdb/snapshot
  • Delete timeseries /api/v1/admin/tsdb/delete_series
  • Clean tombstones /api/v1/admin/tsdb/clean_tombstones

Write endpoint

Requires --web.enable-remote-write-receiver.

  • Prometheus remote write protocol /api/v1/write since prometheus v2.33 not efficient way to push data.

NOTES:

  • The json::Value is not necessarily a number, it may be a string:

JSON does not support special float values such as NaN, Inf, and -Inf, so sample values are transferred as quoted JSON strings rather than raw numbers.

Dependencies

~7–19MB
~251K SLoC