Expand description
Metrics client abstraction supporting multiple backends.
This crate provides a unified interface for querying metrics from different backends (Prometheus, Enya, etc.) using PromQL as the query language.
§Architecture
The MetricsClient trait defines a promise-based async interface that all
backends implement. Methods return Promise objects that can be polled
each frame in immediate mode GUIs like egui. HTTP requests are handled by
reqwest which works on both native (with tokio) and WASM (with browser fetch).
§Example
ⓘ
use enya_client::{MetricsClient, QueryRequest};
use enya_client::prometheus::PrometheusClient;
// Create a client for your backend
let client = PrometheusClient::new("http://localhost:9090");
// Fire off a query - returns a promise
let request = QueryRequest::new("cpu_usage", r#"sum(cpu_usage{env="prod"}) by (host)"#);
let promise = client.query(request, &ctx);
// In your update loop, poll for results
if let Some(result) = promise.ready() {
match result {
Ok(response) => { /* update visualization */ }
Err(e) => { /* show error */ }
}
}Re-exports§
pub use demo::DemoMetricsClient;pub use error::ClientError;pub use promise::promise_channel;pub use request::QueryRequest;pub use types::MetricsBucket;pub use types::MetricsGroup;pub use types::QueryResponse;pub use types::ResultType;pub use types::Timestamp;pub use prometheus::response::MetricLabels;pub use logs::DemoLogsClient;pub use logs::LogEntry;pub use logs::LogLevel;pub use logs::LogsClient;pub use logs::LogsQuery;pub use logs::LogsResponse;pub use logs::LogsResult;pub use logs::LokiClient;pub use logs::QueryDirection;pub use logs::StreamsResult;
Modules§
- demo
- Demo metrics client for offline/showcase mode.
- error
- Error types for the metrics client.
- logs
- Logs client abstraction supporting multiple backends.
- otlp
- OpenTelemetry Protocol (OTLP) support.
- prometheus
- Prometheus backend implementation.
- promise
- Promise-based async helpers for HTTP requests.
- request
- Query request types.
- tracing
- Tracing client abstraction for distributed trace backends.
- types
- Shared API types for metrics query responses.
Structs§
- Backend
Info - Backend health/version information from a health check.
- Health
Check Manager - Manages in-flight health check requests using promises.
- Labels
Manager - Manages in-flight label/metadata fetches using promises.
- Logs
Query Manager - Manages multiple in-flight log queries in parallel using promises.
- Metric
Labels Manager - Manages in-flight per-metric label fetches using promises.
- Promise
- A promise that waits for the reception of a single value, presumably from some async task.
- Query
Manager - Manages multiple in-flight queries in parallel using promises.
Constants§
- DEFAULT_
QUERY_ TIMEOUT_ SECS - Default query timeout in seconds. If a query doesn’t complete within this time, it will be cancelled with a timeout error.
Traits§
- Metrics
Client - Metrics client trait - promise-based async interface.
Functions§
- normalize_
url - Normalize a base URL: ensure it has an
http://scheme and strip trailing slashes. - now_
unix_ secs - Get the current Unix timestamp in seconds. Works on both native and WASM platforms.
- url_
encode - Simple URL encoding for query parameters.
Type Aliases§
- Health
Check Result - Result type for health check operations.
- Labels
Result - Result type for label list operations.
- Metric
Labels Result - Result type for metric series label operations.
- Query
Result - Result type for query operations.