-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_gauge.go
36 lines (28 loc) · 1.03 KB
/
default_gauge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package metrics
import "sync/atomic"
type simpleGauge struct {
name string
description string
labels string
value *atomic.Int64
}
func NewGauge(name string, options ...option) Gauge {
config := configuration{Name: name}
Options.apply(options...)(&config)
this := &simpleGauge{
name: config.Name,
description: config.Description,
labels: config.RenderLabels(),
value: new(atomic.Int64),
}
config.Exporter.Add(this)
return this
}
func (this *simpleGauge) Type() string { return "gauge" }
func (this *simpleGauge) Name() string { return this.name }
func (this *simpleGauge) Description() string { return this.description }
func (this *simpleGauge) Labels() string { return this.labels }
func (this *simpleGauge) Increment() { this.value.Add(1) }
func (this *simpleGauge) IncrementN(value int64) { this.value.Add(value) }
func (this *simpleGauge) Measure(value int64) { this.value.Store(value) }
func (this *simpleGauge) Value() int64 { return this.value.Load() }