From 148fde894bc93e7ecb0ae83d7a90a843520fbfd8 Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Sat, 24 Aug 2013 11:53:14 +0200 Subject: [PATCH] Include summary sample sums and counts if present. This commit finally unlocks the ability for the Prometheus client users of the Summary metric type to automatically get total counts and sums partitioned by labels. It exposes them through two synthetic variables, if the underlying data is present. The following is the base case: foo_samples{quantile=0.5} = foo_samples{quantile=0.99} = The following results with this change: foo_samples{quantile=0.5} = foo_samples{quantile=0.99} = foo_samples_sum = foo_samples_count = Change-Id: I75b5ea0d8c851da8c0c82ed9c8ac0890e4238f87 --- extraction/metricfamilyprocessor.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/extraction/metricfamilyprocessor.go b/extraction/metricfamilyprocessor.go index c16f5ea..6fa871f 100644 --- a/extraction/metricfamilyprocessor.go +++ b/extraction/metricfamilyprocessor.go @@ -121,7 +121,6 @@ func extractGauge(out Ingester, o *ProcessOptions, f *dto.MetricFamily) error { } func extractSummary(out Ingester, o *ProcessOptions, f *dto.MetricFamily) error { - // BUG(matt): Lack of dumping of sum or count. samples := make(model.Samples, 0, len(f.Metric)) for _, m := range f.Metric { @@ -147,6 +146,32 @@ func extractSummary(out Ingester, o *ProcessOptions, f *dto.MetricFamily) error sample.Value = model.SampleValue(q.GetValue()) } + + if m.Summary.SampleSum != nil { + sum := new(model.Sample) + sum.Timestamp = o.Timestamp + metric := model.Metric{} + for _, p := range m.Label { + metric[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + metric[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_sum") + sum.Metric = metric + sum.Value = model.SampleValue(m.Summary.GetSampleSum()) + samples = append(samples, sum) + } + + if m.Summary.SampleCount != nil { + count := new(model.Sample) + count.Timestamp = o.Timestamp + metric := model.Metric{} + for _, p := range m.Label { + metric[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) + } + metric[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_count") + count.Metric = metric + count.Value = model.SampleValue(m.Summary.GetSampleCount()) + samples = append(samples, count) + } } return out.Ingest(&Result{Samples: samples})