forked from cisco-ie/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selfhealth.go
53 lines (45 loc) · 1.52 KB
/
selfhealth.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
51
52
53
package vsphere
import (
"time"
"github.com/influxdata/telegraf/selfstat"
)
// Stopwatch is a simple helper for recording timing information,
// such as gather times and discovery times.
type Stopwatch struct {
stat selfstat.Stat
start time.Time
}
// NewStopwatch creates a new StopWatch and starts measuring time
// its creation.
func NewStopwatch(name, vCenter string) *Stopwatch {
return &Stopwatch{
stat: selfstat.RegisterTiming("vsphere", name+"_ns", map[string]string{"vcenter": vCenter}),
start: time.Now(),
}
}
// NewStopwatchWithTags creates a new StopWatch and starts measuring time
// its creation. Allows additional tags.
func NewStopwatchWithTags(name, vCenter string, tags map[string]string) *Stopwatch {
tags["vcenter"] = vCenter
return &Stopwatch{
stat: selfstat.RegisterTiming("vsphere", name+"_ns", tags),
start: time.Now(),
}
}
// Stop stops a Stopwatch and records the time.
func (s *Stopwatch) Stop() {
s.stat.Set(time.Since(s.start).Nanoseconds())
}
// SendInternalCounter is a convenience method for sending
// non-timing internal metrics.
func SendInternalCounter(name, vCenter string, value int64) {
s := selfstat.Register("vsphere", name, map[string]string{"vcenter": vCenter})
s.Set(value)
}
// SendInternalCounterWithTags is a convenience method for sending
// non-timing internal metrics. Allows additional tags
func SendInternalCounterWithTags(name, vCenter string, tags map[string]string, value int64) {
tags["vcenter"] = vCenter
s := selfstat.Register("vsphere", name, tags)
s.Set(value)
}