aboutsummaryrefslogtreecommitdiff
path: root/collector/time.go
diff options
context:
space:
mode:
authorJohannes 'fish' Ziemke <github@freigeist.org>2014-07-28 12:37:01 +0200
committerJohannes 'fish' Ziemke <github@freigeist.org>2014-07-28 13:02:48 +0200
commit2b3a112b54d27d7b1ac7dc8f503180bbaf038c77 (patch)
treea4312fc28bcfa30e1b5cc18d364fd5033e1fd4b0 /collector/time.go
parent32724a10b099c850b308bb8ba484782a591ef407 (diff)
downloadprometheus_node_collector-2b3a112b54d27d7b1ac7dc8f503180bbaf038c77.tar.bz2
prometheus_node_collector-2b3a112b54d27d7b1ac7dc8f503180bbaf038c77.tar.xz
prometheus_node_collector-2b3a112b54d27d7b1ac7dc8f503180bbaf038c77.zip
Add time exporter
This simple exporter exposes the systems unix time. It's useful to compare it to the prometheus server time and other targets to detect clock skew.
Diffstat (limited to 'collector/time.go')
-rw-r--r--collector/time.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/collector/time.go b/collector/time.go
new file mode 100644
index 0000000..172de88
--- /dev/null
+++ b/collector/time.go
@@ -0,0 +1,47 @@
1// +build !notime
2
3package collector
4
5import (
6 "time"
7
8 "github.com/golang/glog"
9 "github.com/prometheus/client_golang/prometheus"
10)
11
12var (
13 systemTime = prometheus.NewCounter(prometheus.CounterOpts{
14 Namespace: Namespace,
15 Name: "time",
16 Help: "System time in seconds since epoch (1970).",
17 })
18)
19
20type timeCollector struct {
21 config Config
22}
23
24func init() {
25 Factories["time"] = NewTimeCollector
26}
27
28// Takes a config struct and prometheus registry and returns a new Collector exposing
29// the current system time in seconds since epoch.
30func NewTimeCollector(config Config) (Collector, error) {
31 c := timeCollector{
32 config: config,
33 }
34
35 if _, err := prometheus.RegisterOrGet(systemTime); err != nil {
36 return nil, err
37 }
38 return &c, nil
39}
40
41func (c *timeCollector) Update() (updates int, err error) {
42 updates++
43 now := time.Now()
44 glog.V(1).Infof("Set time: %f", now.Unix())
45 systemTime.Set(float64(now.Unix()))
46 return updates, err
47}