-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathrunit_collector.go
More file actions
91 lines (78 loc) · 2.1 KB
/
runit_collector.go
File metadata and controls
91 lines (78 loc) · 2.1 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// +build runit
package collector
import (
"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/soundcloud/go-runit/runit"
)
var (
runitLabelNames = []string{"service"}
runitState = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: Namespace,
Name: "service_state",
Help: "node_exporter: state of runit service.",
},
runitLabelNames,
)
runitStateDesired = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: Namespace,
Name: "service_desired_state",
Help: "node_exporter: desired state of runit service.",
},
runitLabelNames,
)
runitStateNormal = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: Namespace,
Name: "service_normal_state",
Help: "node_exporter: normal state of runit service.",
},
runitLabelNames,
)
)
type runitCollector struct {
config Config
}
func init() {
Factories["runit"] = NewRunitCollector
}
func NewRunitCollector(config Config) (Collector, error) {
c := runitCollector{
config: config,
}
if _, err := prometheus.RegisterOrGet(runitState); err != nil {
return nil, err
}
if _, err := prometheus.RegisterOrGet(runitStateDesired); err != nil {
return nil, err
}
if _, err := prometheus.RegisterOrGet(runitStateNormal); err != nil {
return nil, err
}
return &c, nil
}
func (c *runitCollector) Update() (updates int, err error) {
services, err := runit.GetServices("/etc/service")
if err != nil {
return 0, err
}
for _, service := range services {
status, err := service.Status()
if err != nil {
glog.V(1).Infof("Couldn't get status for %s: %s, skipping...", service.Name, err)
continue
}
glog.V(1).Infof("%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration)
runitState.WithLabelValues(service.Name).Set(float64(status.State))
runitStateDesired.WithLabelValues(service.Name).Set(float64(status.Want))
if status.NormallyUp {
runitStateNormal.WithLabelValues(service.Name).Set(1)
} else {
runitStateNormal.WithLabelValues(service.Name).Set(1)
}
updates += 3
}
return updates, err
}