Prometheus push
This crate works as an extension to prometheus crates like prometheus to be able to push non-blocking (default)
or blocking to your Prometheus pushgateway and with a less dependent setup of reqwest (no openssl for example) or with an implementation of your
own http client.
By default you have to implement the Push trait to use it with your choice of http client or you can use the with_reqwest feature.
This feature already implements Push in a PushClient that leverages reqwest under the hood. Reqwest is setup without default features
(minimal set) in this case so it should not interfere with your own applications reqwest setup (e.g. rust-tls).
Async functionality is considered the standard in this crate but you can enable the blocking feature to get the implementation without async. You
can enable the corresponding blocking reqwest implementation with the with_reqwest_blocking feature in which case you enable the blocking
feature of the reqwest crate as well.
In terms of the underlying prometheus functionality you have to implement the ConvertMetrics trait or you use the already implemented feature
prometheus_crate that leverages the prometheus crate.
Example with features with_reqwest and prometheus_crate
use Collector;
use labels;
use MetricFamily;
use MetricsPusher;
use PrometheusMetricsConverter;
use PushClient;
use MetricsPusher;
use Client;
use Url;
pub type PrometheusMetricsPusher =
;
let push_gateway: Url = ;
let client = new;
let metrics_pusher = from?;
metrics_pusher
.push_all
.await?;
Implement Push yourself
If you are not using reqwest as an http client you are free to implement the Push traits two methods yourself. As a guide you can use the
implementation of the with_reqwest feature (see here).
Basically it is as simple as that.
use Push;
...
Implement ConvertMetrics yourself
In case you want to use another promethues client implementation you can implement your own type that implements
the ConvertMetrics trait to inject it into your instance of MetricsPusher.
Features
default: by default async functionality and no reqwest is enablednon_blocking: this ennables the async functionalityblocking: on top of the default feature you get the same functionality in a blocking fashionwith_reqwest: this feature enables thenon_blockingfeature as well asreqwestin minimal configuration and enables the alredy implementedPushClientwith_reqwest_blocking: likewith_reqwestbut includingblockinginstead ofnon_blockingprometheus_crate: enables the functionality of the prometheus crate