aboutsummaryrefslogtreecommitdiff
path: root/node_exporter.go
diff options
context:
space:
mode:
authorPavel Borzenkov <pavel.borzenkov@gmail.com>2015-11-13 10:42:10 +0300
committerPavel Borzenkov <pavel.borzenkov@gmail.com>2015-11-13 10:42:10 +0300
commit46527808aabae62da3a1d923d77ab197b824b827 (patch)
tree4917c41b28f4be2d8d96c1b0bedcadca66e42460 /node_exporter.go
parentd3fd2a1944973e8f2ccf2c81d420c0195d7b0796 (diff)
downloadprometheus_node_collector-46527808aabae62da3a1d923d77ab197b824b827.tar.bz2
prometheus_node_collector-46527808aabae62da3a1d923d77ab197b824b827.tar.xz
prometheus_node_collector-46527808aabae62da3a1d923d77ab197b824b827.zip
Filter list of collectors enabled by default
Enabled by default collectors are chosen for Linux, which supports all of the implemented collectors. But for other OSes (OS X, for example) this list is not suitable, because they lack most of those collectors. Because of that, it is not possible to run node_exporter with default options on such OSes. Fix this by filtering list of enabled by default collectors based on their availability for current platform. Closes #149 Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
Diffstat (limited to 'node_exporter.go')
-rw-r--r--node_exporter.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/node_exporter.go b/node_exporter.go
index 434dd3d..2a075d0 100644
--- a/node_exporter.go
+++ b/node_exporter.go
@@ -41,8 +41,10 @@ var (
41 memProfile = flag.String("debug.memprofile-file", "", "Write memory profile to this file upon receipt of SIGUSR1.") 41 memProfile = flag.String("debug.memprofile-file", "", "Write memory profile to this file upon receipt of SIGUSR1.")
42 listenAddress = flag.String("web.listen-address", ":9100", "Address on which to expose metrics and web interface.") 42 listenAddress = flag.String("web.listen-address", ":9100", "Address on which to expose metrics and web interface.")
43 metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") 43 metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
44 enabledCollectors = flag.String("collectors.enabled", "diskstats,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname", "Comma-separated list of collectors to use.") 44 enabledCollectors = flag.String("collectors.enabled",
45 printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.") 45 filterAvailableCollectors("diskstats,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname"),
46 "Comma-separated list of collectors to use.")
47 printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.")
46 48
47 collectorLabelNames = []string{"collector", "result"} 49 collectorLabelNames = []string{"collector", "result"}
48 50
@@ -81,6 +83,17 @@ func (n NodeCollector) Collect(ch chan<- prometheus.Metric) {
81 scrapeDurations.Collect(ch) 83 scrapeDurations.Collect(ch)
82} 84}
83 85
86func filterAvailableCollectors(collectors string) string {
87 availableCollectors := make([]string, 0)
88 for _, c := range strings.Split(collectors, ",") {
89 _, ok := collector.Factories[c]
90 if ok {
91 availableCollectors = append(availableCollectors, c)
92 }
93 }
94 return strings.Join(availableCollectors, ",")
95}
96
84func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) { 97func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
85 begin := time.Now() 98 begin := time.Now()
86 err := c.Update(ch) 99 err := c.Update(ch)