Added command-line flag to disable the default metrics
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,6 +5,7 @@
|
|||||||
*.test
|
*.test
|
||||||
*-stamp
|
*-stamp
|
||||||
/.idea
|
/.idea
|
||||||
|
/.vscode
|
||||||
*.iml
|
*.iml
|
||||||
/cover.out
|
/cover.out
|
||||||
/cover.*.out
|
/cover.*.out
|
||||||
|
|||||||
@@ -102,6 +102,12 @@ rich self-documenting metrics for the exporter.
|
|||||||
The -extend.query-path command-line argument specifies a YAML file containing additional queries to run.
|
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).
|
Some examples are provided in [queries.yaml](queries.yaml).
|
||||||
|
|
||||||
|
### Working with non-officially-supported postgres versions
|
||||||
|
|
||||||
|
If you want to use this exporter to monitor a postgres installation that is not officially supported (e.g. 8.2.15) or a variant of postgres (e.g. Greenplum).
|
||||||
|
You may try to disable all internal metrics using the -disable-default-metrics command-line argument, then supply your own set of metrics definitions in
|
||||||
|
an external config file.
|
||||||
|
|
||||||
### Running as non-superuser
|
### 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.
|
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.
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ var Version = "0.0.1"
|
|||||||
var (
|
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()
|
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()
|
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()
|
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()
|
onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()
|
||||||
)
|
)
|
||||||
@@ -669,6 +670,7 @@ type Exporter struct {
|
|||||||
builtinMetricMaps map[string]map[string]ColumnMapping
|
builtinMetricMaps map[string]map[string]ColumnMapping
|
||||||
|
|
||||||
dsn string
|
dsn string
|
||||||
|
disableDefaultMetrics bool
|
||||||
userQueriesPath string
|
userQueriesPath string
|
||||||
duration prometheus.Gauge
|
duration prometheus.Gauge
|
||||||
error prometheus.Gauge
|
error prometheus.Gauge
|
||||||
@@ -692,10 +694,11 @@ type Exporter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewExporter returns a new PostgreSQL exporter for the provided DSN.
|
// 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{
|
return &Exporter{
|
||||||
builtinMetricMaps: builtinMetricMaps,
|
builtinMetricMaps: builtinMetricMaps,
|
||||||
dsn: dsn,
|
dsn: dsn,
|
||||||
|
disableDefaultMetrics: disableDefaultMetrics,
|
||||||
userQueriesPath: userQueriesPath,
|
userQueriesPath: userQueriesPath,
|
||||||
duration: prometheus.NewGauge(prometheus.GaugeOpts{
|
duration: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@@ -913,7 +916,7 @@ func (e *Exporter) checkMapVersions(ch chan<- prometheus.Metric, db *sql.DB) err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error parsing version string: %v", err)
|
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())
|
log.Warnln("PostgreSQL version is lower then our lowest supported version! Got", semanticVersion.String(), "minimum supported is", lowestSupportedVersion.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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())
|
log.Infoln("Semantic Version Changed:", e.lastMapVersion.String(), "->", semanticVersion.String())
|
||||||
e.mappingMtx.Lock()
|
e.mappingMtx.Lock()
|
||||||
|
|
||||||
|
if e.disableDefaultMetrics {
|
||||||
|
e.metricMap = make(map[string]MetricMapNamespace)
|
||||||
|
} else {
|
||||||
e.metricMap = makeDescMap(semanticVersion, e.builtinMetricMaps)
|
e.metricMap = makeDescMap(semanticVersion, e.builtinMetricMaps)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.disableDefaultMetrics {
|
||||||
|
e.queryOverrides = make(map[string]string)
|
||||||
|
} else {
|
||||||
e.queryOverrides = makeQueryOverrideMap(semanticVersion, queryOverrides)
|
e.queryOverrides = makeQueryOverrideMap(semanticVersion, queryOverrides)
|
||||||
|
}
|
||||||
|
|
||||||
e.lastMapVersion = semanticVersion
|
e.lastMapVersion = semanticVersion
|
||||||
|
|
||||||
if e.userQueriesPath != "" {
|
if e.userQueriesPath != "" {
|
||||||
@@ -1106,7 +1119,7 @@ func main() {
|
|||||||
log.Fatal("couldn't find environment variables describing the datasource to use")
|
log.Fatal("couldn't find environment variables describing the datasource to use")
|
||||||
}
|
}
|
||||||
|
|
||||||
exporter := NewExporter(dsn, *queriesPath)
|
exporter := NewExporter(dsn, *disableDefaultMetrics, *queriesPath)
|
||||||
defer func() {
|
defer func() {
|
||||||
if exporter.dbConnection != nil {
|
if exporter.dbConnection != nil {
|
||||||
exporter.dbConnection.Close() // nolint: errcheck
|
exporter.dbConnection.Close() // nolint: errcheck
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func (s *IntegrationSuite) SetUpSuite(c *C) {
|
|||||||
dsn := os.Getenv("DATA_SOURCE_NAME")
|
dsn := os.Getenv("DATA_SOURCE_NAME")
|
||||||
c.Assert(dsn, Not(Equals), "")
|
c.Assert(dsn, Not(Equals), "")
|
||||||
|
|
||||||
exporter := NewExporter(dsn, "")
|
exporter := NewExporter(dsn, false, "")
|
||||||
c.Assert(exporter, NotNil)
|
c.Assert(exporter, NotNil)
|
||||||
// Assign the exporter to the suite
|
// Assign the exporter to the suite
|
||||||
s.e = exporter
|
s.e = exporter
|
||||||
@@ -86,12 +86,12 @@ func (s *IntegrationSuite) TestInvalidDsnDoesntCrash(c *C) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// Send a bad DSN
|
// Send a bad DSN
|
||||||
exporter := NewExporter("invalid dsn", *queriesPath)
|
exporter := NewExporter("invalid dsn", false, *queriesPath)
|
||||||
c.Assert(exporter, NotNil)
|
c.Assert(exporter, NotNil)
|
||||||
exporter.scrape(ch)
|
exporter.scrape(ch)
|
||||||
|
|
||||||
// Send a DSN to a non-listening port.
|
// 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)
|
c.Assert(exporter, NotNil)
|
||||||
exporter.scrape(ch)
|
exporter.scrape(ch)
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ func (s *IntegrationSuite) TestUnknownMetricParsingDoesntCrash(c *C) {
|
|||||||
dsn := os.Getenv("DATA_SOURCE_NAME")
|
dsn := os.Getenv("DATA_SOURCE_NAME")
|
||||||
c.Assert(dsn, Not(Equals), "")
|
c.Assert(dsn, Not(Equals), "")
|
||||||
|
|
||||||
exporter := NewExporter(dsn, "")
|
exporter := NewExporter(dsn, false, "")
|
||||||
c.Assert(exporter, NotNil)
|
c.Assert(exporter, NotNil)
|
||||||
|
|
||||||
// Convert the default maps into a list of empty maps.
|
// Convert the default maps into a list of empty maps.
|
||||||
|
|||||||
Reference in New Issue
Block a user