NewCounterVec creates a new CounterVec based on the provided CounterVecOpts.
(opts CounterVecOpts)
| 200 | |
| 201 | // NewCounterVec creates a new CounterVec based on the provided CounterVecOpts. |
| 202 | func (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 |