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
This commit is contained in:
Matt T. Proud 2013-08-24 11:53:14 +02:00
parent f5f5a2007a
commit 148fde894b
1 changed files with 26 additions and 1 deletions

View File

@ -121,7 +121,6 @@ func extractGauge(out Ingester, o *ProcessOptions, f *dto.MetricFamily) error {
} }
func extractSummary(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)) samples := make(model.Samples, 0, len(f.Metric))
for _, m := range 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()) 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}) return out.Ingest(&Result{Samples: samples})