diff options
-rw-r--r-- | node_exporter.go | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/node_exporter.go b/node_exporter.go index c9b9f1e..ef570f2 100644 --- a/node_exporter.go +++ b/node_exporter.go | |||
@@ -25,34 +25,25 @@ import ( | |||
25 | 25 | ||
26 | "github.com/prometheus/client_golang/prometheus" | 26 | "github.com/prometheus/client_golang/prometheus" |
27 | "github.com/prometheus/common/log" | 27 | "github.com/prometheus/common/log" |
28 | |||
29 | "github.com/prometheus/node_exporter/collector" | 28 | "github.com/prometheus/node_exporter/collector" |
30 | ) | 29 | ) |
31 | 30 | ||
32 | const subsystem = "exporter" | 31 | const ( |
32 | defaultCollectors = "conntrack,diskstats,entropy,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,version,vmstat" | ||
33 | ) | ||
33 | 34 | ||
34 | var ( | 35 | var ( |
35 | // Version of node_exporter. Set at build time. | 36 | // Version of node_exporter. Set at build time. |
36 | Version = "0.0.0.dev" | 37 | Version = "0.0.0.dev" |
37 | 38 | ||
38 | memProfile = flag.String("debug.memprofile-file", "", "Write memory profile to this file upon receipt of SIGUSR1.") | ||
39 | listenAddress = flag.String("web.listen-address", ":9100", "Address on which to expose metrics and web interface.") | ||
40 | metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") | ||
41 | enabledCollectors = flag.String("collectors.enabled", | ||
42 | filterAvailableCollectors("conntrack,diskstats,entropy,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,version,vmstat"), | ||
43 | "Comma-separated list of collectors to use.") | ||
44 | printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.") | ||
45 | |||
46 | collectorLabelNames = []string{"collector", "result"} | ||
47 | |||
48 | scrapeDurations = prometheus.NewSummaryVec( | 39 | scrapeDurations = prometheus.NewSummaryVec( |
49 | prometheus.SummaryOpts{ | 40 | prometheus.SummaryOpts{ |
50 | Namespace: collector.Namespace, | 41 | Namespace: collector.Namespace, |
51 | Subsystem: subsystem, | 42 | Subsystem: "exporter", |
52 | Name: "scrape_duration_seconds", | 43 | Name: "scrape_duration_seconds", |
53 | Help: "node_exporter: Duration of a scrape job.", | 44 | Help: "node_exporter: Duration of a scrape job.", |
54 | }, | 45 | }, |
55 | collectorLabelNames, | 46 | []string{"collector", "result"}, |
56 | ) | 47 | ) |
57 | ) | 48 | ) |
58 | 49 | ||
@@ -107,9 +98,9 @@ func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) { | |||
107 | scrapeDurations.WithLabelValues(name, result).Observe(duration.Seconds()) | 98 | scrapeDurations.WithLabelValues(name, result).Observe(duration.Seconds()) |
108 | } | 99 | } |
109 | 100 | ||
110 | func loadCollectors() (map[string]collector.Collector, error) { | 101 | func loadCollectors(list string) (map[string]collector.Collector, error) { |
111 | collectors := map[string]collector.Collector{} | 102 | collectors := map[string]collector.Collector{} |
112 | for _, name := range strings.Split(*enabledCollectors, ",") { | 103 | for _, name := range strings.Split(list, ",") { |
113 | fn, ok := collector.Factories[name] | 104 | fn, ok := collector.Factories[name] |
114 | if !ok { | 105 | if !ok { |
115 | return nil, fmt.Errorf("collector '%s' not available", name) | 106 | return nil, fmt.Errorf("collector '%s' not available", name) |
@@ -124,6 +115,12 @@ func loadCollectors() (map[string]collector.Collector, error) { | |||
124 | } | 115 | } |
125 | 116 | ||
126 | func main() { | 117 | func main() { |
118 | var ( | ||
119 | listenAddress = flag.String("web.listen-address", ":9100", "Address on which to expose metrics and web interface.") | ||
120 | metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") | ||
121 | enabledCollectors = flag.String("collectors.enabled", filterAvailableCollectors(defaultCollectors), "Comma-separated list of collectors to use.") | ||
122 | printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.") | ||
123 | ) | ||
127 | flag.Parse() | 124 | flag.Parse() |
128 | 125 | ||
129 | if *printCollectors { | 126 | if *printCollectors { |
@@ -138,7 +135,7 @@ func main() { | |||
138 | } | 135 | } |
139 | return | 136 | return |
140 | } | 137 | } |
141 | collectors, err := loadCollectors() | 138 | collectors, err := loadCollectors(*enabledCollectors) |
142 | if err != nil { | 139 | if err != nil { |
143 | log.Fatalf("Couldn't load collectors: %s", err) | 140 | log.Fatalf("Couldn't load collectors: %s", err) |
144 | } | 141 | } |