#remote #prometheus #storage-api #api #storage

prom-remote-api

Prometheus远程存储API for Rust

5个不稳定版本

0.3.0 2023年5月27日
0.2.2 2023年5月9日
0.2.1 2023年1月22日
0.2.0 2023年1月21日
0.1.0 2023年1月16日

#18 in #storage-api

Download history 268/week @ 2024-03-13 204/week @ 2024-03-20 296/week @ 2024-03-27 262/week @ 2024-04-03 223/week @ 2024-04-10 452/week @ 2024-04-17 420/week @ 2024-04-24 345/week @ 2024-05-01 412/week @ 2024-05-08 379/week @ 2024-05-15 467/week @ 2024-05-22 396/week @ 2024-05-29 278/week @ 2024-06-05 319/week @ 2024-06-12 227/week @ 2024-06-19 173/week @ 2024-06-26

1,038 每月下载次数

Apache-2.0

27KB
231

prom-remote-api

Crates.io docs.rs

Prometheus的Rust远程存储API。

使用

Prometheus远程存储API中有两个接口:写入/读取。

这两个接口都使用HTTP上的snappy压缩协议缓冲区编码。

此包提供了

任何第三方存储都可以通过实现RemoteStorage特质与Prometheus集成。

pub trait RemoteStorage: Sync {
    type Err: Send;
    type Context: Send + Sync;

    /// Write samples to remote storage.
    async fn write(&self, ctx: Self::Context, req: WriteRequest) -> Result<(), Self::Err>;

    /// Process one query within [ReadRequest](crate::types::ReadRequest).
    ///
    /// Note: Prometheus remote protocol sends multiple queries by default,
    /// use [read](crate::types::RemoteStorage::read) to serve ReadRequest.
    async fn process_query(
        &self,
        ctx: &Self::Context,
        q: Query,
    ) -> Result<QueryResult, Self::Err>;

    /// Read samples from remote storage.
    ///
    /// [ReadRequest](crate::types::ReadRequest) may contain more than one sub [queries](crate::types::Query).
    async fn read(
        &self,
        ctx: Self::Context,
        req: ReadRequest,
    ) -> Result<ReadResponse, Self::Err> {
        let results = futures::future::join_all(
            req.queries
                .into_iter()
                .map(|q| async { self.process_query(&ctx, q).await }),
        )
        .await
        .into_iter()
        .collect::<Result<Vec<_>, Self::Err>>()?;

        Ok(ReadResponse { results })
    }
}

请参阅warp-demo.rsactix-demo.rs了解如何构建远程存储。

依赖项

~6–22MB
~277K SLoC