Skip to content

Commit 5078dc9

Browse files
committed
Fix up collector registration
Use const definitions to make collector registration consistent. * Use collector subsystem name consistently. * Fix up replication metric name unit. Signed-off-by: SuperQ <[email protected]>
1 parent 3e585c4 commit 5078dc9

10 files changed

+65
-29
lines changed

collector/pg_database.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import (
2121
"github.com/prometheus/client_golang/prometheus"
2222
)
2323

24+
const databaseSubsystem = "database"
25+
2426
func init() {
25-
registerCollector("database", defaultEnabled, NewPGDatabaseCollector)
27+
registerCollector(databaseSubsystem, defaultEnabled, NewPGDatabaseCollector)
2628
}
2729

2830
type PGDatabaseCollector struct {
@@ -43,7 +45,11 @@ func NewPGDatabaseCollector(config collectorConfig) (Collector, error) {
4345

4446
var (
4547
pgDatabaseSizeDesc = prometheus.NewDesc(
46-
"pg_database_size_bytes",
48+
prometheus.BuildFQName(
49+
namespace,
50+
databaseSubsystem,
51+
"size_bytes",
52+
),
4753
"Disk space used by the database",
4854
[]string{"datname"}, nil,
4955
)

collector/pg_postmaster.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
"github.com/prometheus/client_golang/prometheus"
2121
)
2222

23+
const postmasterSubsystem = "postmaster"
24+
2325
func init() {
24-
registerCollector("postmaster", defaultEnabled, NewPGPostmasterCollector)
26+
registerCollector(postmasterSubsystem, defaultEnabled, NewPGPostmasterCollector)
2527
}
2628

2729
type PGPostmasterCollector struct {
@@ -33,7 +35,11 @@ func NewPGPostmasterCollector(collectorConfig) (Collector, error) {
3335

3436
var (
3537
pgPostMasterStartTimeSeconds = prometheus.NewDesc(
36-
"pg_postmaster_start_time_seconds",
38+
prometheus.BuildFQName(
39+
namespace,
40+
postmasterSubsystem,
41+
"start_time_seconds",
42+
),
3743
"Time at which postmaster started",
3844
[]string{}, nil,
3945
)

collector/pg_process_idle.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ import (
2121
"github.com/prometheus/client_golang/prometheus"
2222
)
2323

24+
const processIdleSubsystem = "process_idle"
25+
2426
func init() {
25-
registerCollector("statements", defaultEnabled, NewPGProcessIdleCollector)
27+
registerCollector(processIdleSubsystem, defaultEnabled, NewPGProcessIdleCollector)
2628
}
2729

2830
type PGProcessIdleCollector struct {
2931
log log.Logger
3032
}
3133

32-
const processIdleSubsystem = "process_idle"
33-
3434
func NewPGProcessIdleCollector(config collectorConfig) (Collector, error) {
3535
return &PGProcessIdleCollector{log: config.logger}, nil
3636
}

collector/pg_replication.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
"github.com/prometheus/client_golang/prometheus"
2121
)
2222

23+
const replicationSubsystem = "replication"
24+
2325
func init() {
24-
registerCollector("replication", defaultEnabled, NewPGReplicationCollector)
26+
registerCollector(replicationSubsystem, defaultEnabled, NewPGReplicationCollector)
2527
}
2628

2729
type PGReplicationCollector struct {
@@ -33,12 +35,20 @@ func NewPGReplicationCollector(collectorConfig) (Collector, error) {
3335

3436
var (
3537
pgReplicationLag = prometheus.NewDesc(
36-
"pg_replication_lag",
38+
prometheus.BuildFQName(
39+
namespace,
40+
replicationSubsystem,
41+
"lag_seconds",
42+
),
3743
"Replication lag behind master in seconds",
3844
[]string{}, nil,
3945
)
4046
pgReplicationIsReplica = prometheus.NewDesc(
41-
"pg_replication_is_replica",
47+
prometheus.BuildFQName(
48+
namespace,
49+
replicationSubsystem,
50+
"is_replica",
51+
),
4252
"Indicates if the server is a replica",
4353
[]string{}, nil,
4454
)

collector/pg_stat_bgwriter.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import (
2121
"github.com/prometheus/client_golang/prometheus"
2222
)
2323

24+
const bgWriterSubsystem = "stat_bgwriter"
25+
2426
func init() {
25-
registerCollector("bgwriter", defaultEnabled, NewPGStatBGWriterCollector)
27+
registerCollector(bgWriterSubsystem, defaultEnabled, NewPGStatBGWriterCollector)
2628
}
2729

2830
type PGStatBGWriterCollector struct {
@@ -32,8 +34,6 @@ func NewPGStatBGWriterCollector(collectorConfig) (Collector, error) {
3234
return &PGStatBGWriterCollector{}, nil
3335
}
3436

35-
const bgWriterSubsystem = "stat_bgwriter"
36-
3737
var (
3838
statBGWriterCheckpointsTimedDesc = prometheus.NewDesc(
3939
prometheus.BuildFQName(namespace, bgWriterSubsystem, "checkpoints_timed_total"),

collector/pg_stat_database.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
"github.com/prometheus/client_golang/prometheus"
2121
)
2222

23+
const statDatabaseSubsystem = "stat_database"
24+
2325
func init() {
24-
registerCollector("stat_database", defaultEnabled, NewPGStatDatabaseCollector)
26+
registerCollector(statDatabaseSubsystem, defaultEnabled, NewPGStatDatabaseCollector)
2527
}
2628

2729
type PGStatDatabaseCollector struct{}
@@ -30,8 +32,6 @@ func NewPGStatDatabaseCollector(config collectorConfig) (Collector, error) {
3032
return &PGStatDatabaseCollector{}, nil
3133
}
3234

33-
const statDatabaseSubsystem = "stat_database"
34-
3535
var (
3636
statDatabaseNumbackends = prometheus.NewDesc(
3737
prometheus.BuildFQName(

collector/pg_stat_statements.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ import (
2121
"github.com/prometheus/client_golang/prometheus"
2222
)
2323

24+
const statStatementsSubsystem = "stat_statements"
25+
2426
func init() {
2527
// WARNING:
2628
// Disabled by default because this set of metrics can be quite expensive on a busy server
2729
// Every unique query will cause a new timeseries to be created
28-
registerCollector("statements", defaultDisabled, NewPGStatStatementsCollector)
30+
registerCollector(statStatementsSubsystem, defaultDisabled, NewPGStatStatementsCollector)
2931
}
3032

3133
type PGStatStatementsCollector struct {
3234
log log.Logger
3335
}
3436

35-
const statStatementsSubsystem = "stat_statements"
36-
3737
func NewPGStatStatementsCollector(config collectorConfig) (Collector, error) {
3838
return &PGStatStatementsCollector{log: config.logger}, nil
3939
}

collector/pg_stat_user_tables.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ import (
2222
"github.com/prometheus/client_golang/prometheus"
2323
)
2424

25+
const userTableSubsystem = "stat_user_tables"
26+
2527
func init() {
26-
registerCollector("user_tables", defaultEnabled, NewPGStatUserTablesCollector)
28+
registerCollector(userTableSubsystem, defaultEnabled, NewPGStatUserTablesCollector)
2729
}
2830

2931
type PGStatUserTablesCollector struct {
3032
log log.Logger
3133
}
3234

33-
const userTableSubsystem = "stat_user_tables"
34-
3535
func NewPGStatUserTablesCollector(config collectorConfig) (Collector, error) {
3636
return &PGStatUserTablesCollector{log: config.logger}, nil
3737
}

collector/pg_statio_user_tables.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ import (
2121
"github.com/prometheus/client_golang/prometheus"
2222
)
2323

24+
const statioUserTableSubsystem = "statio_user_tables"
25+
2426
func init() {
25-
registerCollector("statio_user_tables", defaultEnabled, NewPGStatIOUserTablesCollector)
27+
registerCollector(statioUserTableSubsystem, defaultEnabled, NewPGStatIOUserTablesCollector)
2628
}
2729

2830
type PGStatIOUserTablesCollector struct {
2931
log log.Logger
3032
}
3133

32-
const statioUserTableSubsystem = "statio_user_tables"
33-
3434
func NewPGStatIOUserTablesCollector(config collectorConfig) (Collector, error) {
3535
return &PGStatIOUserTablesCollector{log: config.logger}, nil
3636
}

collector/replication_slots.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import (
2121
"github.com/prometheus/client_golang/prometheus"
2222
)
2323

24+
const replicationSlotSubsystem = "replication_slot"
25+
2426
func init() {
25-
registerCollector("replication_slot", defaultEnabled, NewPGReplicationSlotCollector)
27+
registerCollector(replicationSlotSubsystem, defaultEnabled, NewPGReplicationSlotCollector)
2628
}
2729

2830
type PGReplicationSlotCollector struct {
@@ -35,17 +37,29 @@ func NewPGReplicationSlotCollector(config collectorConfig) (Collector, error) {
3537

3638
var (
3739
pgReplicationSlotCurrentWalDesc = prometheus.NewDesc(
38-
"pg_replication_slot_current_wal_lsn",
40+
prometheus.BuildFQName(
41+
namespace,
42+
replicationSlotSubsystem,
43+
"slot_current_wal_lsn",
44+
),
3945
"current wal lsn value",
4046
[]string{"slot_name"}, nil,
4147
)
4248
pgReplicationSlotCurrentFlushDesc = prometheus.NewDesc(
43-
"pg_replication_slot_confirmed_flush_lsn",
49+
prometheus.BuildFQName(
50+
namespace,
51+
replicationSlotSubsystem,
52+
"slot_confirmed_flush_lsn",
53+
),
4454
"last lsn confirmed flushed to the replication slot",
4555
[]string{"slot_name"}, nil,
4656
)
4757
pgReplicationSlotIsActiveDesc = prometheus.NewDesc(
48-
"pg_replication_slot_is_active",
58+
prometheus.BuildFQName(
59+
namespace,
60+
replicationSlotSubsystem,
61+
"slot_is_active",
62+
),
4963
"whether the replication slot is active or not",
5064
[]string{"slot_name"}, nil,
5165
)

0 commit comments

Comments
 (0)