aboutsummaryrefslogtreecommitdiff
path: root/node_exporter.go
diff options
context:
space:
mode:
authorJohannes 'fish' Ziemke <github@freigeist.org>2015-05-20 20:04:49 +0200
committerJohannes 'fish' Ziemke <github@freigeist.org>2015-05-21 11:36:56 +0200
commit665b05eedcd802c837b45887b4e4789dff5c70d2 (patch)
treedecb92977cd7aad3e160c29381ab59d8fa33cbac /node_exporter.go
parent5b20dad9adc07cab8ee925c208ca8982fa43d36d (diff)
downloadprometheus_node_collector-665b05eedcd802c837b45887b4e4789dff5c70d2.tar.bz2
prometheus_node_collector-665b05eedcd802c837b45887b4e4789dff5c70d2.tar.xz
prometheus_node_collector-665b05eedcd802c837b45887b4e4789dff5c70d2.zip
Use flags instead of config and remove attributes
Diffstat (limited to 'node_exporter.go')
-rw-r--r--node_exporter.go31
1 files changed, 5 insertions, 26 deletions
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 @@
1package main 1package main
2 2
3import ( 3import (
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
108func getConfig(file string) (*collector.Config, error) { 105func 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
118func 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:")