diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | collector/attributes.go | 46 | ||||
-rw-r--r-- | collector/bonding.go | 2 | ||||
-rw-r--r-- | collector/collector.go | 7 | ||||
-rw-r--r-- | collector/diskstats.go | 7 | ||||
-rw-r--r-- | collector/filesystem.go | 8 | ||||
-rw-r--r-- | collector/gmond.go | 7 | ||||
-rw-r--r-- | collector/interrupts.go | 8 | ||||
-rw-r--r-- | collector/ipvs.go | 24 | ||||
-rw-r--r-- | collector/ipvs_test.go | 12 | ||||
-rw-r--r-- | collector/lastlogin.go | 8 | ||||
-rw-r--r-- | collector/loadavg.go | 8 | ||||
-rw-r--r-- | collector/megacli.go | 21 | ||||
-rw-r--r-- | collector/meminfo.go | 7 | ||||
-rw-r--r-- | collector/netdev.go | 7 | ||||
-rw-r--r-- | collector/netstat.go | 7 | ||||
-rw-r--r-- | collector/ntp.go | 4 | ||||
-rw-r--r-- | collector/runit.go | 6 | ||||
-rw-r--r-- | collector/stat.go | 8 | ||||
-rw-r--r-- | collector/tcpstat.go | 8 | ||||
-rw-r--r-- | collector/textfile.go | 4 | ||||
-rw-r--r-- | collector/time.go | 8 | ||||
-rw-r--r-- | node_exporter.go | 31 |
23 files changed, 87 insertions, 162 deletions
@@ -31,7 +31,6 @@ Which collectors are used is controlled by the `--collectors.enabled` flag. | |||
31 | 31 | ||
32 | Name | Description | 32 | Name | Description |
33 | ---------|------------ | 33 | ---------|------------ |
34 | attributes | Exposes attributes from the configuration file. Deprecated, use textfile module instead. | ||
35 | diskstats | Exposes disk I/O statistics from `/proc/diskstats`. | 34 | diskstats | Exposes disk I/O statistics from `/proc/diskstats`. |
36 | filesystem | Exposes filesystem statistics, such as disk space used. | 35 | filesystem | Exposes filesystem statistics, such as disk space used. |
37 | loadavg | Exposes load average. | 36 | loadavg | Exposes load average. |
diff --git a/collector/attributes.go b/collector/attributes.go deleted file mode 100644 index 761832b..0000000 --- a/collector/attributes.go +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | // +build !noattributes | ||
2 | |||
3 | package collector | ||
4 | |||
5 | import ( | ||
6 | "github.com/golang/glog" | ||
7 | "github.com/prometheus/client_golang/prometheus" | ||
8 | ) | ||
9 | |||
10 | type attributesCollector struct { | ||
11 | config Config | ||
12 | metric *prometheus.GaugeVec | ||
13 | } | ||
14 | |||
15 | func init() { | ||
16 | Factories["attributes"] = NewAttributesCollector | ||
17 | } | ||
18 | |||
19 | // Takes a config struct and prometheus registry and returns a new Collector exposing | ||
20 | // labels from the config. | ||
21 | func NewAttributesCollector(config Config) (Collector, error) { | ||
22 | labelNames := []string{} | ||
23 | for l := range config.Attributes { | ||
24 | labelNames = append(labelNames, l) | ||
25 | } | ||
26 | |||
27 | return &attributesCollector{ | ||
28 | config: config, | ||
29 | metric: prometheus.NewGaugeVec( | ||
30 | prometheus.GaugeOpts{ | ||
31 | Namespace: Namespace, | ||
32 | Name: "attributes", | ||
33 | Help: "The node_exporter attributes.", | ||
34 | }, | ||
35 | labelNames, | ||
36 | ), | ||
37 | }, nil | ||
38 | } | ||
39 | |||
40 | func (c *attributesCollector) Update(ch chan<- prometheus.Metric) (err error) { | ||
41 | glog.V(1).Info("Set node_attributes{%v}: 1", c.config.Attributes) | ||
42 | c.metric.Reset() | ||
43 | c.metric.With(c.config.Attributes).Set(1) | ||
44 | c.metric.Collect(ch) | ||
45 | return err | ||
46 | } | ||
diff --git a/collector/bonding.go b/collector/bonding.go index 1a13245..05cc9af 100644 --- a/collector/bonding.go +++ b/collector/bonding.go | |||
@@ -26,7 +26,7 @@ func init() { | |||
26 | 26 | ||
27 | // NewBondingCollector returns a newly allocated bondingCollector. | 27 | // NewBondingCollector returns a newly allocated bondingCollector. |
28 | // It exposes the number of configured and active slave of linux bonding interfaces. | 28 | // It exposes the number of configured and active slave of linux bonding interfaces. |
29 | func NewBondingCollector(config Config) (Collector, error) { | 29 | func NewBondingCollector() (Collector, error) { |
30 | return &bondingCollector{ | 30 | return &bondingCollector{ |
31 | slaves: prometheus.NewGaugeVec( | 31 | slaves: prometheus.NewGaugeVec( |
32 | prometheus.GaugeOpts{ | 32 | prometheus.GaugeOpts{ |
diff --git a/collector/collector.go b/collector/collector.go index f6fc0a6..571098f 100644 --- a/collector/collector.go +++ b/collector/collector.go | |||
@@ -7,7 +7,7 @@ import ( | |||
7 | 7 | ||
8 | const Namespace = "node" | 8 | const Namespace = "node" |
9 | 9 | ||
10 | var Factories = make(map[string]func(Config) (Collector, error)) | 10 | var Factories = make(map[string]func() (Collector, error)) |
11 | 11 | ||
12 | // Interface a collector has to implement. | 12 | // Interface a collector has to implement. |
13 | type Collector interface { | 13 | type Collector interface { |
@@ -20,8 +20,3 @@ type Collector interface { | |||
20 | // scraped. (However, for metric gathering that takes very long, it might | 20 | // scraped. (However, for metric gathering that takes very long, it might |
21 | // actually be better to do them proactively before scraping to minimize scrape | 21 | // actually be better to do them proactively before scraping to minimize scrape |
22 | // time.) | 22 | // time.) |
23 | |||
24 | type Config struct { | ||
25 | Config map[string]string `json:"config"` | ||
26 | Attributes map[string]string `json:"attributes"` | ||
27 | } | ||
diff --git a/collector/diskstats.go b/collector/diskstats.go index 82927c4..1f61db2 100644 --- a/collector/diskstats.go +++ b/collector/diskstats.go | |||
@@ -26,7 +26,7 @@ var ( | |||
26 | ) | 26 | ) |
27 | 27 | ||
28 | type diskstatsCollector struct { | 28 | type diskstatsCollector struct { |
29 | config Config | 29 | |
30 | ignoredDevicesPattern *regexp.Regexp | 30 | ignoredDevicesPattern *regexp.Regexp |
31 | metrics []prometheus.Collector | 31 | metrics []prometheus.Collector |
32 | } | 32 | } |
@@ -35,13 +35,12 @@ func init() { | |||
35 | Factories["diskstats"] = NewDiskstatsCollector | 35 | Factories["diskstats"] = NewDiskstatsCollector |
36 | } | 36 | } |
37 | 37 | ||
38 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 38 | // Takes a prometheus registry and returns a new Collector exposing |
39 | // disk device stats. | 39 | // disk device stats. |
40 | func NewDiskstatsCollector(config Config) (Collector, error) { | 40 | func NewDiskstatsCollector() (Collector, error) { |
41 | var diskLabelNames = []string{"device"} | 41 | var diskLabelNames = []string{"device"} |
42 | 42 | ||
43 | return &diskstatsCollector{ | 43 | return &diskstatsCollector{ |
44 | config: config, | ||
45 | ignoredDevicesPattern: regexp.MustCompile(*ignoredDevices), | 44 | ignoredDevicesPattern: regexp.MustCompile(*ignoredDevices), |
46 | // Docs from https://www.kernel.org/doc/Documentation/iostats.txt | 45 | // Docs from https://www.kernel.org/doc/Documentation/iostats.txt |
47 | metrics: []prometheus.Collector{ | 46 | metrics: []prometheus.Collector{ |
diff --git a/collector/filesystem.go b/collector/filesystem.go index e2b170f..0640571 100644 --- a/collector/filesystem.go +++ b/collector/filesystem.go | |||
@@ -25,7 +25,7 @@ var ( | |||
25 | ) | 25 | ) |
26 | 26 | ||
27 | type filesystemCollector struct { | 27 | type filesystemCollector struct { |
28 | config Config | 28 | |
29 | ignoredMountPointsPattern *regexp.Regexp | 29 | ignoredMountPointsPattern *regexp.Regexp |
30 | 30 | ||
31 | size, free, avail, files, filesFree *prometheus.GaugeVec | 31 | size, free, avail, files, filesFree *prometheus.GaugeVec |
@@ -35,13 +35,13 @@ func init() { | |||
35 | Factories["filesystem"] = NewFilesystemCollector | 35 | Factories["filesystem"] = NewFilesystemCollector |
36 | } | 36 | } |
37 | 37 | ||
38 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 38 | // Takes a prometheus registry and returns a new Collector exposing |
39 | // network device filesystems. | 39 | // network device filesystems. |
40 | func NewFilesystemCollector(config Config) (Collector, error) { | 40 | func NewFilesystemCollector() (Collector, error) { |
41 | var filesystemLabelNames = []string{"filesystem"} | 41 | var filesystemLabelNames = []string{"filesystem"} |
42 | 42 | ||
43 | return &filesystemCollector{ | 43 | return &filesystemCollector{ |
44 | config: config, | 44 | |
45 | ignoredMountPointsPattern: regexp.MustCompile(*ignoredMountPoints), | 45 | ignoredMountPointsPattern: regexp.MustCompile(*ignoredMountPoints), |
46 | size: prometheus.NewGaugeVec( | 46 | size: prometheus.NewGaugeVec( |
47 | prometheus.GaugeOpts{ | 47 | prometheus.GaugeOpts{ |
diff --git a/collector/gmond.go b/collector/gmond.go index 457b405..4694d08 100644 --- a/collector/gmond.go +++ b/collector/gmond.go | |||
@@ -25,7 +25,7 @@ const ( | |||
25 | 25 | ||
26 | type gmondCollector struct { | 26 | type gmondCollector struct { |
27 | metrics map[string]*prometheus.GaugeVec | 27 | metrics map[string]*prometheus.GaugeVec |
28 | config Config | 28 | |
29 | } | 29 | } |
30 | 30 | ||
31 | func init() { | 31 | func init() { |
@@ -34,10 +34,9 @@ func init() { | |||
34 | 34 | ||
35 | var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`) | 35 | var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`) |
36 | 36 | ||
37 | // Takes a config struct and prometheus registry and returns a new Collector scraping ganglia. | 37 | // Takes a prometheus registry and returns a new Collector scraping ganglia. |
38 | func NewGmondCollector(config Config) (Collector, error) { | 38 | func NewGmondCollector() (Collector, error) { |
39 | c := gmondCollector{ | 39 | c := gmondCollector{ |
40 | config: config, | ||
41 | metrics: map[string]*prometheus.GaugeVec{}, | 40 | metrics: map[string]*prometheus.GaugeVec{}, |
42 | } | 41 | } |
43 | 42 | ||
diff --git a/collector/interrupts.go b/collector/interrupts.go index 74c98e9..6ec4073 100644 --- a/collector/interrupts.go +++ b/collector/interrupts.go | |||
@@ -18,7 +18,7 @@ const ( | |||
18 | ) | 18 | ) |
19 | 19 | ||
20 | type interruptsCollector struct { | 20 | type interruptsCollector struct { |
21 | config Config | 21 | |
22 | metric *prometheus.CounterVec | 22 | metric *prometheus.CounterVec |
23 | } | 23 | } |
24 | 24 | ||
@@ -26,11 +26,11 @@ func init() { | |||
26 | Factories["interrupts"] = NewInterruptsCollector | 26 | Factories["interrupts"] = NewInterruptsCollector |
27 | } | 27 | } |
28 | 28 | ||
29 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 29 | // Takes a prometheus registry and returns a new Collector exposing |
30 | // interrupts stats | 30 | // interrupts stats |
31 | func NewInterruptsCollector(config Config) (Collector, error) { | 31 | func NewInterruptsCollector() (Collector, error) { |
32 | return &interruptsCollector{ | 32 | return &interruptsCollector{ |
33 | config: config, | 33 | |
34 | metric: prometheus.NewCounterVec( | 34 | metric: prometheus.NewCounterVec( |
35 | prometheus.CounterOpts{ | 35 | prometheus.CounterOpts{ |
36 | Namespace: Namespace, | 36 | Namespace: Namespace, |
diff --git a/collector/ipvs.go b/collector/ipvs.go index ac37706..f77cc50 100644 --- a/collector/ipvs.go +++ b/collector/ipvs.go | |||
@@ -3,6 +3,7 @@ | |||
3 | package collector | 3 | package collector |
4 | 4 | ||
5 | import ( | 5 | import ( |
6 | "flag" | ||
6 | "fmt" | 7 | "fmt" |
7 | "strconv" | 8 | "strconv" |
8 | 9 | ||
@@ -10,6 +11,10 @@ import ( | |||
10 | "github.com/prometheus/procfs" | 11 | "github.com/prometheus/procfs" |
11 | ) | 12 | ) |
12 | 13 | ||
14 | var ( | ||
15 | ipvsProcfsMountPoint = flag.String("collector.ipvs.procfs", procfs.DefaultMountPoint, "procfs mountpoint.") | ||
16 | ) | ||
17 | |||
13 | type ipvsCollector struct { | 18 | type ipvsCollector struct { |
14 | Collector | 19 | Collector |
15 | fs procfs.FS | 20 | fs procfs.FS |
@@ -23,11 +28,11 @@ func init() { | |||
23 | 28 | ||
24 | // NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the | 29 | // NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the |
25 | // "procfs" config parameter to override the default proc location (/proc). | 30 | // "procfs" config parameter to override the default proc location (/proc). |
26 | func NewIPVSCollector(config Config) (Collector, error) { | 31 | func NewIPVSCollector() (Collector, error) { |
27 | return newIPVSCollector(config) | 32 | return newIPVSCollector() |
28 | } | 33 | } |
29 | 34 | ||
30 | func newIPVSCollector(config Config) (*ipvsCollector, error) { | 35 | func newIPVSCollector() (*ipvsCollector, error) { |
31 | var ( | 36 | var ( |
32 | ipvsBackendLabelNames = []string{ | 37 | ipvsBackendLabelNames = []string{ |
33 | "local_address", | 38 | "local_address", |
@@ -37,23 +42,14 @@ func newIPVSCollector(config Config) (*ipvsCollector, error) { | |||
37 | "proto", | 42 | "proto", |
38 | } | 43 | } |
39 | c ipvsCollector | 44 | c ipvsCollector |
40 | subsystem string | ||
41 | err error | 45 | err error |
46 | subsystem = "ipvs" | ||
42 | ) | 47 | ) |
43 | 48 | ||
44 | if p, ok := config.Config["procfs"]; !ok { | 49 | c.fs, err = procfs.NewFS(*ipvsProcfsMountPoint) |
45 | c.fs, err = procfs.NewFS(procfs.DefaultMountPoint) | ||
46 | } else { | ||
47 | c.fs, err = procfs.NewFS(p) | ||
48 | } | ||
49 | if err != nil { | 50 | if err != nil { |
50 | return nil, err | 51 | return nil, err |
51 | } | 52 | } |
52 | if s, ok := config.Config["ipvs_subsystem"]; ok { | ||
53 | subsystem = s | ||
54 | } else { | ||
55 | subsystem = "ipvs" | ||
56 | } | ||
57 | 53 | ||
58 | c.connections = prometheus.NewCounter( | 54 | c.connections = prometheus.NewCounter( |
59 | prometheus.CounterOpts{ | 55 | prometheus.CounterOpts{ |
diff --git a/collector/ipvs_test.go b/collector/ipvs_test.go index 65fd4e1..d9326e4 100644 --- a/collector/ipvs_test.go +++ b/collector/ipvs_test.go | |||
@@ -1,6 +1,7 @@ | |||
1 | package collector | 1 | package collector |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "flag" | ||
4 | "io/ioutil" | 5 | "io/ioutil" |
5 | "net" | 6 | "net" |
6 | "net/http" | 7 | "net/http" |
@@ -106,7 +107,10 @@ var ( | |||
106 | ) | 107 | ) |
107 | 108 | ||
108 | func TestIPVSCollector(t *testing.T) { | 109 | func TestIPVSCollector(t *testing.T) { |
109 | collector, err := newIPVSCollector(Config{Config: map[string]string{"procfs": "fixtures"}}) | 110 | if err := flag.Set("collector.ipvs.procfs", "fixtures"); err != nil { |
111 | t.Fatal(err) | ||
112 | } | ||
113 | collector, err := newIPVSCollector() | ||
110 | if err != nil { | 114 | if err != nil { |
111 | t.Fatal(err) | 115 | t.Fatal(err) |
112 | } | 116 | } |
@@ -165,7 +169,10 @@ func (c miniCollector) Describe(ch chan<- *prometheus.Desc) { | |||
165 | } | 169 | } |
166 | 170 | ||
167 | func TestIPVSCollectorResponse(t *testing.T) { | 171 | func TestIPVSCollectorResponse(t *testing.T) { |
168 | collector, err := NewIPVSCollector(Config{Config: map[string]string{"procfs": "fixtures"}}) | 172 | if err := flag.Set("collector.ipvs.procfs", "fixtures"); err != nil { |
173 | t.Fatal(err) | ||
174 | } | ||
175 | collector, err := NewIPVSCollector() | ||
169 | if err != nil { | 176 | if err != nil { |
170 | t.Fatal(err) | 177 | t.Fatal(err) |
171 | } | 178 | } |
@@ -183,6 +190,7 @@ func TestIPVSCollectorResponse(t *testing.T) { | |||
183 | wantLines := strings.Split(string(wantMetrics), "\n") | 190 | wantLines := strings.Split(string(wantMetrics), "\n") |
184 | gotLines := strings.Split(string(rw.Body.String()), "\n") | 191 | gotLines := strings.Split(string(rw.Body.String()), "\n") |
185 | gotLinesIdx := 0 | 192 | gotLinesIdx := 0 |
193 | t.Log(gotLines) | ||
186 | 194 | ||
187 | // Until the Prometheus Go client library offers better testability | 195 | // Until the Prometheus Go client library offers better testability |
188 | // (https://github.com/prometheus/client_golang/issues/58), we simply compare | 196 | // (https://github.com/prometheus/client_golang/issues/58), we simply compare |
diff --git a/collector/lastlogin.go b/collector/lastlogin.go index 3574da0..05aee4a 100644 --- a/collector/lastlogin.go +++ b/collector/lastlogin.go | |||
@@ -17,7 +17,7 @@ import ( | |||
17 | const lastLoginSubsystem = "last_login" | 17 | const lastLoginSubsystem = "last_login" |
18 | 18 | ||
19 | type lastLoginCollector struct { | 19 | type lastLoginCollector struct { |
20 | config Config | 20 | |
21 | metric prometheus.Gauge | 21 | metric prometheus.Gauge |
22 | } | 22 | } |
23 | 23 | ||
@@ -25,11 +25,11 @@ func init() { | |||
25 | Factories["lastlogin"] = NewLastLoginCollector | 25 | Factories["lastlogin"] = NewLastLoginCollector |
26 | } | 26 | } |
27 | 27 | ||
28 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 28 | // Takes a prometheus registry and returns a new Collector exposing |
29 | // 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. |
30 | func NewLastLoginCollector(config Config) (Collector, error) { | 30 | func NewLastLoginCollector() (Collector, error) { |
31 | return &lastLoginCollector{ | 31 | return &lastLoginCollector{ |
32 | config: config, | 32 | |
33 | metric: prometheus.NewGauge(prometheus.GaugeOpts{ | 33 | metric: prometheus.NewGauge(prometheus.GaugeOpts{ |
34 | Namespace: Namespace, | 34 | Namespace: Namespace, |
35 | Subsystem: lastLoginSubsystem, | 35 | Subsystem: lastLoginSubsystem, |
diff --git a/collector/loadavg.go b/collector/loadavg.go index 6b157d2..8f40e1d 100644 --- a/collector/loadavg.go +++ b/collector/loadavg.go | |||
@@ -17,7 +17,7 @@ const ( | |||
17 | ) | 17 | ) |
18 | 18 | ||
19 | type loadavgCollector struct { | 19 | type loadavgCollector struct { |
20 | config Config | 20 | |
21 | metric prometheus.Gauge | 21 | metric prometheus.Gauge |
22 | } | 22 | } |
23 | 23 | ||
@@ -25,11 +25,11 @@ func init() { | |||
25 | Factories["loadavg"] = NewLoadavgCollector | 25 | Factories["loadavg"] = NewLoadavgCollector |
26 | } | 26 | } |
27 | 27 | ||
28 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 28 | // Takes a prometheus registry and returns a new Collector exposing |
29 | // 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. |
30 | func NewLoadavgCollector(config Config) (Collector, error) { | 30 | func NewLoadavgCollector() (Collector, error) { |
31 | return &loadavgCollector{ | 31 | return &loadavgCollector{ |
32 | config: config, | 32 | |
33 | metric: prometheus.NewGauge(prometheus.GaugeOpts{ | 33 | metric: prometheus.NewGauge(prometheus.GaugeOpts{ |
34 | Namespace: Namespace, | 34 | Namespace: Namespace, |
35 | Name: "load1", | 35 | Name: "load1", |
diff --git a/collector/megacli.go b/collector/megacli.go index fd4ccfc..e83eb49 100644 --- a/collector/megacli.go +++ b/collector/megacli.go | |||
@@ -4,6 +4,7 @@ package collector | |||
4 | 4 | ||
5 | import ( | 5 | import ( |
6 | "bufio" | 6 | "bufio" |
7 | "flag" | ||
7 | "io" | 8 | "io" |
8 | "os/exec" | 9 | "os/exec" |
9 | "strconv" | 10 | "strconv" |
@@ -17,9 +18,12 @@ const ( | |||
17 | adapterHeaderSep = "================" | 18 | adapterHeaderSep = "================" |
18 | ) | 19 | ) |
19 | 20 | ||
21 | var ( | ||
22 | megacliCommand = flag.String("collector.megacli.command", defaultMegaCli, "Command to run megacli.") | ||
23 | ) | ||
24 | |||
20 | type megaCliCollector struct { | 25 | type megaCliCollector struct { |
21 | config Config | 26 | cli string |
22 | cli string | ||
23 | 27 | ||
24 | driveTemperature *prometheus.GaugeVec | 28 | driveTemperature *prometheus.GaugeVec |
25 | driveCounters *prometheus.CounterVec | 29 | driveCounters *prometheus.CounterVec |
@@ -30,17 +34,12 @@ func init() { | |||
30 | Factories["megacli"] = NewMegaCliCollector | 34 | Factories["megacli"] = NewMegaCliCollector |
31 | } | 35 | } |
32 | 36 | ||
33 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 37 | // Takes a prometheus registry and returns a new Collector exposing |
34 | // RAID status through megacli. | 38 | // RAID status through megacli. |
35 | func NewMegaCliCollector(config Config) (Collector, error) { | 39 | func NewMegaCliCollector() (Collector, error) { |
36 | cli := defaultMegaCli | ||
37 | if config.Config["megacli_command"] != "" { | ||
38 | cli = config.Config["megacli_command"] | ||
39 | } | ||
40 | |||
41 | return &megaCliCollector{ | 40 | return &megaCliCollector{ |
42 | config: config, | 41 | |
43 | cli: cli, | 42 | cli: *megacliCommand, |
44 | driveTemperature: prometheus.NewGaugeVec(prometheus.GaugeOpts{ | 43 | driveTemperature: prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
45 | Namespace: Namespace, | 44 | Namespace: Namespace, |
46 | Name: "megacli_drive_temperature_celsius", | 45 | Name: "megacli_drive_temperature_celsius", |
diff --git a/collector/meminfo.go b/collector/meminfo.go index 58a6e70..434e5bc 100644 --- a/collector/meminfo.go +++ b/collector/meminfo.go | |||
@@ -21,7 +21,7 @@ const ( | |||
21 | ) | 21 | ) |
22 | 22 | ||
23 | type meminfoCollector struct { | 23 | type meminfoCollector struct { |
24 | config Config | 24 | |
25 | metrics map[string]prometheus.Gauge | 25 | metrics map[string]prometheus.Gauge |
26 | } | 26 | } |
27 | 27 | ||
@@ -29,11 +29,10 @@ func init() { | |||
29 | Factories["meminfo"] = NewMeminfoCollector | 29 | Factories["meminfo"] = NewMeminfoCollector |
30 | } | 30 | } |
31 | 31 | ||
32 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 32 | // Takes a prometheus registry and returns a new Collector exposing |
33 | // memory stats. | 33 | // memory stats. |
34 | func NewMeminfoCollector(config Config) (Collector, error) { | 34 | func NewMeminfoCollector() (Collector, error) { |
35 | return &meminfoCollector{ | 35 | return &meminfoCollector{ |
36 | config: config, | ||
37 | metrics: map[string]prometheus.Gauge{}, | 36 | metrics: map[string]prometheus.Gauge{}, |
38 | }, nil | 37 | }, nil |
39 | } | 38 | } |
diff --git a/collector/netdev.go b/collector/netdev.go index e5d0afd..ee538bc 100644 --- a/collector/netdev.go +++ b/collector/netdev.go | |||
@@ -19,7 +19,7 @@ const ( | |||
19 | ) | 19 | ) |
20 | 20 | ||
21 | type netDevCollector struct { | 21 | type netDevCollector struct { |
22 | config Config | 22 | |
23 | metrics map[string]*prometheus.GaugeVec | 23 | metrics map[string]*prometheus.GaugeVec |
24 | } | 24 | } |
25 | 25 | ||
@@ -27,11 +27,10 @@ func init() { | |||
27 | Factories["netdev"] = NewNetDevCollector | 27 | Factories["netdev"] = NewNetDevCollector |
28 | } | 28 | } |
29 | 29 | ||
30 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 30 | // Takes a prometheus registry and returns a new Collector exposing |
31 | // network device stats. | 31 | // network device stats. |
32 | func NewNetDevCollector(config Config) (Collector, error) { | 32 | func NewNetDevCollector() (Collector, error) { |
33 | return &netDevCollector{ | 33 | return &netDevCollector{ |
34 | config: config, | ||
35 | metrics: map[string]*prometheus.GaugeVec{}, | 34 | metrics: map[string]*prometheus.GaugeVec{}, |
36 | }, nil | 35 | }, nil |
37 | } | 36 | } |
diff --git a/collector/netstat.go b/collector/netstat.go index d7f2532..6e93b6a 100644 --- a/collector/netstat.go +++ b/collector/netstat.go | |||
@@ -19,7 +19,7 @@ const ( | |||
19 | ) | 19 | ) |
20 | 20 | ||
21 | type netStatCollector struct { | 21 | type netStatCollector struct { |
22 | config Config | 22 | |
23 | metrics map[string]prometheus.Gauge | 23 | metrics map[string]prometheus.Gauge |
24 | } | 24 | } |
25 | 25 | ||
@@ -27,11 +27,10 @@ func init() { | |||
27 | Factories["netstat"] = NewNetStatCollector | 27 | Factories["netstat"] = NewNetStatCollector |
28 | } | 28 | } |
29 | 29 | ||
30 | // NewNetStatCollector takes a config struct and returns | 30 | // NewNetStatCollector takes a returns |
31 | // a new Collector exposing network stats. | 31 | // a new Collector exposing network stats. |
32 | func NewNetStatCollector(config Config) (Collector, error) { | 32 | func NewNetStatCollector() (Collector, error) { |
33 | return &netStatCollector{ | 33 | return &netStatCollector{ |
34 | config: config, | ||
35 | metrics: map[string]prometheus.Gauge{}, | 34 | metrics: map[string]prometheus.Gauge{}, |
36 | }, nil | 35 | }, nil |
37 | } | 36 | } |
diff --git a/collector/ntp.go b/collector/ntp.go index ba57ee3..844ecd4 100644 --- a/collector/ntp.go +++ b/collector/ntp.go | |||
@@ -24,9 +24,9 @@ func init() { | |||
24 | Factories["ntp"] = NewNtpCollector | 24 | Factories["ntp"] = NewNtpCollector |
25 | } | 25 | } |
26 | 26 | ||
27 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 27 | // Takes a prometheus registry and returns a new Collector exposing |
28 | // the offset between ntp and the current system time. | 28 | // the offset between ntp and the current system time. |
29 | func NewNtpCollector(config Config) (Collector, error) { | 29 | func NewNtpCollector() (Collector, error) { |
30 | if *ntpServer == "" { | 30 | if *ntpServer == "" { |
31 | return nil, fmt.Errorf("No NTP server specifies, see --ntpServer") | 31 | return nil, fmt.Errorf("No NTP server specifies, see --ntpServer") |
32 | } | 32 | } |
diff --git a/collector/runit.go b/collector/runit.go index 989c904..abb23f1 100644 --- a/collector/runit.go +++ b/collector/runit.go | |||
@@ -9,7 +9,7 @@ import ( | |||
9 | ) | 9 | ) |
10 | 10 | ||
11 | type runitCollector struct { | 11 | type runitCollector struct { |
12 | config Config | 12 | |
13 | 13 | ||
14 | state, stateDesired, stateNormal *prometheus.GaugeVec | 14 | state, stateDesired, stateNormal *prometheus.GaugeVec |
15 | } | 15 | } |
@@ -18,7 +18,7 @@ func init() { | |||
18 | Factories["runit"] = NewRunitCollector | 18 | Factories["runit"] = NewRunitCollector |
19 | } | 19 | } |
20 | 20 | ||
21 | func NewRunitCollector(config Config) (Collector, error) { | 21 | func NewRunitCollector() (Collector, error) { |
22 | var ( | 22 | var ( |
23 | subsystem = "service" | 23 | subsystem = "service" |
24 | constLabels = prometheus.Labels{"supervisor": "runit"} | 24 | constLabels = prometheus.Labels{"supervisor": "runit"} |
@@ -26,7 +26,7 @@ func NewRunitCollector(config Config) (Collector, error) { | |||
26 | ) | 26 | ) |
27 | 27 | ||
28 | return &runitCollector{ | 28 | return &runitCollector{ |
29 | config: config, | 29 | |
30 | state: prometheus.NewGaugeVec( | 30 | state: prometheus.NewGaugeVec( |
31 | prometheus.GaugeOpts{ | 31 | prometheus.GaugeOpts{ |
32 | Namespace: Namespace, | 32 | Namespace: Namespace, |
diff --git a/collector/stat.go b/collector/stat.go index 7c7beeb..68b7e40 100644 --- a/collector/stat.go +++ b/collector/stat.go | |||
@@ -17,7 +17,7 @@ const ( | |||
17 | ) | 17 | ) |
18 | 18 | ||
19 | type statCollector struct { | 19 | type statCollector struct { |
20 | config Config | 20 | |
21 | cpu *prometheus.CounterVec | 21 | cpu *prometheus.CounterVec |
22 | intr prometheus.Counter | 22 | intr prometheus.Counter |
23 | ctxt prometheus.Counter | 23 | ctxt prometheus.Counter |
@@ -31,11 +31,11 @@ func init() { | |||
31 | Factories["stat"] = NewStatCollector | 31 | Factories["stat"] = NewStatCollector |
32 | } | 32 | } |
33 | 33 | ||
34 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 34 | // Takes a prometheus registry and returns a new Collector exposing |
35 | // network device stats. | 35 | // network device stats. |
36 | func NewStatCollector(config Config) (Collector, error) { | 36 | func NewStatCollector() (Collector, error) { |
37 | return &statCollector{ | 37 | return &statCollector{ |
38 | config: config, | 38 | |
39 | cpu: prometheus.NewCounterVec( | 39 | cpu: prometheus.NewCounterVec( |
40 | prometheus.CounterOpts{ | 40 | prometheus.CounterOpts{ |
41 | Namespace: Namespace, | 41 | Namespace: Namespace, |
diff --git a/collector/tcpstat.go b/collector/tcpstat.go index d8bee65..1584f8f 100644 --- a/collector/tcpstat.go +++ b/collector/tcpstat.go | |||
@@ -35,7 +35,7 @@ const ( | |||
35 | ) | 35 | ) |
36 | 36 | ||
37 | type tcpStatCollector struct { | 37 | type tcpStatCollector struct { |
38 | config Config | 38 | |
39 | metric *prometheus.GaugeVec | 39 | metric *prometheus.GaugeVec |
40 | } | 40 | } |
41 | 41 | ||
@@ -43,11 +43,11 @@ func init() { | |||
43 | Factories["tcpstat"] = NewTCPStatCollector | 43 | Factories["tcpstat"] = NewTCPStatCollector |
44 | } | 44 | } |
45 | 45 | ||
46 | // NewTCPStatCollector takes a config struct and returns | 46 | // NewTCPStatCollector takes a returns |
47 | // a new Collector exposing network stats. | 47 | // a new Collector exposing network stats. |
48 | func NewTCPStatCollector(config Config) (Collector, error) { | 48 | func NewTCPStatCollector() (Collector, error) { |
49 | return &tcpStatCollector{ | 49 | return &tcpStatCollector{ |
50 | config: config, | 50 | |
51 | metric: prometheus.NewGaugeVec( | 51 | metric: prometheus.NewGaugeVec( |
52 | prometheus.GaugeOpts{ | 52 | prometheus.GaugeOpts{ |
53 | Namespace: Namespace, | 53 | Namespace: Namespace, |
diff --git a/collector/textfile.go b/collector/textfile.go index a8d98c1..382274b 100644 --- a/collector/textfile.go +++ b/collector/textfile.go | |||
@@ -31,9 +31,9 @@ func init() { | |||
31 | Factories["textfile"] = NewTextFileCollector | 31 | Factories["textfile"] = NewTextFileCollector |
32 | } | 32 | } |
33 | 33 | ||
34 | // Takes a config struct and registers a | 34 | // Takes a registers a |
35 | // SetMetricFamilyInjectionHook. | 35 | // SetMetricFamilyInjectionHook. |
36 | func NewTextFileCollector(config Config) (Collector, error) { | 36 | func NewTextFileCollector() (Collector, error) { |
37 | if *textFileDirectory == "" { | 37 | if *textFileDirectory == "" { |
38 | // This collector is enabled by default, so do not fail if | 38 | // This collector is enabled by default, so do not fail if |
39 | // the flag is not passed. | 39 | // the flag is not passed. |
diff --git a/collector/time.go b/collector/time.go index 83a7f23..6a0ba69 100644 --- a/collector/time.go +++ b/collector/time.go | |||
@@ -10,7 +10,7 @@ import ( | |||
10 | ) | 10 | ) |
11 | 11 | ||
12 | type timeCollector struct { | 12 | type timeCollector struct { |
13 | config Config | 13 | |
14 | metric prometheus.Counter | 14 | metric prometheus.Counter |
15 | } | 15 | } |
16 | 16 | ||
@@ -18,11 +18,11 @@ func init() { | |||
18 | Factories["time"] = NewTimeCollector | 18 | Factories["time"] = NewTimeCollector |
19 | } | 19 | } |
20 | 20 | ||
21 | // Takes a config struct and prometheus registry and returns a new Collector exposing | 21 | // Takes a prometheus registry and returns a new Collector exposing |
22 | // the current system time in seconds since epoch. | 22 | // the current system time in seconds since epoch. |
23 | func NewTimeCollector(config Config) (Collector, error) { | 23 | func NewTimeCollector() (Collector, error) { |
24 | return &timeCollector{ | 24 | return &timeCollector{ |
25 | config: config, | 25 | |
26 | metric: prometheus.NewCounter(prometheus.CounterOpts{ | 26 | metric: prometheus.NewCounter(prometheus.CounterOpts{ |
27 | Namespace: Namespace, | 27 | Namespace: Namespace, |
28 | Name: "time", | 28 | Name: "time", |
diff --git a/node_exporter.go b/node_exporter.go index 26966e5..7c7911a 100644 --- a/node_exporter.go +++ b/node_exporter.go | |||
@@ -1,10 +1,8 @@ | |||
1 | package main | 1 | package main |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "encoding/json" | ||
5 | "flag" | 4 | "flag" |
6 | "fmt" | 5 | "fmt" |
7 | "io/ioutil" | ||
8 | "net/http" | 6 | "net/http" |
9 | _ "net/http/pprof" | 7 | _ "net/http/pprof" |
10 | "os" | 8 | "os" |
@@ -26,11 +24,10 @@ var ( | |||
26 | // set at build time | 24 | // set at build time |
27 | Version = "0.0.0.dev" | 25 | Version = "0.0.0.dev" |
28 | 26 | ||
29 | configFile = flag.String("config.file", "", "Path to config file.") | ||
30 | memProfile = flag.String("debug.memprofile-file", "", "Write memory profile to this file upon receipt of SIGUSR1.") | 27 | memProfile = flag.String("debug.memprofile-file", "", "Write memory profile to this file upon receipt of SIGUSR1.") |
31 | listenAddress = flag.String("web.listen-address", ":9100", "Address on which to expose metrics and web interface.") | 28 | listenAddress = flag.String("web.listen-address", ":9100", "Address on which to expose metrics and web interface.") |
32 | metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") | 29 | metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") |
33 | enabledCollectors = flag.String("collectors.enabled", "attributes,diskstats,filesystem,loadavg,meminfo,stat,textfile,time,netdev,netstat", "Comma-separated list of collectors to use.") | 30 | enabledCollectors = flag.String("collectors.enabled", "diskstats,filesystem,loadavg,meminfo,stat,textfile,time,netdev,netstat", "Comma-separated list of collectors to use.") |
34 | printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.") | 31 | printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.") |
35 | authUser = flag.String("auth.user", "", "Username for basic auth.") | 32 | authUser = flag.String("auth.user", "", "Username for basic auth.") |
36 | authPass = flag.String("auth.pass", "", "Password for basic auth.") | 33 | authPass = flag.String("auth.pass", "", "Password for basic auth.") |
@@ -105,32 +102,14 @@ func Execute(name string, c collector.Collector, ch chan<- prometheus.Metric) { | |||
105 | scrapeDurations.WithLabelValues(name, result).Observe(duration.Seconds()) | 102 | scrapeDurations.WithLabelValues(name, result).Observe(duration.Seconds()) |
106 | } | 103 | } |
107 | 104 | ||
108 | func getConfig(file string) (*collector.Config, error) { | 105 | func loadCollectors() (map[string]collector.Collector, error) { |
109 | config := &collector.Config{} | ||
110 | glog.Infof("Reading config %s", *configFile) | ||
111 | bytes, err := ioutil.ReadFile(*configFile) | ||
112 | if err != nil { | ||
113 | return nil, err | ||
114 | } | ||
115 | return config, json.Unmarshal(bytes, &config) | ||
116 | } | ||
117 | |||
118 | func loadCollectors(file string) (map[string]collector.Collector, error) { | ||
119 | collectors := map[string]collector.Collector{} | 106 | collectors := map[string]collector.Collector{} |
120 | config := &collector.Config{} | ||
121 | if file != "" { | ||
122 | var err error | ||
123 | config, err = getConfig(file) | ||
124 | if err != nil { | ||
125 | return nil, fmt.Errorf("couldn't read config %s: %s", file, err) | ||
126 | } | ||
127 | } | ||
128 | for _, name := range strings.Split(*enabledCollectors, ",") { | 107 | for _, name := range strings.Split(*enabledCollectors, ",") { |
129 | fn, ok := collector.Factories[name] | 108 | fn, ok := collector.Factories[name] |
130 | if !ok { | 109 | if !ok { |
131 | return nil, fmt.Errorf("collector '%s' not available", name) | 110 | return nil, fmt.Errorf("collector '%s' not available", name) |
132 | } | 111 | } |
133 | c, err := fn(*config) | 112 | c, err := fn() |
134 | if err != nil { | 113 | if err != nil { |
135 | return nil, err | 114 | return nil, err |
136 | } | 115 | } |
@@ -154,9 +133,9 @@ func main() { | |||
154 | } | 133 | } |
155 | return | 134 | return |
156 | } | 135 | } |
157 | collectors, err := loadCollectors(*configFile) | 136 | collectors, err := loadCollectors() |
158 | if err != nil { | 137 | if err != nil { |
159 | glog.Fatalf("Couldn't load config and collectors: %s", err) | 138 | glog.Fatalf("Couldn't load collectors: %s", err) |
160 | } | 139 | } |
161 | 140 | ||
162 | glog.Infof("Enabled collectors:") | 141 | glog.Infof("Enabled collectors:") |