Convert remaining collectors to use ConstMetrics

This commit is contained in:
Johannes 'fish' Ziemke 2016-12-28 15:21:31 +01:00
commit 8e50b80d12
17 changed files with 455 additions and 614 deletions

View file

@ -24,7 +24,7 @@ import (
)
type loadavgCollector struct {
metric []prometheus.Gauge
metric []typedDesc
}
func init() {
@ -34,22 +34,10 @@ func init() {
// Take a prometheus registry and return a new Collector exposing load average.
func NewLoadavgCollector() (Collector, error) {
return &loadavgCollector{
metric: []prometheus.Gauge{
prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "load1",
Help: "1m load average.",
}),
prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "load5",
Help: "5m load average.",
}),
prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "load15",
Help: "15m load average.",
}),
metric: []typedDesc{
{prometheus.NewDesc(Namespace+"_load1", "1m load average.", nil, nil), prometheus.GaugeValue},
{prometheus.NewDesc(Namespace+"_load5", "5m load average.", nil, nil), prometheus.GaugeValue},
{prometheus.NewDesc(Namespace+"_load15", "15m load average.", nil, nil), prometheus.GaugeValue},
},
}, nil
}
@ -60,9 +48,8 @@ func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) (err error) {
return fmt.Errorf("couldn't get load: %s", err)
}
for i, load := range loads {
log.Debugf("Set load %d: %f", i, load)
c.metric[i].Set(load)
c.metric[i].Collect(ch)
log.Debugf("return load %d: %f", i, load)
ch <- c.metric[i].mustNewConstMetric(load)
}
return err
}