diff options
author | Steve Durrheimer <s.durrheimer@gmail.com> | 2016-04-30 19:58:17 +0200 |
---|---|---|
committer | Steve Durrheimer <s.durrheimer@gmail.com> | 2016-05-04 08:43:33 +0200 |
commit | 60cbc9efc0ff3a5c25394aeaef0c8df3ebad7037 (patch) | |
tree | 594b54b417bfb9da1ab4cdd0eff21d7a57777f08 /node_exporter.go | |
parent | d890b63fb5ebf6144766cd43bf29f0a0e6192491 (diff) | |
download | prometheus_node_collector-60cbc9efc0ff3a5c25394aeaef0c8df3ebad7037.tar.bz2 prometheus_node_collector-60cbc9efc0ff3a5c25394aeaef0c8df3ebad7037.tar.xz prometheus_node_collector-60cbc9efc0ff3a5c25394aeaef0c8df3ebad7037.zip |
Make version informations consistent between prometheus components
This also fixes #231 by adding the '-version' flag
Diffstat (limited to 'node_exporter.go')
-rw-r--r-- | node_exporter.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/node_exporter.go b/node_exporter.go index 4f64663..1e5594a 100644 --- a/node_exporter.go +++ b/node_exporter.go | |||
@@ -18,6 +18,7 @@ import ( | |||
18 | "fmt" | 18 | "fmt" |
19 | "net/http" | 19 | "net/http" |
20 | _ "net/http/pprof" | 20 | _ "net/http/pprof" |
21 | "os" | ||
21 | "sort" | 22 | "sort" |
22 | "strings" | 23 | "strings" |
23 | "sync" | 24 | "sync" |
@@ -25,17 +26,15 @@ import ( | |||
25 | 26 | ||
26 | "github.com/prometheus/client_golang/prometheus" | 27 | "github.com/prometheus/client_golang/prometheus" |
27 | "github.com/prometheus/common/log" | 28 | "github.com/prometheus/common/log" |
29 | "github.com/prometheus/common/version" | ||
28 | "github.com/prometheus/node_exporter/collector" | 30 | "github.com/prometheus/node_exporter/collector" |
29 | ) | 31 | ) |
30 | 32 | ||
31 | const ( | 33 | const ( |
32 | defaultCollectors = "conntrack,cpu,diskstats,entropy,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,version,vmstat" | 34 | defaultCollectors = "conntrack,cpu,diskstats,entropy,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,vmstat" |
33 | ) | 35 | ) |
34 | 36 | ||
35 | var ( | 37 | var ( |
36 | // Version of node_exporter. Set at build time. | ||
37 | Version = "0.0.0.dev" | ||
38 | |||
39 | scrapeDurations = prometheus.NewSummaryVec( | 38 | scrapeDurations = prometheus.NewSummaryVec( |
40 | prometheus.SummaryOpts{ | 39 | prometheus.SummaryOpts{ |
41 | Namespace: collector.Namespace, | 40 | Namespace: collector.Namespace, |
@@ -114,8 +113,13 @@ func loadCollectors(list string) (map[string]collector.Collector, error) { | |||
114 | return collectors, nil | 113 | return collectors, nil |
115 | } | 114 | } |
116 | 115 | ||
116 | func init() { | ||
117 | prometheus.MustRegister(version.NewCollector("node_exporter")) | ||
118 | } | ||
119 | |||
117 | func main() { | 120 | func main() { |
118 | var ( | 121 | var ( |
122 | showVersion = flag.Bool("version", false, "Print version information.") | ||
119 | listenAddress = flag.String("web.listen-address", ":9100", "Address on which to expose metrics and web interface.") | 123 | 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.") | 124 | 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.") | 125 | enabledCollectors = flag.String("collectors.enabled", filterAvailableCollectors(defaultCollectors), "Comma-separated list of collectors to use.") |
@@ -123,6 +127,14 @@ func main() { | |||
123 | ) | 127 | ) |
124 | flag.Parse() | 128 | flag.Parse() |
125 | 129 | ||
130 | if *showVersion { | ||
131 | fmt.Fprintln(os.Stdout, version.Print("node_exporter")) | ||
132 | os.Exit(0) | ||
133 | } | ||
134 | |||
135 | log.Infoln("Starting node_exporter", version.Info()) | ||
136 | log.Infoln("Build context", version.BuildContext()) | ||
137 | |||
126 | if *printCollectors { | 138 | if *printCollectors { |
127 | collectorNames := make(sort.StringSlice, 0, len(collector.Factories)) | 139 | collectorNames := make(sort.StringSlice, 0, len(collector.Factories)) |
128 | for n := range collector.Factories { | 140 | for n := range collector.Factories { |
@@ -161,7 +173,7 @@ func main() { | |||
161 | </html>`)) | 173 | </html>`)) |
162 | }) | 174 | }) |
163 | 175 | ||
164 | log.Infof("Starting node_exporter v%s at %s", Version, *listenAddress) | 176 | log.Infoln("Listening on", *listenAddress) |
165 | err = http.ListenAndServe(*listenAddress, nil) | 177 | err = http.ListenAndServe(*listenAddress, nil) |
166 | if err != nil { | 178 | if err != nil { |
167 | log.Fatal(err) | 179 | log.Fatal(err) |