diff options
author | Tobias Schmidt <ts@soundcloud.com> | 2014-11-24 21:00:17 -0500 |
---|---|---|
committer | Tobias Schmidt <ts@soundcloud.com> | 2014-11-24 21:08:50 -0500 |
commit | 872f921867eadca491876bb2e6ad17d05cf2808a (patch) | |
tree | 3c888b689076d1ac2c7e9b91bae0ae89d282be15 /collector/loadavg.go | |
parent | 974f6fc7624aae3014f44178ba99f55be731470e (diff) | |
download | prometheus_node_collector-872f921867eadca491876bb2e6ad17d05cf2808a.tar.bz2 prometheus_node_collector-872f921867eadca491876bb2e6ad17d05cf2808a.tar.xz prometheus_node_collector-872f921867eadca491876bb2e6ad17d05cf2808a.zip |
Reduce number of global variables used
This is the first step to make the exporter more testable.
Diffstat (limited to 'collector/loadavg.go')
-rw-r--r-- | collector/loadavg.go | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/collector/loadavg.go b/collector/loadavg.go index b4ab9d4..6b157d2 100644 --- a/collector/loadavg.go +++ b/collector/loadavg.go | |||
@@ -16,16 +16,9 @@ const ( | |||
16 | procLoad = "/proc/loadavg" | 16 | procLoad = "/proc/loadavg" |
17 | ) | 17 | ) |
18 | 18 | ||
19 | var ( | ||
20 | load1 = prometheus.NewGauge(prometheus.GaugeOpts{ | ||
21 | Namespace: Namespace, | ||
22 | Name: "load1", | ||
23 | Help: "1m load average.", | ||
24 | }) | ||
25 | ) | ||
26 | |||
27 | type loadavgCollector struct { | 19 | type loadavgCollector struct { |
28 | config Config | 20 | config Config |
21 | metric prometheus.Gauge | ||
29 | } | 22 | } |
30 | 23 | ||
31 | func init() { | 24 | func init() { |
@@ -35,10 +28,14 @@ func init() { | |||
35 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 28 | // Takes a config struct and prometheus registry and returns a new Collector exposing |
36 | // load, seconds since last login and a list of tags as specified by config. | 29 | // load, seconds since last login and a list of tags as specified by config. |
37 | func NewLoadavgCollector(config Config) (Collector, error) { | 30 | func NewLoadavgCollector(config Config) (Collector, error) { |
38 | c := loadavgCollector{ | 31 | return &loadavgCollector{ |
39 | config: config, | 32 | config: config, |
40 | } | 33 | metric: prometheus.NewGauge(prometheus.GaugeOpts{ |
41 | return &c, nil | 34 | Namespace: Namespace, |
35 | Name: "load1", | ||
36 | Help: "1m load average.", | ||
37 | }), | ||
38 | }, nil | ||
42 | } | 39 | } |
43 | 40 | ||
44 | func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) (err error) { | 41 | func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) (err error) { |
@@ -47,8 +44,8 @@ func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) (err error) { | |||
47 | return fmt.Errorf("Couldn't get load: %s", err) | 44 | return fmt.Errorf("Couldn't get load: %s", err) |
48 | } | 45 | } |
49 | glog.V(1).Infof("Set node_load: %f", load) | 46 | glog.V(1).Infof("Set node_load: %f", load) |
50 | load1.Set(load) | 47 | c.metric.Set(load) |
51 | load1.Collect(ch) | 48 | c.metric.Collect(ch) |
52 | return err | 49 | return err |
53 | } | 50 | } |
54 | 51 | ||