prometheus-json-encoder

Crates.ioprometheus-json-encoder
lib.rsprometheus-json-encoder
version0.1.1
sourcesrc
created_at2022-07-15 14:42:24.810923
updated_at2022-07-15 14:59:31.511552
descriptionJSON encoder implementation for the prometheus crate : https://docs.rs/prometheus/latest/prometheus/
homepage
repository
max_upload_size
id626252
size16,427
(AlianBenabdallah)

documentation

README

prometheus-json-encoder

Implements a JsonEncoder object for prometheus 0.13.0.

Basic example

use opentelemetry::{global, KeyValue, sdk::Resource};
use opentelemetry_prometheus::PrometheusExporter;
use prometheus_json_encoder::JsonEncoder;

fn init_meter() -> PrometheusExporter {
    opentelemetry_prometheus::exporter()
        .with_resource(Resource::new(vec![KeyValue::new("R", "V")]))
        .init()
}

fn main(){
    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", "value1")]);
    counter.add(100, &[KeyValue::new("key", "value2")]);
    counter.add(100, &[KeyValue::new("key2", "value")]);
    recorder.record(100, &[KeyValue::new("key", "value")]);

    // Encode data as text or protobuf
    let encoder = JsonEncoder::new();
    let metric_families = exporter.registry().gather();
    let mut result = Vec::new();
    encoder.encode(&metric_families, &mut result);
    println!("format :\n{}", encoder.format_type());
    println!("{:?}", result);
    let test = std::str::from_utf8(&result).unwrap();
    println!("{}", test)
    
}


Commit count: 0

cargo fmt