Prometheus Push :arrow_double_up:
prometheus_push
works as an extension to prometheus crates like prometheus or
prometheus-client to be able to push non-blocking (default) or blocking to your Prometheus
pushgateway with a less dependent setup of reqwest
(no openssl
for example) or with an implementation of your own http client or even
another prometheus
crate – this whole crate is completely generic so you are free to do whatever you want.
If you wanna use it with reqwest
, prometheus
or prometheus-client
crates you literally do not have to implement anything (see
scenarios below), as those common usages are already implemented as features within this crate.
In this crates stripped version you have to implement the Push
trait (see here) to use it with your choice of
http client or –as said– you can use the with_reqwest
or with_reqwest_blocking
features. These features already implement Push
in a
PushClient
that leverages reqwest
under the hood. Reqwest is set up 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 (feature non_blocking
) 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.
In terms of the underlying prometheus functionality you have to implement the ConvertMetrics
trait yourself (see here)
or you use the already implemented feature prometheus_crate
that leverages the prometheus crate or
prometheus_client_crate
that uses the prometheus-client crate.
Scenarios
1. I use reqwest
and prometheus
crates in a non-blocking fashion
In your Cargo.toml
:
[]
= { = "<version>", = false, = ["with_reqwest", "prometheus_crate"] }
use labels;
use PrometheusMetricsPusher;
use Client;
use Url;
async
2. I use reqwest
and prometheus
crates in a blocking fashion
In your Cargo.toml
:
[]
= { = "<version>", = false, = ["with_reqwest_blocking", "prometheus_crate"] }
use labels;
use PrometheusMetricsPusherBlocking;
use Client;
use Url;
3. I use reqwest
and prometheus-client
crates in a non-blocking fashion
In your Cargo.toml
:
[]
= { = "<version>", = false, = ["with_reqwest", "prometheus_client_crate"] }
use encode;
use PrometheusClientMetricsPusher;
use Client;
use Url;
async
4. I use reqwest
and prometheus-client
crates in a blocking fashion
In your Cargo.toml
:
[]
= { = "<version>", = false, = ["with_reqwest_blocking", "prometheus_client_crate"] }
use encode;
use PrometheusClientMetricsPusherBlocking;
use Client;
use Url;
5. I want to implement everything myself
In case you wanna implement everything yourself you can do so by implementing the Push
trait and the ConvertMetrics
trait.
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 prometheus 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_blocking
feature as well asreqwest
in minimal configuration and enables the alredy implementedPushClient
with_reqwest_blocking
: likewith_reqwest
but includingblocking
instead ofnon_blocking
prometheus_crate
: enables the functionality of the prometheus crateprometheus_client_crate
: enables the functionality of the prometheus-client crate