Skip to content

Commit 28e504f

Browse files
SuperQalessio-form3
authored andcommitted
Add a build info metric (prometheus-community#323)
* Add a build info metric Add a standard Prometheus build info metric to make monitoring rollouts easier. * Update prometheus vendoring. * Fix build error Fix missing bool in builtinMetricMaps. Signed-off-by: Ben Kochie <[email protected]> (cherry picked from commit aeec47e)
1 parent 725dd47 commit 28e504f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+16975
-33
lines changed

cmd/postgres_exporter/postgres_exporter.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,52 @@ import (
3131
"github.com/go-kit/log/level"
3232
"github.com/lib/pq"
3333
"github.com/prometheus/client_golang/prometheus"
34+
"github.com/prometheus/client_golang/prometheus/promhttp"
35+
"github.com/prometheus/common/log"
36+
"github.com/prometheus/common/version"
37+
"gopkg.in/alecthomas/kingpin.v2"
38+
"gopkg.in/yaml.v2"
39+
)
40+
41+
// Branch is set during build to the git branch.
42+
var Branch string
43+
44+
// BuildDate is set during build to the ISO-8601 date and time.
45+
var BuildDate string
46+
47+
// Revision is set during build to the git commit revision.
48+
var Revision string
49+
50+
// Version is set during build to the git describe version
51+
// (semantic version)-(commitish) form.
52+
var Version = "0.0.1-rev"
53+
54+
// VersionShort is set during build to the semantic version.
55+
var VersionShort = "0.0.1"
56+
57+
var (
58+
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
59+
metricPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").Envar("PG_EXPORTER_WEB_TELEMETRY_PATH").String()
60+
disableDefaultMetrics = kingpin.Flag("disable-default-metrics", "Do not include default metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_DEFAULT_METRICS").Bool()
61+
disableSettingsMetrics = kingpin.Flag("disable-settings-metrics", "Do not include pg_settings metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_SETTINGS_METRICS").Bool()
62+
autoDiscoverDatabases = kingpin.Flag("auto-discover-databases", "Whether to discover the databases on a server dynamically.").Default("false").Envar("PG_EXPORTER_AUTO_DISCOVER_DATABASES").Bool()
63+
queriesPath = kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").Envar("PG_EXPORTER_EXTEND_QUERY_PATH").String()
64+
onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()
65+
constantLabelsList = kingpin.Flag("constantLabels", "A list of label=value separated by comma(,).").Default("").Envar("PG_EXPORTER_CONSTANT_LABELS").String()
66+
excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String()
67+
)
68+
69+
// Metric name parts.
70+
const (
71+
// Namespace for all metrics.
72+
namespace = "pg"
73+
// Subsystems.
74+
exporter = "exporter"
75+
// Metric label used for static string data thats handy to send to Prometheus
76+
// e.g. version
77+
staticLabelName = "static"
78+
// Metric label used for server identification.
79+
serverLabelName = "server"
3480
)
3581

3682
// ColumnUsage should be one of several enum values which describe how a
@@ -896,6 +942,13 @@ func main() {
896942
exporter.servers.Close()
897943
}()
898944

945+
// Setup build info metric.
946+
version.Branch = Branch
947+
version.BuildDate = BuildDate
948+
version.Revision = Revision
949+
version.Version = VersionShort
950+
prometheus.MustRegister(version.NewCollector("postgres_exporter"))
951+
899952
prometheus.MustRegister(exporter)
900953

901954
http.Handle(*metricPath, promhttp.Handler())

0 commit comments

Comments
 (0)