Make version informations consistent between prometheus components

This also fixes #231 by adding the '-version' flag
This commit is contained in:
Steve Durrheimer 2016-04-30 19:58:17 +02:00
commit 60cbc9efc0
No known key found for this signature in database
GPG key ID: 8F443EBA70F74839
7 changed files with 122 additions and 62 deletions

View file

@ -18,6 +18,7 @@ import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"sort"
"strings"
"sync"
@ -25,17 +26,15 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"
"github.com/prometheus/node_exporter/collector"
)
const (
defaultCollectors = "conntrack,cpu,diskstats,entropy,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,version,vmstat"
defaultCollectors = "conntrack,cpu,diskstats,entropy,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,vmstat"
)
var (
// Version of node_exporter. Set at build time.
Version = "0.0.0.dev"
scrapeDurations = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: collector.Namespace,
@ -114,8 +113,13 @@ func loadCollectors(list string) (map[string]collector.Collector, error) {
return collectors, nil
}
func init() {
prometheus.MustRegister(version.NewCollector("node_exporter"))
}
func main() {
var (
showVersion = flag.Bool("version", false, "Print version information.")
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", filterAvailableCollectors(defaultCollectors), "Comma-separated list of collectors to use.")
@ -123,6 +127,14 @@ func main() {
)
flag.Parse()
if *showVersion {
fmt.Fprintln(os.Stdout, version.Print("node_exporter"))
os.Exit(0)
}
log.Infoln("Starting node_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
if *printCollectors {
collectorNames := make(sort.StringSlice, 0, len(collector.Factories))
for n := range collector.Factories {
@ -161,7 +173,7 @@ func main() {
</html>`))
})
log.Infof("Starting node_exporter v%s at %s", Version, *listenAddress)
log.Infoln("Listening on", *listenAddress)
err = http.ListenAndServe(*listenAddress, nil)
if err != nil {
log.Fatal(err)