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

Function extractCounter

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

Source from the content-addressed store, hash-verified

234}
235
236func extractCounter(o *DecodeOptions, f *dto.MetricFamily) model.Vector {
237 samples := make(model.Vector, 0, len(f.Metric))
238
239 for _, m := range f.Metric {
240 if m.Counter == nil {
241 continue
242 }
243
244 lset := make(model.LabelSet, len(m.Label)+1)
245 for _, p := range m.Label {
246 lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue())
247 }
248 lset[model.MetricNameLabel] = model.LabelValue(f.GetName())
249
250 smpl := &model.Sample{
251 Metric: model.Metric(lset),
252 Value: model.SampleValue(m.Counter.GetValue()),
253 }
254
255 if m.TimestampMs != nil {
256 smpl.Timestamp = model.TimeFromUnixNano(*m.TimestampMs * 1000000)
257 } else {
258 smpl.Timestamp = o.Timestamp
259 }
260
261 samples = append(samples, smpl)
262 }
263
264 return samples
265}
266
267func extractGauge(o *DecodeOptions, f *dto.MetricFamily) model.Vector {
268 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