-
Notifications
You must be signed in to change notification settings - Fork 3
/
current.go
50 lines (43 loc) · 1.08 KB
/
current.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package telemetry
import (
"sync"
"time"
)
//Current - a metric containing the value most recently passed to it
type Current struct {
Name string
value float64
lock sync.Mutex
}
//NewCurrent - Create a new current metric and add it to the telemetry register
func NewCurrent(tel *Telemetry, name string, _ time.Duration) *Current {
current := Current{
Name: name,
value: float64(0),
}
tel.lock.Lock()
defer tel.lock.Unlock()
tel.registry[name] = ¤t
return ¤t
}
//Add - set the value of the Current metric
func (c *Current) Add(tel *Telemetry, value float64) error {
c.lock.Lock()
defer c.lock.Unlock()
tel.lock.Lock()
defer tel.lock.Unlock()
tel.registry[c.Name].(*Current).value = value
return nil
}
//Get - return the value of the metric
func (c *Current) Get(tel *Telemetry) float64 {
return tel.registry[c.Name].(*Current).value
}
//GetName - return the human readable name of the metric
func (c *Current) GetName() string {
return c.Name
}
//Maintain - stub method for interface, metric is so simple that it isn't needed
func (c *Current) Maintain() {
return
}