MCPcopy
hub / github.com/prometheus/client_golang / NewCounterVec

Method NewCounterVec

prometheus/counter.go:202–223  ·  view source on GitHub ↗

NewCounterVec creates a new CounterVec based on the provided CounterVecOpts.

(opts CounterVecOpts)

Source from the content-addressed store, hash-verified

200
201// NewCounterVec creates a new CounterVec based on the provided CounterVecOpts.
202func (v2) NewCounterVec(opts CounterVecOpts) *CounterVec {
203 desc := V2.NewDesc(
204 BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),
205 opts.Help,
206 opts.VariableLabels,
207 opts.ConstLabels,
208 )
209 if opts.now == nil {
210 opts.now = time.Now
211 }
212 return &CounterVec{
213 MetricVec: NewMetricVec(desc, func(lvs ...string) Metric {
214 if len(lvs) != len(desc.variableLabels.names) {
215 panic(makeInconsistentCardinalityError(desc.fqName, desc.variableLabels.names, lvs))
216 }
217 result := &counter{desc: desc, labelPairs: MakeLabelPairs(desc, lvs), now: opts.now}
218 result.init(result) // Init self-collection.
219 result.createdTs = timestamppb.New(opts.now())
220 return result
221 }),
222 }
223}
224
225// GetMetricWithLabelValues returns the Counter for the given slice of label
226// values (same order as the variable labels in Desc). If that combination of

Callers 6

NewCounterVecFunction · 0.45
BenchmarkCounterFunction · 0.45
WrapHandlerMethod · 0.45
instrumentHandlerFuncFunction · 0.45
instrumentRoundTripperFunction · 0.45

Calls 6

BuildFQNameFunction · 0.85
NewMetricVecFunction · 0.85
MakeLabelPairsFunction · 0.85
NewDescMethod · 0.80
initMethod · 0.80

Tested by 2

BenchmarkCounterFunction · 0.36