From 46527808aabae62da3a1d923d77ab197b824b827 Mon Sep 17 00:00:00 2001 From: Pavel Borzenkov Date: Fri, 13 Nov 2015 10:42:10 +0300 Subject: [PATCH] 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 --- node_exporter.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/node_exporter.go b/node_exporter.go index 434dd3df..2a075d02 100644 --- a/node_exporter.go +++ b/node_exporter.go @@ -41,8 +41,10 @@ var ( memProfile = flag.String("debug.memprofile-file", "", "Write memory profile to this file upon receipt of SIGUSR1.") listenAddress = flag.String("web.listen-address", ":9100", "Address on which to expose metrics and web interface.") metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") - 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.") - printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.") + enabledCollectors = flag.String("collectors.enabled", + filterAvailableCollectors("diskstats,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname"), + "Comma-separated list of collectors to use.") + printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.") collectorLabelNames = []string{"collector", "result"} @@ -81,6 +83,17 @@ func (n NodeCollector) Collect(ch chan<- prometheus.Metric) { scrapeDurations.Collect(ch) } +func filterAvailableCollectors(collectors string) string { + availableCollectors := make([]string, 0) + for _, c := range strings.Split(collectors, ",") { + _, ok := collector.Factories[c] + if ok { + availableCollectors = append(availableCollectors, c) + } + } + return strings.Join(availableCollectors, ",") +} + func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) { begin := time.Now() err := c.Update(ch)