You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-08-06 17:22:43 +03:00
Fix up collector registration (#812)
Use const definitions to make collector registration consistent. * Use collector subsystem name consistently. * Fix up replication metric name unit. Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
@@ -21,8 +21,10 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const databaseSubsystem = "database"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("database", defaultEnabled, NewPGDatabaseCollector)
|
registerCollector(databaseSubsystem, defaultEnabled, NewPGDatabaseCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PGDatabaseCollector struct {
|
type PGDatabaseCollector struct {
|
||||||
@@ -43,7 +45,11 @@ func NewPGDatabaseCollector(config collectorConfig) (Collector, error) {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
pgDatabaseSizeDesc = prometheus.NewDesc(
|
pgDatabaseSizeDesc = prometheus.NewDesc(
|
||||||
"pg_database_size_bytes",
|
prometheus.BuildFQName(
|
||||||
|
namespace,
|
||||||
|
databaseSubsystem,
|
||||||
|
"size_bytes",
|
||||||
|
),
|
||||||
"Disk space used by the database",
|
"Disk space used by the database",
|
||||||
[]string{"datname"}, nil,
|
[]string{"datname"}, nil,
|
||||||
)
|
)
|
||||||
|
@@ -20,8 +20,10 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const postmasterSubsystem = "postmaster"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("postmaster", defaultEnabled, NewPGPostmasterCollector)
|
registerCollector(postmasterSubsystem, defaultEnabled, NewPGPostmasterCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PGPostmasterCollector struct {
|
type PGPostmasterCollector struct {
|
||||||
@@ -33,7 +35,11 @@ func NewPGPostmasterCollector(collectorConfig) (Collector, error) {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
pgPostMasterStartTimeSeconds = prometheus.NewDesc(
|
pgPostMasterStartTimeSeconds = prometheus.NewDesc(
|
||||||
"pg_postmaster_start_time_seconds",
|
prometheus.BuildFQName(
|
||||||
|
namespace,
|
||||||
|
postmasterSubsystem,
|
||||||
|
"start_time_seconds",
|
||||||
|
),
|
||||||
"Time at which postmaster started",
|
"Time at which postmaster started",
|
||||||
[]string{}, nil,
|
[]string{}, nil,
|
||||||
)
|
)
|
||||||
|
@@ -21,16 +21,16 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const processIdleSubsystem = "process_idle"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("statements", defaultEnabled, NewPGProcessIdleCollector)
|
registerCollector(processIdleSubsystem, defaultEnabled, NewPGProcessIdleCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PGProcessIdleCollector struct {
|
type PGProcessIdleCollector struct {
|
||||||
log log.Logger
|
log log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
const processIdleSubsystem = "process_idle"
|
|
||||||
|
|
||||||
func NewPGProcessIdleCollector(config collectorConfig) (Collector, error) {
|
func NewPGProcessIdleCollector(config collectorConfig) (Collector, error) {
|
||||||
return &PGProcessIdleCollector{log: config.logger}, nil
|
return &PGProcessIdleCollector{log: config.logger}, nil
|
||||||
}
|
}
|
||||||
|
@@ -20,8 +20,10 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const replicationSubsystem = "replication"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("replication", defaultEnabled, NewPGReplicationCollector)
|
registerCollector(replicationSubsystem, defaultEnabled, NewPGReplicationCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PGReplicationCollector struct {
|
type PGReplicationCollector struct {
|
||||||
@@ -33,12 +35,20 @@ func NewPGReplicationCollector(collectorConfig) (Collector, error) {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
pgReplicationLag = prometheus.NewDesc(
|
pgReplicationLag = prometheus.NewDesc(
|
||||||
"pg_replication_lag",
|
prometheus.BuildFQName(
|
||||||
|
namespace,
|
||||||
|
replicationSubsystem,
|
||||||
|
"lag_seconds",
|
||||||
|
),
|
||||||
"Replication lag behind master in seconds",
|
"Replication lag behind master in seconds",
|
||||||
[]string{}, nil,
|
[]string{}, nil,
|
||||||
)
|
)
|
||||||
pgReplicationIsReplica = prometheus.NewDesc(
|
pgReplicationIsReplica = prometheus.NewDesc(
|
||||||
"pg_replication_is_replica",
|
prometheus.BuildFQName(
|
||||||
|
namespace,
|
||||||
|
replicationSubsystem,
|
||||||
|
"is_replica",
|
||||||
|
),
|
||||||
"Indicates if the server is a replica",
|
"Indicates if the server is a replica",
|
||||||
[]string{}, nil,
|
[]string{}, nil,
|
||||||
)
|
)
|
||||||
|
@@ -21,8 +21,10 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const replicationSlotSubsystem = "replication_slot"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("replication_slot", defaultEnabled, NewPGReplicationSlotCollector)
|
registerCollector(replicationSlotSubsystem, defaultEnabled, NewPGReplicationSlotCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PGReplicationSlotCollector struct {
|
type PGReplicationSlotCollector struct {
|
||||||
@@ -35,17 +37,29 @@ func NewPGReplicationSlotCollector(config collectorConfig) (Collector, error) {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
pgReplicationSlotCurrentWalDesc = prometheus.NewDesc(
|
pgReplicationSlotCurrentWalDesc = prometheus.NewDesc(
|
||||||
"pg_replication_slot_current_wal_lsn",
|
prometheus.BuildFQName(
|
||||||
|
namespace,
|
||||||
|
replicationSlotSubsystem,
|
||||||
|
"slot_current_wal_lsn",
|
||||||
|
),
|
||||||
"current wal lsn value",
|
"current wal lsn value",
|
||||||
[]string{"slot_name"}, nil,
|
[]string{"slot_name"}, nil,
|
||||||
)
|
)
|
||||||
pgReplicationSlotCurrentFlushDesc = prometheus.NewDesc(
|
pgReplicationSlotCurrentFlushDesc = prometheus.NewDesc(
|
||||||
"pg_replication_slot_confirmed_flush_lsn",
|
prometheus.BuildFQName(
|
||||||
|
namespace,
|
||||||
|
replicationSlotSubsystem,
|
||||||
|
"slot_confirmed_flush_lsn",
|
||||||
|
),
|
||||||
"last lsn confirmed flushed to the replication slot",
|
"last lsn confirmed flushed to the replication slot",
|
||||||
[]string{"slot_name"}, nil,
|
[]string{"slot_name"}, nil,
|
||||||
)
|
)
|
||||||
pgReplicationSlotIsActiveDesc = prometheus.NewDesc(
|
pgReplicationSlotIsActiveDesc = prometheus.NewDesc(
|
||||||
"pg_replication_slot_is_active",
|
prometheus.BuildFQName(
|
||||||
|
namespace,
|
||||||
|
replicationSlotSubsystem,
|
||||||
|
"slot_is_active",
|
||||||
|
),
|
||||||
"whether the replication slot is active or not",
|
"whether the replication slot is active or not",
|
||||||
[]string{"slot_name"}, nil,
|
[]string{"slot_name"}, nil,
|
||||||
)
|
)
|
@@ -21,8 +21,10 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const bgWriterSubsystem = "stat_bgwriter"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("bgwriter", defaultEnabled, NewPGStatBGWriterCollector)
|
registerCollector(bgWriterSubsystem, defaultEnabled, NewPGStatBGWriterCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PGStatBGWriterCollector struct {
|
type PGStatBGWriterCollector struct {
|
||||||
@@ -32,8 +34,6 @@ func NewPGStatBGWriterCollector(collectorConfig) (Collector, error) {
|
|||||||
return &PGStatBGWriterCollector{}, nil
|
return &PGStatBGWriterCollector{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const bgWriterSubsystem = "stat_bgwriter"
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
statBGWriterCheckpointsTimedDesc = prometheus.NewDesc(
|
statBGWriterCheckpointsTimedDesc = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, bgWriterSubsystem, "checkpoints_timed_total"),
|
prometheus.BuildFQName(namespace, bgWriterSubsystem, "checkpoints_timed_total"),
|
||||||
|
@@ -20,8 +20,10 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const statDatabaseSubsystem = "stat_database"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("stat_database", defaultEnabled, NewPGStatDatabaseCollector)
|
registerCollector(statDatabaseSubsystem, defaultEnabled, NewPGStatDatabaseCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PGStatDatabaseCollector struct{}
|
type PGStatDatabaseCollector struct{}
|
||||||
@@ -30,8 +32,6 @@ func NewPGStatDatabaseCollector(config collectorConfig) (Collector, error) {
|
|||||||
return &PGStatDatabaseCollector{}, nil
|
return &PGStatDatabaseCollector{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const statDatabaseSubsystem = "stat_database"
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
statDatabaseNumbackends = prometheus.NewDesc(
|
statDatabaseNumbackends = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(
|
prometheus.BuildFQName(
|
||||||
|
@@ -21,19 +21,19 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const statStatementsSubsystem = "stat_statements"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// WARNING:
|
// WARNING:
|
||||||
// Disabled by default because this set of metrics can be quite expensive on a busy server
|
// Disabled by default because this set of metrics can be quite expensive on a busy server
|
||||||
// Every unique query will cause a new timeseries to be created
|
// Every unique query will cause a new timeseries to be created
|
||||||
registerCollector("statements", defaultDisabled, NewPGStatStatementsCollector)
|
registerCollector(statStatementsSubsystem, defaultDisabled, NewPGStatStatementsCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PGStatStatementsCollector struct {
|
type PGStatStatementsCollector struct {
|
||||||
log log.Logger
|
log log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
const statStatementsSubsystem = "stat_statements"
|
|
||||||
|
|
||||||
func NewPGStatStatementsCollector(config collectorConfig) (Collector, error) {
|
func NewPGStatStatementsCollector(config collectorConfig) (Collector, error) {
|
||||||
return &PGStatStatementsCollector{log: config.logger}, nil
|
return &PGStatStatementsCollector{log: config.logger}, nil
|
||||||
}
|
}
|
||||||
|
@@ -22,16 +22,16 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const userTableSubsystem = "stat_user_tables"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("user_tables", defaultEnabled, NewPGStatUserTablesCollector)
|
registerCollector(userTableSubsystem, defaultEnabled, NewPGStatUserTablesCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PGStatUserTablesCollector struct {
|
type PGStatUserTablesCollector struct {
|
||||||
log log.Logger
|
log log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
const userTableSubsystem = "stat_user_tables"
|
|
||||||
|
|
||||||
func NewPGStatUserTablesCollector(config collectorConfig) (Collector, error) {
|
func NewPGStatUserTablesCollector(config collectorConfig) (Collector, error) {
|
||||||
return &PGStatUserTablesCollector{log: config.logger}, nil
|
return &PGStatUserTablesCollector{log: config.logger}, nil
|
||||||
}
|
}
|
||||||
|
@@ -21,16 +21,16 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const statioUserTableSubsystem = "statio_user_tables"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerCollector("statio_user_tables", defaultEnabled, NewPGStatIOUserTablesCollector)
|
registerCollector(statioUserTableSubsystem, defaultEnabled, NewPGStatIOUserTablesCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PGStatIOUserTablesCollector struct {
|
type PGStatIOUserTablesCollector struct {
|
||||||
log log.Logger
|
log log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
const statioUserTableSubsystem = "statio_user_tables"
|
|
||||||
|
|
||||||
func NewPGStatIOUserTablesCollector(config collectorConfig) (Collector, error) {
|
func NewPGStatIOUserTablesCollector(config collectorConfig) (Collector, error) {
|
||||||
return &PGStatIOUserTablesCollector{log: config.logger}, nil
|
return &PGStatIOUserTablesCollector{log: config.logger}, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user