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

@ -23,7 +23,7 @@ import (
)
type timeCollector struct {
metric prometheus.Counter
desc *prometheus.Desc
}
func init() {
@ -34,18 +34,17 @@ func init() {
// the current system time in seconds since epoch.
func NewTimeCollector() (Collector, error) {
return &timeCollector{
metric: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Name: "time",
Help: "System time in seconds since epoch (1970).",
}),
desc: prometheus.NewDesc(
Namespace+"_time",
"System time in seconds since epoch (1970).",
nil, nil,
),
}, nil
}
func (c *timeCollector) Update(ch chan<- prometheus.Metric) (err error) {
func (c *timeCollector) Update(ch chan<- prometheus.Metric) error {
now := float64(time.Now().Unix())
log.Debugf("Set time: %f", now)
c.metric.Set(now)
c.metric.Collect(ch)
return err
log.Debugf("Return time: %f", now)
ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, now)
return nil
}