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

Function NewCounter

prometheus/counter.go:87–101  ·  view source on GitHub ↗

NewCounter creates a new Counter based on the provided CounterOpts. The returned implementation also implements ExemplarAdder. It is safe to perform the corresponding type assertion. The returned implementation tracks the counter value in two separate variables, a float64 and a uint64. The latter

(opts CounterOpts)

Source from the content-addressed store, hash-verified

85// Both internal tracking values are added up in the Write method. This has to
86// be taken into account when it comes to precision and overflow behavior.
87func NewCounter(opts CounterOpts) Counter {
88 desc := NewDesc(
89 BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),
90 opts.Help,
91 nil,
92 opts.ConstLabels,
93 )
94 if opts.now == nil {
95 opts.now = time.Now
96 }
97 result := &counter{desc: desc, labelPairs: desc.constLabelPairs, now: opts.now}
98 result.init(result) // Init self-collection.
99 result.createdTs = timestamppb.New(opts.now())
100 return result
101}
102
103type counter struct {
104 // valBits contains the bits of the represented float64 value, while

Callers 15

ExampleRegisterFunction · 0.92
TestNewMultiTRegistryFunction · 0.92
ExampleRegistry_groupingFunction · 0.92
TestHandlerErrorHandlingFunction · 0.92
TestPushFunction · 0.92
TestToFloat64Function · 0.92
TestCollectAndCompareFunction · 0.92
TestNoMetricFilterFunction · 0.92

Calls 3

NewDescFunction · 0.85
BuildFQNameFunction · 0.85
initMethod · 0.80

Tested by 15

ExampleRegisterFunction · 0.74
TestNewMultiTRegistryFunction · 0.74
ExampleRegistry_groupingFunction · 0.74
TestHandlerErrorHandlingFunction · 0.74
TestPushFunction · 0.74
TestToFloat64Function · 0.74
TestCollectAndCompareFunction · 0.74
TestNoMetricFilterFunction · 0.74