-
Notifications
You must be signed in to change notification settings - Fork 1
/
register.go
46 lines (41 loc) · 1017 Bytes
/
register.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
package systime
import (
"fmt"
"os"
"github.com/Cloud-Foundations/tricorder/go/tricorder"
"github.com/Cloud-Foundations/tricorder/go/tricorder/units"
)
var onlineCpuFilename string = "/sys/devices/system/cpu/online"
func register(dir *tricorder.DirectorySpec) *prober {
p := new(prober)
p.numCpus = getNumCpus()
if p.numCpus > 0 {
if err := dir.RegisterMetric("idle-time", &p.idleTime, units.Second,
"idle time since last boot"); err != nil {
panic(err)
}
}
getNumCpus()
if err := dir.RegisterMetric("time", &p.probeTime, units.None,
"time of last probe"); err != nil {
panic(err)
}
if err := dir.RegisterMetric("uptime", &p.upTime, units.Second,
"time since last boot"); err != nil {
panic(err)
}
return p
}
func getNumCpus() uint64 {
file, err := os.Open(onlineCpuFilename)
if err != nil {
return 1
}
defer file.Close()
var low, high uint64
nScanned, err := fmt.Fscanf(file, "%d-%d", &low, &high)
if err != nil || nScanned != 2 {
return 1
}
return high - low + 1
}