Skip to content

Commit 3601f30

Browse files
committed
Fix version flag
Use Prometheus common/version to print --version output. * Add `-h` short help flag. Fixes: #492 Signed-off-by: Ben Kochie <[email protected]>
1 parent 21f27a8 commit 3601f30

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

cmd/postgres_exporter/postgres_exporter.go

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"net/url"
2525
"os"
2626
"regexp"
27-
"runtime"
2827
"strconv"
2928
"strings"
3029
"sync"
@@ -40,22 +39,6 @@ import (
4039
"gopkg.in/yaml.v2"
4140
)
4241

43-
// Branch is set during build to the git branch.
44-
var Branch string
45-
46-
// BuildDate is set during build to the ISO-8601 date and time.
47-
var BuildDate string
48-
49-
// Revision is set during build to the git commit revision.
50-
var Revision string
51-
52-
// Version is set during build to the git describe version
53-
// (semantic version)-(commitish) form.
54-
var Version = "0.0.1-rev"
55-
56-
// VersionShort is set during build to the semantic version.
57-
var VersionShort = "0.0.1"
58-
5942
var (
6043
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
6144
metricPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").Envar("PG_EXPORTER_WEB_TELEMETRY_PATH").String()
@@ -75,6 +58,8 @@ const (
7558
namespace = "pg"
7659
// Subsystems.
7760
exporter = "exporter"
61+
// The name of the exporter.
62+
exporterName = "postgres_exporter"
7863
// Metric label used for static string data thats handy to send to Prometheus
7964
// e.g. version
8065
staticLabelName = "static"
@@ -1789,8 +1774,9 @@ func contains(a []string, x string) bool {
17891774
}
17901775

17911776
func main() {
1792-
kingpin.Version(fmt.Sprintf("postgres_exporter %s (built with %s)\n", Version, runtime.Version()))
1777+
kingpin.Version(version.Print(exporterName))
17931778
log.AddFlags(kingpin.CommandLine)
1779+
kingpin.HelpFlag.Short('h')
17941780
kingpin.Parse()
17951781

17961782
// landingPage contains the HTML served at '/'.
@@ -1833,11 +1819,7 @@ func main() {
18331819
}()
18341820

18351821
// Setup build info metric.
1836-
version.Branch = Branch
1837-
version.BuildDate = BuildDate
1838-
version.Revision = Revision
1839-
version.Version = VersionShort
1840-
prometheus.MustRegister(version.NewCollector("postgres_exporter"))
1822+
prometheus.MustRegister(version.NewCollector(exporterName))
18411823

18421824
prometheus.MustRegister(exporter)
18431825

0 commit comments

Comments
 (0)