mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-31 16:37:31 -08:00
1c17481a42
Switch to Update using the Collecter Collect interface, due to not knowing all metricnames in all modules beforehand we can't use Describe and thus the full Collecter interface. Remove 'updates', it's meaning varies by module and doesn't add much.
45 lines
883 B
Go
45 lines
883 B
Go
// +build !notime
|
|
|
|
package collector
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/golang/glog"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
var (
|
|
systemTime = prometheus.NewCounter(prometheus.CounterOpts{
|
|
Namespace: Namespace,
|
|
Name: "time",
|
|
Help: "System time in seconds since epoch (1970).",
|
|
})
|
|
)
|
|
|
|
type timeCollector struct {
|
|
config Config
|
|
}
|
|
|
|
func init() {
|
|
Factories["time"] = NewTimeCollector
|
|
}
|
|
|
|
// Takes a config struct and prometheus registry and returns a new Collector exposing
|
|
// the current system time in seconds since epoch.
|
|
func NewTimeCollector(config Config) (Collector, error) {
|
|
c := timeCollector{
|
|
config: config,
|
|
}
|
|
|
|
return &c, nil
|
|
}
|
|
|
|
func (c *timeCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
|
now := time.Now()
|
|
glog.V(1).Infof("Set time: %f", now.Unix())
|
|
systemTime.Set(float64(now.Unix()))
|
|
systemTime.Collect(ch)
|
|
return err
|
|
}
|