Hello, the following snippet creates a protobuf Histogram, copied from rust-prometheus.
fn proto(&self) -> proto::Histogram {
let mut h = proto::Histogram::new();
h.set_sample_sum(self.sum);
h.set_sample_count(self.count);
let mut count = 0;
let mut buckets = Vec::with_capacity(self.upper_bounds.len());
for (i, upper_bound) in self.upper_bounds.iter().enumerate() {
count += self.counts[i];
let mut b = proto::Bucket::new();
b.set_cumulative_count(count);
b.set_upper_bound(*upper_bound);
buckets.push(b);
}
h.set_bucket(RepeatedField::from_vec(buckets));
h
}
Hope it helps!
BTW, rust-prometheus is a prometheus client for rust, ported from client_golang. It has a TextEncoder that converts a MetricFamily proto message into text format, if you want to supprot text format, it would be a shortcut ;-)
Hello, the following snippet creates a protobuf Histogram, copied from rust-prometheus.
Hope it helps!
BTW, rust-prometheus is a prometheus client for rust, ported from client_golang. It has a TextEncoder that converts a MetricFamily proto message into text format, if you want to supprot text format, it would be a shortcut ;-)