You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.1 KiB
91 lines
2.1 KiB
10 years ago
|
// +build !norunit
|
||
11 years ago
|
|
||
11 years ago
|
package collector
|
||
12 years ago
|
|
||
|
import (
|
||
11 years ago
|
"github.com/golang/glog"
|
||
12 years ago
|
"github.com/prometheus/client_golang/prometheus"
|
||
|
"github.com/soundcloud/go-runit/runit"
|
||
|
)
|
||
|
|
||
|
type runitCollector struct {
|
||
11 years ago
|
config Config
|
||
10 years ago
|
|
||
|
state, stateDesired, stateNormal *prometheus.GaugeVec
|
||
12 years ago
|
}
|
||
|
|
||
11 years ago
|
func init() {
|
||
11 years ago
|
Factories["runit"] = NewRunitCollector
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
func NewRunitCollector(config Config) (Collector, error) {
|
||
10 years ago
|
var (
|
||
|
subsystem = "service"
|
||
|
constLabels = prometheus.Labels{"supervisor": "runit"}
|
||
|
labelNames = []string{"service"}
|
||
|
)
|
||
12 years ago
|
|
||
10 years ago
|
return &runitCollector{
|
||
|
config: config,
|
||
|
state: prometheus.NewGaugeVec(
|
||
|
prometheus.GaugeOpts{
|
||
10 years ago
|
Namespace: Namespace,
|
||
|
Subsystem: subsystem,
|
||
|
Name: "state",
|
||
|
Help: "state of runit service.",
|
||
|
ConstLabels: constLabels,
|
||
10 years ago
|
},
|
||
10 years ago
|
labelNames,
|
||
10 years ago
|
),
|
||
|
stateDesired: prometheus.NewGaugeVec(
|
||
|
prometheus.GaugeOpts{
|
||
10 years ago
|
Namespace: Namespace,
|
||
|
Subsystem: subsystem,
|
||
|
Name: "desired_state",
|
||
|
Help: "desired state of runit service.",
|
||
|
ConstLabels: constLabels,
|
||
10 years ago
|
},
|
||
10 years ago
|
labelNames,
|
||
10 years ago
|
),
|
||
|
stateNormal: prometheus.NewGaugeVec(
|
||
|
prometheus.GaugeOpts{
|
||
10 years ago
|
Namespace: Namespace,
|
||
|
Subsystem: subsystem,
|
||
|
Name: "normal_state",
|
||
|
Help: "normal state of runit service.",
|
||
|
ConstLabels: constLabels,
|
||
10 years ago
|
},
|
||
10 years ago
|
labelNames,
|
||
10 years ago
|
),
|
||
|
}, nil
|
||
12 years ago
|
}
|
||
|
|
||
10 years ago
|
func (c *runitCollector) Update(ch chan<- prometheus.Metric) error {
|
||
11 years ago
|
services, err := runit.GetServices("/etc/service")
|
||
12 years ago
|
if err != nil {
|
||
10 years ago
|
return err
|
||
12 years ago
|
}
|
||
|
|
||
|
for _, service := range services {
|
||
|
status, err := service.Status()
|
||
|
if err != nil {
|
||
11 years ago
|
glog.V(1).Infof("Couldn't get status for %s: %s, skipping...", service.Name, err)
|
||
11 years ago
|
continue
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
11 years ago
|
glog.V(1).Infof("%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration)
|
||
10 years ago
|
c.state.WithLabelValues(service.Name).Set(float64(status.State))
|
||
|
c.stateDesired.WithLabelValues(service.Name).Set(float64(status.Want))
|
||
12 years ago
|
if status.NormallyUp {
|
||
10 years ago
|
c.stateNormal.WithLabelValues(service.Name).Set(1)
|
||
12 years ago
|
} else {
|
||
10 years ago
|
c.stateNormal.WithLabelValues(service.Name).Set(0)
|
||
12 years ago
|
}
|
||
|
}
|
||
10 years ago
|
c.state.Collect(ch)
|
||
|
c.stateDesired.Collect(ch)
|
||
|
c.stateNormal.Collect(ch)
|
||
|
|
||
|
return nil
|
||
12 years ago
|
}
|