Merge pull request #494 from prometheus-community/superq/version_info

Fix version flag
This commit is contained in:
Ben Kochie 2021-03-03 18:01:46 +01:00 committed by GitHub
commit 5c660bac37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,6 @@ import (
"net/url" "net/url"
"os" "os"
"regexp" "regexp"
"runtime"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -45,22 +44,6 @@ import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
// Branch is set during build to the git branch.
var Branch string
// BuildDate is set during build to the ISO-8601 date and time.
var BuildDate string
// Revision is set during build to the git commit revision.
var Revision string
// Version is set during build to the git describe version
// (semantic version)-(commitish) form.
var Version = "0.0.1-rev"
// VersionShort is set during build to the semantic version.
var VersionShort = "0.0.1"
var ( var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String() listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
webConfig = webflag.AddFlags(kingpin.CommandLine) webConfig = webflag.AddFlags(kingpin.CommandLine)
@ -82,6 +65,8 @@ const (
namespace = "pg" namespace = "pg"
// Subsystems. // Subsystems.
exporter = "exporter" exporter = "exporter"
// The name of the exporter.
exporterName = "postgres_exporter"
// Metric label used for static string data thats handy to send to Prometheus // Metric label used for static string data thats handy to send to Prometheus
// e.g. version // e.g. version
staticLabelName = "static" staticLabelName = "static"
@ -1796,9 +1781,10 @@ func contains(a []string, x string) bool {
} }
func main() { func main() {
kingpin.Version(fmt.Sprintf("postgres_exporter %s (built with %s)\n", Version, runtime.Version())) kingpin.Version(version.Print(exporterName))
promlogConfig := &promlog.Config{} promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig) flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.HelpFlag.Short('h')
kingpin.Parse() kingpin.Parse()
logger = promlog.New(promlogConfig) logger = promlog.New(promlogConfig)
@ -1843,12 +1829,7 @@ func main() {
exporter.servers.Close() exporter.servers.Close()
}() }()
// Setup build info metric. prometheus.MustRegister(version.NewCollector(exporterName))
version.Branch = Branch
version.BuildDate = BuildDate
version.Revision = Revision
version.Version = VersionShort
prometheus.MustRegister(version.NewCollector("postgres_exporter"))
prometheus.MustRegister(exporter) prometheus.MustRegister(exporter)