aboutsummaryrefslogtreecommitdiff
path: root/collector/time.go
diff options
context:
space:
mode:
authorJohannes 'fish' Ziemke <github@freigeist.org>2016-12-28 15:21:31 +0100
committerJohannes 'fish' Ziemke <github@freigeist.org>2017-01-03 14:11:10 +0100
commit8e50b80d1285be8334066aca7a9f7ec26221f7c1 (patch)
tree71ca4eb02d97823134567ef8956c5b1e5124afde /collector/time.go
parentc53bc168fe759d84ab8a031f2eae0777b221506d (diff)
downloadprometheus_node_collector-8e50b80d1285be8334066aca7a9f7ec26221f7c1.tar.bz2
prometheus_node_collector-8e50b80d1285be8334066aca7a9f7ec26221f7c1.tar.xz
prometheus_node_collector-8e50b80d1285be8334066aca7a9f7ec26221f7c1.zip
Convert remaining collectors to use ConstMetrics
Diffstat (limited to 'collector/time.go')
-rw-r--r--collector/time.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/collector/time.go b/collector/time.go
index 627f467..5854f7a 100644
--- a/collector/time.go
+++ b/collector/time.go
@@ -23,7 +23,7 @@ import (
23) 23)
24 24
25type timeCollector struct { 25type timeCollector struct {
26 metric prometheus.Counter 26 desc *prometheus.Desc
27} 27}
28 28
29func init() { 29func init() {
@@ -34,18 +34,17 @@ func init() {
34// the current system time in seconds since epoch. 34// the current system time in seconds since epoch.
35func NewTimeCollector() (Collector, error) { 35func NewTimeCollector() (Collector, error) {
36 return &timeCollector{ 36 return &timeCollector{
37 metric: prometheus.NewCounter(prometheus.CounterOpts{ 37 desc: prometheus.NewDesc(
38 Namespace: Namespace, 38 Namespace+"_time",
39 Name: "time", 39 "System time in seconds since epoch (1970).",
40 Help: "System time in seconds since epoch (1970).", 40 nil, nil,
41 }), 41 ),
42 }, nil 42 }, nil
43} 43}
44 44
45func (c *timeCollector) Update(ch chan<- prometheus.Metric) (err error) { 45func (c *timeCollector) Update(ch chan<- prometheus.Metric) error {
46 now := float64(time.Now().Unix()) 46 now := float64(time.Now().Unix())
47 log.Debugf("Set time: %f", now) 47 log.Debugf("Return time: %f", now)
48 c.metric.Set(now) 48 ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, now)
49 c.metric.Collect(ch) 49 return nil
50 return err
51} 50}