diff options
author | Mikhail Salosin <salosinm@gmail.com> | 2015-09-15 19:46:59 +0300 |
---|---|---|
committer | Mikhail Salosin <salosinm@gmail.com> | 2015-09-15 19:46:59 +0300 |
commit | e41593de14d37b0d1ec5c9d6bcdfca1114d4f483 (patch) | |
tree | c11cc12b36f832d40327498d5531add69ab61723 /collector/runit.go | |
parent | efe09051dc5d5ccffa38adc6b0de654d32e09f1f (diff) | |
download | prometheus_node_collector-e41593de14d37b0d1ec5c9d6bcdfca1114d4f483.tar.bz2 prometheus_node_collector-e41593de14d37b0d1ec5c9d6bcdfca1114d4f483.tar.xz prometheus_node_collector-e41593de14d37b0d1ec5c9d6bcdfca1114d4f483.zip |
Add unix timestamp of the last service state change to runit collector
Diffstat (limited to 'collector/runit.go')
-rw-r--r-- | collector/runit.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/collector/runit.go b/collector/runit.go index 72ab685..4aad744 100644 --- a/collector/runit.go +++ b/collector/runit.go | |||
@@ -9,7 +9,7 @@ import ( | |||
9 | ) | 9 | ) |
10 | 10 | ||
11 | type runitCollector struct { | 11 | type runitCollector struct { |
12 | state, stateDesired, stateNormal *prometheus.GaugeVec | 12 | state, stateDesired, stateNormal, stateTimestamp *prometheus.GaugeVec |
13 | } | 13 | } |
14 | 14 | ||
15 | func init() { | 15 | func init() { |
@@ -29,7 +29,7 @@ func NewRunitCollector() (Collector, error) { | |||
29 | Namespace: Namespace, | 29 | Namespace: Namespace, |
30 | Subsystem: subsystem, | 30 | Subsystem: subsystem, |
31 | Name: "state", | 31 | Name: "state", |
32 | Help: "state of runit service.", | 32 | Help: "State of runit service.", |
33 | ConstLabels: constLabels, | 33 | ConstLabels: constLabels, |
34 | }, | 34 | }, |
35 | labelNames, | 35 | labelNames, |
@@ -39,7 +39,7 @@ func NewRunitCollector() (Collector, error) { | |||
39 | Namespace: Namespace, | 39 | Namespace: Namespace, |
40 | Subsystem: subsystem, | 40 | Subsystem: subsystem, |
41 | Name: "desired_state", | 41 | Name: "desired_state", |
42 | Help: "desired state of runit service.", | 42 | Help: "Desired state of runit service.", |
43 | ConstLabels: constLabels, | 43 | ConstLabels: constLabels, |
44 | }, | 44 | }, |
45 | labelNames, | 45 | labelNames, |
@@ -49,7 +49,17 @@ func NewRunitCollector() (Collector, error) { | |||
49 | Namespace: Namespace, | 49 | Namespace: Namespace, |
50 | Subsystem: subsystem, | 50 | Subsystem: subsystem, |
51 | Name: "normal_state", | 51 | Name: "normal_state", |
52 | Help: "normal state of runit service.", | 52 | Help: "Normal state of runit service.", |
53 | ConstLabels: constLabels, | ||
54 | }, | ||
55 | labelNames, | ||
56 | ), | ||
57 | stateTimestamp: prometheus.NewGaugeVec( | ||
58 | prometheus.GaugeOpts{ | ||
59 | Namespace: Namespace, | ||
60 | Subsystem: subsystem, | ||
61 | Name: "state_last_change_timestamp_seconds", | ||
62 | Help: "Unix timestamp of the last runit service state change.", | ||
53 | ConstLabels: constLabels, | 63 | ConstLabels: constLabels, |
54 | }, | 64 | }, |
55 | labelNames, | 65 | labelNames, |
@@ -73,6 +83,7 @@ func (c *runitCollector) Update(ch chan<- prometheus.Metric) error { | |||
73 | log.Debugf("%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration) | 83 | log.Debugf("%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration) |
74 | c.state.WithLabelValues(service.Name).Set(float64(status.State)) | 84 | c.state.WithLabelValues(service.Name).Set(float64(status.State)) |
75 | c.stateDesired.WithLabelValues(service.Name).Set(float64(status.Want)) | 85 | c.stateDesired.WithLabelValues(service.Name).Set(float64(status.Want)) |
86 | c.stateTimestamp.WithLabelValues(service.Name).Set(float64(status.Timestamp.Unix())) | ||
76 | if status.NormallyUp { | 87 | if status.NormallyUp { |
77 | c.stateNormal.WithLabelValues(service.Name).Set(1) | 88 | c.stateNormal.WithLabelValues(service.Name).Set(1) |
78 | } else { | 89 | } else { |
@@ -82,6 +93,7 @@ func (c *runitCollector) Update(ch chan<- prometheus.Metric) error { | |||
82 | c.state.Collect(ch) | 93 | c.state.Collect(ch) |
83 | c.stateDesired.Collect(ch) | 94 | c.stateDesired.Collect(ch) |
84 | c.stateNormal.Collect(ch) | 95 | c.stateNormal.Collect(ch) |
96 | c.stateTimestamp.Collect(ch) | ||
85 | 97 | ||
86 | return nil | 98 | return nil |
87 | } | 99 | } |