Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • gitlab-org/build/omnibus-mirror/postgres_exporter
1 result
Show changes
Commits on Source (4)
Loading
Loading
@@ -5,6 +5,7 @@
*.test
*-stamp
/.idea
/.vscode
*.iml
/cover.out
/cover.*.out
Loading
Loading
Loading
Loading
@@ -47,6 +47,24 @@ Package vendoring is handled with [`govendor`](https://github.com/kardianos/gove
* `web.telemetry-path`
Path under which to expose metrics.
 
* `disable-default-metrics`
Use only metrics supplied from `queries.yaml` via `--extend.query-path`
* `extend.query-path`
Path to a YAML file containing custom queries to run. Check out [`queries.yaml`](queries.yaml)
for examples of the format.
* `dumpmaps`
Do not run - print the internal representation of the metric maps. Useful when debugging a custom
queries file.
* `log.level`
Set logging level: one of `debug`, `info`, `warn`, `error`, `fatal`
* `log.format`
Set the log output target and format. e.g. `logger:syslog?appname=bob&local=7` or `logger:stdout?json=true`
Defaults to `logger:stderr`.
### Environment Variables
 
The following environment variables configure the exporter:
Loading
Loading
@@ -102,6 +120,12 @@ rich self-documenting metrics for the exporter.
The -extend.query-path command-line argument specifies a YAML file containing additional queries to run.
Some examples are provided in [queries.yaml](queries.yaml).
 
### Disabling default metrics
To work with non-officially-supported postgres versions you can try disabling (e.g. 8.2.15)
or a variant of postgres (e.g. Greenplum) you can disable the default metrics with the `--disable-default-metrics`
flag. This removes all built-in metrics, and uses only metrics defined by queries in the `queries.yaml` file you supply
(so you must supply one, otherwise the exporter will return nothing but internal statuses and not your database).
### Running as non-superuser
 
To be able to collect metrics from pg_stat_activity and pg_stat_replication as non-superuser you have to create views as a superuser, and assign permissions separately to those. In PostgreSQL, views run with the permissions of the user that created them so they can act as security barriers.
Loading
Loading
@@ -136,3 +160,5 @@ GRANT SELECT ON postgres_exporter.pg_stat_replication TO postgres_exporter;
* To build a copy for your current architecture run `go run mage.go binary` or just `go run mage.go`
This will create a symlink to the just built binary in the root directory.
* To build release tar balls run `go run mage.go release`.
* Build system is a bit temperamental at the moment since the conversion to mage - I am working on getting it
to be a perfect out of the box experience, but am time-constrained on it at the moment.
Loading
Loading
@@ -96,7 +96,7 @@ func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
return
case "ms", "s", "min", "h", "d":
unit = "seconds"
case "kB", "MB", "GB", "TB", "8kB", "16kB", "16MB":
case "kB", "MB", "GB", "TB", "8kB", "16kB", "32kB", "16MB":
unit = "bytes"
default:
err = fmt.Errorf("Unknown unit for runtime variable: %q", s.unit)
Loading
Loading
@@ -129,6 +129,8 @@ func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
val *= math.Pow(2, 13)
case "16kB":
val *= math.Pow(2, 14)
case "32kB":
val *= math.Pow(2, 15)
case "16MB":
val *= math.Pow(2, 24)
}
Loading
Loading
Loading
Loading
@@ -33,10 +33,11 @@ import (
var Version = "0.0.1"
 
var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").OverrideDefaultFromEnvar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
metricPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").OverrideDefaultFromEnvar("PG_EXPORTER_WEB_TELEMETRY_PATH").String()
queriesPath = kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").OverrideDefaultFromEnvar("PG_EXPORTER_EXTEND_QUERY_PATH").String()
onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").OverrideDefaultFromEnvar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
metricPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").OverrideDefaultFromEnvar("PG_EXPORTER_WEB_TELEMETRY_PATH").String()
disableDefaultMetrics = kingpin.Flag("disable-default-metrics", "Do not include default metrics.").Default("false").OverrideDefaultFromEnvar("PG_EXPORTER_DISABLE_DEFAULT_METRICS").Bool()
queriesPath = kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").OverrideDefaultFromEnvar("PG_EXPORTER_EXTEND_QUERY_PATH").String()
onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()
)
 
// Metric name parts.
Loading
Loading
@@ -668,13 +669,14 @@ type Exporter struct {
// only, since it just points to the global.
builtinMetricMaps map[string]map[string]ColumnMapping
 
dsn string
userQueriesPath string
duration prometheus.Gauge
error prometheus.Gauge
psqlUp prometheus.Gauge
userQueriesError *prometheus.GaugeVec
totalScrapes prometheus.Counter
dsn string
disableDefaultMetrics bool
userQueriesPath string
duration prometheus.Gauge
error prometheus.Gauge
psqlUp prometheus.Gauge
userQueriesError *prometheus.GaugeVec
totalScrapes prometheus.Counter
 
// dbDsn is the connection string used to establish the dbConnection
dbDsn string
Loading
Loading
@@ -692,11 +694,12 @@ type Exporter struct {
}
 
// NewExporter returns a new PostgreSQL exporter for the provided DSN.
func NewExporter(dsn string, userQueriesPath string) *Exporter {
func NewExporter(dsn string, disableDefaultMetrics bool, userQueriesPath string) *Exporter {
return &Exporter{
builtinMetricMaps: builtinMetricMaps,
dsn: dsn,
userQueriesPath: userQueriesPath,
disableDefaultMetrics: disableDefaultMetrics,
userQueriesPath: userQueriesPath,
duration: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: exporter,
Loading
Loading
@@ -913,7 +916,7 @@ func (e *Exporter) checkMapVersions(ch chan<- prometheus.Metric, db *sql.DB) err
if err != nil {
return fmt.Errorf("Error parsing version string: %v", err)
}
if semanticVersion.LT(lowestSupportedVersion) {
if !e.disableDefaultMetrics && semanticVersion.LT(lowestSupportedVersion) {
log.Warnln("PostgreSQL version is lower then our lowest supported version! Got", semanticVersion.String(), "minimum supported is", lowestSupportedVersion.String())
}
 
Loading
Loading
@@ -922,8 +925,18 @@ func (e *Exporter) checkMapVersions(ch chan<- prometheus.Metric, db *sql.DB) err
log.Infoln("Semantic Version Changed:", e.lastMapVersion.String(), "->", semanticVersion.String())
e.mappingMtx.Lock()
 
e.metricMap = makeDescMap(semanticVersion, e.builtinMetricMaps)
e.queryOverrides = makeQueryOverrideMap(semanticVersion, queryOverrides)
if e.disableDefaultMetrics {
e.metricMap = make(map[string]MetricMapNamespace)
} else {
e.metricMap = makeDescMap(semanticVersion, e.builtinMetricMaps)
}
if e.disableDefaultMetrics {
e.queryOverrides = make(map[string]string)
} else {
e.queryOverrides = makeQueryOverrideMap(semanticVersion, queryOverrides)
}
e.lastMapVersion = semanticVersion
 
if e.userQueriesPath != "" {
Loading
Loading
@@ -1106,7 +1119,7 @@ func main() {
log.Fatal("couldn't find environment variables describing the datasource to use")
}
 
exporter := NewExporter(dsn, *queriesPath)
exporter := NewExporter(dsn, *disableDefaultMetrics, *queriesPath)
defer func() {
if exporter.dbConnection != nil {
exporter.dbConnection.Close() // nolint: errcheck
Loading
Loading
Loading
Loading
@@ -31,7 +31,7 @@ func (s *IntegrationSuite) SetUpSuite(c *C) {
dsn := os.Getenv("DATA_SOURCE_NAME")
c.Assert(dsn, Not(Equals), "")
 
exporter := NewExporter(dsn, "")
exporter := NewExporter(dsn, false, "")
c.Assert(exporter, NotNil)
// Assign the exporter to the suite
s.e = exporter
Loading
Loading
@@ -86,12 +86,12 @@ func (s *IntegrationSuite) TestInvalidDsnDoesntCrash(c *C) {
}()
 
// Send a bad DSN
exporter := NewExporter("invalid dsn", *queriesPath)
exporter := NewExporter("invalid dsn", false, *queriesPath)
c.Assert(exporter, NotNil)
exporter.scrape(ch)
 
// Send a DSN to a non-listening port.
exporter = NewExporter("postgresql://nothing:nothing@127.0.0.1:1/nothing", *queriesPath)
exporter = NewExporter("postgresql://nothing:nothing@127.0.0.1:1/nothing", false, *queriesPath)
c.Assert(exporter, NotNil)
exporter.scrape(ch)
}
Loading
Loading
@@ -109,7 +109,7 @@ func (s *IntegrationSuite) TestUnknownMetricParsingDoesntCrash(c *C) {
dsn := os.Getenv("DATA_SOURCE_NAME")
c.Assert(dsn, Not(Equals), "")
 
exporter := NewExporter(dsn, "")
exporter := NewExporter(dsn, false, "")
c.Assert(exporter, NotNil)
 
// Convert the default maps into a list of empty maps.
Loading
Loading
Loading
Loading
@@ -627,7 +627,7 @@ func makeBuilder(cmd string, platform Platform) func() error {
 
fmt.Println("Building", platform.PlatformBin(cmd))
return sh.RunWith(map[string]string{"CGO_ENABLED": "0", "GOOS": platform.OS, "GOARCH": platform.Arch},
"go", "build", "-a", "-ldflags", fmt.Sprintf("-extldflags '-static' -X version.Version=%s", version),
"go", "build", "-a", "-ldflags", fmt.Sprintf("-extldflags '-static' -X main.Version=%s", version),
"-o", platform.PlatformBin(cmd), cmdSrc)
}
return f
Loading
Loading