Add CLI flag to return version info

Fixes wrouesnel/postgres_exporter#67.
This commit is contained in:
Tyler Yahn 2017-05-15 15:30:43 -07:00 committed by Will Rouesnel
parent 1bf7f2435f
commit 5c587cb725

View File

@ -11,6 +11,7 @@ import (
"net/url"
"os"
"regexp"
"runtime"
"strconv"
"sync"
"time"
@ -23,6 +24,7 @@ import (
"github.com/prometheus/common/log"
)
// executable version (set at build time by make)
var Version string = "0.0.1"
var db *sql.DB = nil
@ -44,6 +46,7 @@ var (
"dumpmaps", false,
"Do not run, simply dump the maps.",
)
showVersion = flag.Bool("version", false, "print version")
)
// Metric name parts.
@ -967,6 +970,14 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
func main() {
flag.Parse()
if *showVersion {
fmt.Printf(
"postgres_exporter %s (built with %s)\n",
Version, runtime.Version(),
)
return
}
if *onlyDumpMaps {
dumpMaps()
return