Rename metric and removed cruft

This commit is contained in:
Johannes 'fish' Ziemke 2013-07-25 15:55:07 +02:00
parent ada754e7f6
commit 3a58f3b22f
1 changed files with 34 additions and 18 deletions

View File

@ -5,26 +5,42 @@ import (
"github.com/soundcloud/go-runit/runit" "github.com/soundcloud/go-runit/runit"
) )
var ()
type runitCollector struct { type runitCollector struct {
name string name string
config config config config
serviceStatus prometheus.Gauge state prometheus.Gauge
stateDesired prometheus.Gauge
stateNormal prometheus.Gauge
} }
func NewRunitCollector(config config, registry prometheus.Registry) (runitCollector, error) { func NewRunitCollector(config config, registry prometheus.Registry) (runitCollector, error) {
c := runitCollector{ c := runitCollector{
name: "runit_collector", name: "runit_collector",
config: config, config: config,
serviceStatus: prometheus.NewGauge(), state: prometheus.NewGauge(),
stateDesired: prometheus.NewGauge(),
stateNormal: prometheus.NewGauge(),
} }
registry.Register( registry.Register(
"node_service_status", "node_service_state",
"node_exporter: state of runit service.",
prometheus.NilLabels,
c.state,
)
registry.Register(
"node_service_desired_state",
"node_exporter: desired status of runit service.",
prometheus.NilLabels,
c.stateDesired,
)
registry.Register(
"node_service_normal_state",
"node_exporter: status of runit service.", "node_exporter: status of runit service.",
prometheus.NilLabels, prometheus.NilLabels,
c.serviceStatus, c.stateNormal,
) )
return c, nil return c, nil
@ -43,21 +59,21 @@ func (c *runitCollector) Update() (updates int, err error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
debug(c.Name(), "%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration) debug(c.Name(), "%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration)
labels := map[string]string{ labels := map[string]string{
"name": service.Name, "service": service.Name,
"state": runit.StateToString[status.State],
"want": runit.StateToString[status.Want],
} }
c.state.Set(labels, float64(status.State))
c.stateDesired.Set(labels, float64(status.Want))
if status.NormallyUp { if status.NormallyUp {
labels["normally_up"] = "yes" c.stateNormal.Set(labels, 1)
} else { } else {
labels["normally_up"] = "no" c.stateNormal.Set(labels, 1)
} }
updates += 3
c.serviceStatus.Set(labels, float64(status.Duration))
updates++
} }
return updates, err return updates, err
} }