Skip to content

Commit 4042410

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 f86ccd6 commit 4042410

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

cmd/postgres_exporter/postgres_exporter.go

+5-23
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"
@@ -45,22 +44,6 @@ import (
4544
"gopkg.in/yaml.v2"
4645
)
4746

48-
// Branch is set during build to the git branch.
49-
var Branch string
50-
51-
// BuildDate is set during build to the ISO-8601 date and time.
52-
var BuildDate string
53-
54-
// Revision is set during build to the git commit revision.
55-
var Revision string
56-
57-
// Version is set during build to the git describe version
58-
// (semantic version)-(commitish) form.
59-
var Version = "0.0.1-rev"
60-
61-
// VersionShort is set during build to the semantic version.
62-
var VersionShort = "0.0.1"
63-
6447
var (
6548
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
6649
webConfig = webflag.AddFlags(kingpin.CommandLine)
@@ -82,6 +65,8 @@ const (
8265
namespace = "pg"
8366
// Subsystems.
8467
exporter = "exporter"
68+
// The name of the exporter.
69+
exporterName = "postgres_exporter"
8570
// Metric label used for static string data thats handy to send to Prometheus
8671
// e.g. version
8772
staticLabelName = "static"
@@ -1796,9 +1781,10 @@ func contains(a []string, x string) bool {
17961781
}
17971782

17981783
func main() {
1799-
kingpin.Version(fmt.Sprintf("postgres_exporter %s (built with %s)\n", Version, runtime.Version()))
1784+
kingpin.Version(version.Print(exporterName))
18001785
promlogConfig := &promlog.Config{}
18011786
flag.AddFlags(kingpin.CommandLine, promlogConfig)
1787+
kingpin.HelpFlag.Short('h')
18021788
kingpin.Parse()
18031789
logger = promlog.New(promlogConfig)
18041790

@@ -1844,11 +1830,7 @@ func main() {
18441830
}()
18451831

18461832
// Setup build info metric.
1847-
version.Branch = Branch
1848-
version.BuildDate = BuildDate
1849-
version.Revision = Revision
1850-
version.Version = VersionShort
1851-
prometheus.MustRegister(version.NewCollector("postgres_exporter"))
1833+
prometheus.MustRegister(version.NewCollector(exporterName))
18521834

18531835
prometheus.MustRegister(exporter)
18541836

0 commit comments

Comments
 (0)