MCPcopy Create free account
hub / github.com/prometheus/common / extractCounter

Function extractCounter

expfmt/decode.go:229–258  ·  view source on GitHub ↗
(o *DecodeOptions, f *dto.MetricFamily)

Source from the content-addressed store, hash-verified

227}
228
229func extractCounter(o *DecodeOptions, f *dto.MetricFamily) model.Vector {
230 samples := make(model.Vector, 0, len(f.Metric))
231
232 for _, m := range f.Metric {
233 if m.Counter == nil {
234 continue
235 }
236
237 lset := make(model.LabelSet, len(m.Label)+1)
238 for _, p := range m.Label {
239 lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue())
240 }
241 lset[model.MetricNameLabel] = model.LabelValue(f.GetName())
242
243 smpl := &model.Sample{
244 Metric: model.Metric(lset),
245 Value: model.SampleValue(m.Counter.GetValue()),
246 }
247
248 if m.TimestampMs != nil {
249 smpl.Timestamp = model.TimeFromUnixNano(*m.TimestampMs * 1000000)
250 } else {
251 smpl.Timestamp = o.Timestamp
252 }
253
254 samples = append(samples, smpl)
255 }
256
257 return samples
258}
259
260func extractGauge(o *DecodeOptions, f *dto.MetricFamily) model.Vector {
261 samples := make(model.Vector, 0, len(f.Metric))

Callers 1

extractSamplesFunction · 0.85

Calls 5

LabelNameTypeAlias · 0.92
LabelValueTypeAlias · 0.92
MetricTypeAlias · 0.92
SampleValueTypeAlias · 0.92
TimeFromUnixNanoFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…