Crate opentelemetry_prometheus
source · [−]Expand description
OpenTelemetry Prometheus Exporter
Prometheus Exporter Example
use opentelemetry::{global, KeyValue, sdk::Resource};
use opentelemetry_prometheus::PrometheusExporter;
use prometheus::{TextEncoder, Encoder};
fn init_meter() -> PrometheusExporter {
opentelemetry_prometheus::exporter()
.with_resource(Resource::new(vec![KeyValue::new("R", "V")]))
.init()
}
let exporter = init_meter();
let meter = global::meter("my-app");
// Use two instruments
let counter = meter
.u64_counter("a.counter")
.with_description("Counts things")
.init();
let recorder = meter
.i64_value_recorder("a.value_recorder")
.with_description("Records values")
.init();
counter.add(100, &[KeyValue::new("key", "value")]);
recorder.record(100, &[KeyValue::new("key", "value")]);
// Encode data as text or protobuf
let encoder = TextEncoder::new();
let metric_families = exporter.registry().gather();
let mut result = Vec::new();
encoder.encode(&metric_families, &mut result);
// result now contains encoded metrics:
//
// # HELP a_counter Counts things
// # TYPE a_counter counter
// a_counter{R="V",key="value"} 100
// # HELP a_value_recorder Records values
// # TYPE a_value_recorder histogram
// a_value_recorder_bucket{R="V",key="value",le="0.5"} 0
// a_value_recorder_bucket{R="V",key="value",le="0.9"} 0
// a_value_recorder_bucket{R="V",key="value",le="0.99"} 0
// a_value_recorder_bucket{R="V",key="value",le="+Inf"} 1
// a_value_recorder_sum{R="V",key="value"} 100
// a_value_recorder_count{R="V",key="value"} 1
Structs
Configuration for the prometheus exporter.
An implementation of metrics::Exporter
that sends metrics to Prometheus.
An implementation of an Encoder
that converts a MetricFamily
proto message
into text format.
Traits
An interface for encoding metric families into an underlying wire protocol.
Functions
Create a new prometheus exporter builder.