Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 3c72755

Browse files
committed
Put db info on warning logs
1 parent 22fc479 commit 3c72755

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

gauges/deadtuples.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ func (g *Gauges) DeadTuples() *prometheus.GaugeVec {
2020
}, []string{"table"})
2121

2222
if !g.hasExtension("pgstattuple") {
23-
log.Warn("postgresql_dead_tuples_pct disabled because pgstattuple extension is not installed")
23+
log.WithField("db", g.name).
24+
Warn("postgresql_dead_tuples_pct disabled because pgstattuple extension is not installed")
2425
return gauge
2526
}
2627
if !g.hasPermissionToExecutePgStatTuple() {
27-
log.Warn("postgresql_dead_tuples_pct disabled because user doesn't have permission to use pgstattuple functions")
28+
log.WithField("db", g.name).
29+
Warn("postgresql_dead_tuples_pct disabled because user doesn't have permission to use pgstattuple functions")
2830
return gauge
2931
}
3032

@@ -56,7 +58,7 @@ func (g *Gauges) DeadTuples() *prometheus.GaugeVec {
5658

5759
func (g *Gauges) hasPermissionToExecutePgStatTuple() bool {
5860
if _, err := g.db.Exec("SELECT 1 FROM pgstattuple('pg_class')"); err != nil {
59-
log.WithError(err).Error("failed to execute pgstattuple function")
61+
log.WithField("db", g.name).WithError(err).Error("failed to execute pgstattuple function")
6062
return false
6163
}
6264
return true

gauges/gauge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (g *Gauges) queryWithTimeout(
152152
func (g *Gauges) version() string {
153153
var version string
154154
if err := g.db.QueryRow("show server_version").Scan(&version); err != nil {
155-
log.WithError(err).Error("failed to get postgresql version, assuming 9.6.0")
155+
log.WithField("db", g.name).WithError(err).Error("failed to get postgresql version, assuming 9.6.0")
156156
return "9.6.0"
157157
}
158158
return version

gauges/slow_queries.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ func (g *Gauges) SlowestQueries() *prometheus.GaugeVec {
2929
[]string{"query"},
3030
)
3131
if !g.hasExtension("pg_stat_statements") {
32-
log.Warn("postgresql_slowest_queries disabled because pg_stat_statements extension is not installed")
32+
log.WithField("db", g.name).
33+
Warn("postgresql_slowest_queries disabled because pg_stat_statements extension is not installed")
3334
return gauge
3435
}
3536
if !g.hasSharedPreloadLibrary("pg_stat_statements") {
36-
log.Warn("postgresql_slowest_queries disabled because pg_stat_statements is not on shared_preload_libraries")
37+
log.WithField("db", g.name).
38+
Warn("postgresql_slowest_queries disabled because pg_stat_statements is not on shared_preload_libraries")
3739
return gauge
3840
}
3941
go func() {

gauges/vacuum.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ func (g *Gauges) VacuumRunningTotal() prometheus.Gauge {
113113
`
114114

115115
if !postgres.Version(g.version()).Is96Or10() {
116-
log.Warn("postgresql_vacuum_running_total disabled because it's only supported for PostgreSQL 9.6 or newer versions")
116+
log.WithField("db", g.name).
117+
Warn("postgresql_vacuum_running_total disabled because it's only supported for PostgreSQL 9.6 or newer versions")
117118
return prometheus.NewGauge(gaugeOpts)
118119
}
119120
return g.new(gaugeOpts, vacuumRunningQuery)

0 commit comments

Comments
 (0)