Skip to content

Commit

Permalink
Include summary sample sums and counts if present.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matttproud committed Aug 25, 2013
1 parent f5f5a20 commit 148fde8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion extraction/metricfamilyprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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})
Expand Down

0 comments on commit 148fde8

Please sign in to comment.