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

Function extractCounter

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

Source from the content-addressed store, hash-verified

202}
203
204func extractCounter(o *DecodeOptions, f *dto.MetricFamily) model.Vector {
205 samples := make(model.Vector, 0, len(f.Metric))
206
207 for _, m := range f.Metric {
208 if m.Counter == nil {
209 continue
210 }
211
212 lset := make(model.LabelSet, len(m.Label)+1)
213 for _, p := range m.Label {
214 lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue())
215 }
216 lset[model.MetricNameLabel] = model.LabelValue(f.GetName())
217
218 smpl := &model.Sample{
219 Metric: model.Metric(lset),
220 Value: model.SampleValue(m.Counter.GetValue()),
221 }
222
223 if m.TimestampMs != nil {
224 smpl.Timestamp = model.TimeFromUnixNano(*m.TimestampMs * 1000000)
225 } else {
226 smpl.Timestamp = o.Timestamp
227 }
228
229 samples = append(samples, smpl)
230 }
231
232 return samples
233}
234
235func extractGauge(o *DecodeOptions, f *dto.MetricFamily) model.Vector {
236 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