Skip to content

Commit

Permalink
Merge pull request #6 from credativ/pg14
Browse files Browse the repository at this point in the history
Add pg_stat_wal, pg_stat_replication_slots, and new pg_stat_database fields
  • Loading branch information
tbe authored Jun 9, 2022
2 parents 3c62cc7 + d27b514 commit 3dbe2ce
Show file tree
Hide file tree
Showing 45 changed files with 5,549 additions and 161 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI
on: [push, pull_request]

jobs:
test:

strategy:
matrix:
pg:
- 14
- 13
- 12
- 11
- 10

name: 🐘 PostgreSQL ${{ matrix.pg }}
runs-on: ubuntu-latest
container: pgxn/pgxn-tools

steps:
- name: Start PostgreSQL ${{ matrix.pg }}
run: pg-start ${{ matrix.pg }}
- name: Create root user
run: sudo -u postgres createuser --superuser root
- name: Check out the repo
uses: actions/checkout@v2
- name: Install extra build dependencies
run: sudo apt-get install -y golang
- name: Build
run: go generate && go build
- name: Test on PostgreSQL ${{ matrix.pg }}
run: if ! make installcheck; then cat regression.diffs; exit 1; fi
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.idea
bin/
pg-exporter
pid
results/
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ bin/pg-exporter:
-X github.com/prometheus/common/version.BuildUser=$(BUILD_USER) \
-X github.com/prometheus/common/version.BuildDate=$(BUILD_DATE)" \
-o bin/pg_exporter

PG_CONFIG = pg_config
PGXS = $(shell pg_config --pgxs)
REGRESS = start \
all \
stat_activity \
stat_database \
stat_wal \
stop
include $(PGXS)
24 changes: 12 additions & 12 deletions collector/models/PgStatBgWriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (

// +metric=row
type PgStatBgWriter struct {
tableName struct{} `sql:"pg_stat_bgwriter"`
CheckpointsTimed int64 `sql:"checkpoints_timed" help:"Number of scheduled checkpoints that have been performed" metric:"checkpoints_timed_total"`
CheckpointsReq int64 `sql:"checkpoints_req" help:"Number of requested checkpoints that have been performed" metric:"checkpoints_req_total"`
CheckpointWriteTime float64 `sql:"checkpoint_write_time" help:"Total amount of time that has been spent in the portion of checkpoint processing where files are written to disk, in milliseconds" metric:"checkpoint_write_seconds_total"`
CheckpointSyncTime float64 `sql:"checkpoint_sync_time" help:"Total amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk, in milliseconds" metric:"checkpoint_sync_seconds_total"`
BuffersCheckpoint int64 `sql:"buffers_checkpoint" help:"Number of buffers written during checkpoints" metric:"buffers_checkpoint_total"`
BuffersClean int64 `sql:"buffers_clean" help:"Number of buffers written by the background writer" metric:"buffers_clean_total"`
MaxwrittenClean int64 `sql:"maxwritten_clean" help:"Number of times the background writer stopped a cleaning scan because it had written too many buffers" metric:"maxwritten_clean_total"`
BuffersBackend int64 `sql:"buffers_backend" help:"Number of buffers written directly by a backend" metric:"buffers_backend_total"`
BuffersBackendFsync int64 `sql:"buffers_backend_fsync" help:"Number of times a backend had to execute its own fsync call" metric:"buffers_backend_fsync_total"`
BuffersAlloc int64 `sql:"buffers_alloc" help:"Number of buffers allocated" metric:"buffers_alloc_total"`
StatsReset time.Time `sql:"stats_reset" help:"Time at which these statistics were last reset"`
tableName struct{} `pg:"pg_stat_bgwriter"`
CheckpointsTimed int64 `pg:"checkpoints_timed" help:"Number of scheduled checkpoints that have been performed" metric:"checkpoints_timed_total"`
CheckpointsReq int64 `pg:"checkpoints_req" help:"Number of requested checkpoints that have been performed" metric:"checkpoints_req_total"`
CheckpointWriteTime float64 `pg:"checkpoint_write_time" help:"Total amount of time that has been spent in the portion of checkpoint processing where files are written to disk, in milliseconds" metric:"checkpoint_write_seconds_total"`
CheckpointSyncTime float64 `pg:"checkpoint_sync_time" help:"Total amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk, in milliseconds" metric:"checkpoint_sync_seconds_total"`
BuffersCheckpoint int64 `pg:"buffers_checkpoint" help:"Number of buffers written during checkpoints" metric:"buffers_checkpoint_total"`
BuffersClean int64 `pg:"buffers_clean" help:"Number of buffers written by the background writer" metric:"buffers_clean_total"`
MaxwrittenClean int64 `pg:"maxwritten_clean" help:"Number of times the background writer stopped a cleaning scan because it had written too many buffers" metric:"maxwritten_clean_total"`
BuffersBackend int64 `pg:"buffers_backend" help:"Number of buffers written directly by a backend" metric:"buffers_backend_total"`
BuffersBackendFsync int64 `pg:"buffers_backend_fsync" help:"Number of times a backend had to execute its own fsync call" metric:"buffers_backend_fsync_total"`
BuffersAlloc int64 `pg:"buffers_alloc" help:"Number of buffers allocated" metric:"buffers_alloc_total"`
StatsReset time.Time `pg:"stats_reset" help:"Time at which these statistics were last reset"`
}
8 changes: 4 additions & 4 deletions collector/models/pgDatabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package models

// +metric=slice
type PgDatabase struct {
tableName struct{} `sql:"pg_database"`
Datname string `sql:"datname" metric:"database,type:label"`
FrozenXID int64 `sql:"datfrozenxid" help:"All transaction IDs before this one have been replaced with a permanent transaction ID in this database" metric:"frozen_xid"`
MinMXID int64 `sql:"datminmxid" help:"All multixact IDs before this one have been replaced with a transaction ID in this database" metric:"min_mxid"`
tableName struct{} `pg:"pg_database"`
Datname string `pg:"datname" metric:"database,type:label"`
FrozenXID int64 `pg:"datfrozenxid" help:"All transaction IDs before this one have been replaced with a permanent transaction ID in this database" metric:"frozen_xid"`
MinMXID int64 `pg:"datminmxid" help:"All multixact IDs before this one have been replaced with a transaction ID in this database" metric:"min_mxid"`
}
14 changes: 7 additions & 7 deletions collector/models/pgLocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

// +metric=slice
type PgLocks struct {
tableName struct{} `sql:"pg_locks"`
Locktype sql.NullString `sql:"locktype" help:"Type of the lockable object" metric:",type:label"`
ScopeType sql.NullString `sql:"scope_type" help:"The type of the target" metric:",type:label"`
Database sql.NullString `sql:"database" help:"The Database name if applicable" metric:",type:label"`
Mode sql.NullString `sql:"mode" help:"Name of the lock mode held or desired by this process" metric:",type:label"`
Granted sql.NullBool `sql:"granted" help:"True if lock is held, false if lock is awaited" metric:",type:label"`
Locks int64 `sql:"locks" help:"Number of locks per state" metric:"count,type:gauge"`
tableName struct{} `pg:"pg_locks"`
Locktype sql.NullString `pg:"locktype" help:"Type of the lockable object" metric:",type:label"`
ScopeType sql.NullString `pg:"scope_type" help:"The type of the target" metric:",type:label"`
Database sql.NullString `pg:"database" help:"The Database name if applicable" metric:",type:label"`
Mode sql.NullString `pg:"mode" help:"Name of the lock mode held or desired by this process" metric:",type:label"`
Granted sql.NullBool `pg:"granted" help:"True if lock is held, false if lock is awaited" metric:",type:label"`
Locks int64 `pg:"locks" help:"Number of locks per state" metric:"count,type:gauge"`
}
8 changes: 4 additions & 4 deletions collector/models/pgPreparedTransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

// +metric=slice
type PgPreparedTransactions struct {
tableName struct{} `sql:"pg_prepared_xacts"`
Oldest time.Time `sql:"oldest" help:"Time at which the oldest transaction was prepared for commit" metric:",type:counter"`
Database string `sql:"database" help:"Name of the database which the transactions where executed" metric:",type:label"`
Count int64 `sql:"count" help:"Number of prepared transactions" metric:"count,type:gauge"`
tableName struct{} `pg:"pg_prepared_xacts"`
Oldest time.Time `pg:"oldest" help:"Time at which the oldest transaction was prepared for commit" metric:",type:counter"`
Database string `pg:"database" help:"Name of the database which the transactions where executed" metric:",type:label"`
Count int64 `pg:"count" help:"Number of prepared transactions" metric:"count,type:gauge"`
}
20 changes: 10 additions & 10 deletions collector/models/pgStatActivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (

// +metric=slice
type PgStatActivity struct {
tableName struct{} `sql:"pg_stat_activity"`
DatID int64 `sql:"datid" help:"OID of the database this backend is connected to" metric:"database_id,type:label"`
DatName string `sql:"datname" help:"Name of the database this backend is connected to" metric:"database,type:label"`
Usename sql.NullString `sql:"usename" help:"Name of the user logged into this backend" metric:"username,type:label"`
ApplicationName sql.NullString `sql:"application_name" help:"Name of the application that is connected to this backend" metric:",type:label"`
ClientAddr sql.NullString `sql:"client_addr" help:"IP address of the client connected to this backend" metric:",type:label"`
State sql.NullString `sql:"state" help:"Current overall state of this backend" metric:",type:label"`
WaitEventType sql.NullString `sql:"wait_event_type" help:"The type of event for which the backend is waiting, if any" metric:",type:label"`
BackendType sql.NullString `sql:"backend_type" help:"Type of current backend" metric:",type:label"`
Connections int64 `sql:"connections" help:"Number of active connections" metric:",type:gauge"`
tableName struct{} `pg:"pg_stat_activity"`
DatID int64 `pg:"datid" help:"OID of the database this backend is connected to" metric:"database_id,type:label"`
DatName string `pg:"datname" help:"Name of the database this backend is connected to" metric:"database,type:label"`
Usename sql.NullString `pg:"usename" help:"Name of the user logged into this backend" metric:"username,type:label"`
ApplicationName sql.NullString `pg:"application_name" help:"Name of the application that is connected to this backend" metric:",type:label"`
ClientAddr sql.NullString `pg:"client_addr" help:"IP address of the client connected to this backend" metric:",type:label"`
State sql.NullString `pg:"state" help:"Current overall state of this backend" metric:",type:label"`
WaitEventType sql.NullString `pg:"wait_event_type" help:"The type of event for which the backend is waiting, if any" metric:",type:label"`
BackendType sql.NullString `pg:"backend_type" help:"Type of current backend" metric:",type:label"`
Connections int64 `pg:"connections" help:"Number of active connections" metric:",type:gauge"`
}
12 changes: 6 additions & 6 deletions collector/models/pgStatArchiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

// +metric=row
type PgStatArchiver struct {
tableName struct{} `sql:"pg_stat_archiver"`
ArchivedCount int64 `sql:"archived_count" help:"Number of WAL files that have been successfully archived" metric:"archived_count_total"`
LastArchivedTime time.Time `sql:"last_archived_time" help:"Time of the last successful archive operation"`
FailedCount int64 `sql:"failed_count" help:"Number of failed attempts for archiving WAL files" metric:"failed_count_total"`
LastFailedTime time.Time `sql:"last_failed_time" help:"Time of the last failed archival operation"`
StatsReset time.Time `sql:"stats_reset" help:"Time at which these statistics were last reset"`
tableName struct{} `pg:"pg_stat_archiver"`
ArchivedCount int64 `pg:"archived_count" help:"Number of WAL files that have been successfully archived" metric:"archived_count_total"`
LastArchivedTime time.Time `pg:"last_archived_time" help:"Time of the last successful archive operation"`
FailedCount int64 `pg:"failed_count" help:"Number of failed attempts for archiving WAL files" metric:"failed_count_total"`
LastFailedTime time.Time `pg:"last_failed_time" help:"Time of the last failed archival operation"`
StatsReset time.Time `pg:"stats_reset" help:"Time at which these statistics were last reset"`
}
49 changes: 29 additions & 20 deletions collector/models/pgStatDatabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,33 @@ import (

// +metric=slice
type PgStatDatabase struct {
tableName struct{} `sql:"pg_stat_database"`
DatID int64 `sql:"datid" help:"OID of a database" metric:"database_id,type:label"`
DatName string `sql:"datname" help:"Name of this database" metric:"database,type:label"`
NumBackends int `sql:"numbackends" help:"Number of backends currently connected to this database" metric:"backends,type:gauge"`
XactCommit int64 `sql:"xact_commit" help:"Number of transactions in this database that have been committed" metric:"xact_commited_total"`
XactRollback int64 `sql:"xact_rollback" help:"Number of transactions in this database that have been rolled back" metric:"xact_rolledback_total"`
BlksRead int64 `sql:"blks_read" help:"Number of disk blocks read in this database" metric:"blocks_read_total"`
BlksHit int64 `sql:"blks_hit" help:"Number of times disk blocks were found already in the buffer cache, so that a read was not necessary" metric:"blocks_hit_total"`
TupReturned int64 `sql:"tup_returned" help:"Number of rows returned by queries in this database" metric:"rows_returned_total"`
TupFetched int64 `sql:"tup_fetched" help:"Number of rows fetched by queries in this database" metric:"rows_fetched_total"`
TupInserted int64 `sql:"tup_inserted" help:"Number of rows inserted by queries in this database" metric:"rows_inserted_total"`
TupUpdated int64 `sql:"tup_updated" help:"Number of rows updated by queries in this database" metric:"rows_updated_total"`
TupDeleted int64 `sql:"tup_deleted" help:"Number of rows deleted by queries in this database" metric:"rows_deleted_total"`
Conflicts int64 `sql:"conflicts" help:"Number of queries canceled due to conflicts with recovery in this database" metric:"conflicts_total"`
TempFiles int64 `sql:"temp_files" help:"Number of temporary files created by queries in this database" metric:"temp_files_total"`
TempBytes int64 `sql:"temp_bytes" help:"Total amount of data written to temporary files by queries in this database" metric:"temp_bytes_total"`
Deadlocks int64 `sql:"deadlocks" help:"Number of deadlocks detected in this database" metric:"deadlocks_total"`
BlkReadTime Milliseconds `sql:"blk_read_time" help:"Time spent reading data file blocks by backends in this database" metric:"blk_read_seconds_total"`
BlkWriteTime Milliseconds `sql:"blk_write_time" help:"Time spent writing data file blocks by backends in this database" metric:"blk_write_seconds_total"`
StatsReset time.Time `sql:"stats_reset" help:"Time at which these statistics were last reset"`
tableName struct{} `pg:"pg_stat_database"`
DatID int64 `pg:"datid" help:"OID of a database" metric:"database_id,type:label"`
DatName string `pg:"datname" help:"Name of this database" metric:"database,type:label"`
NumBackends int `pg:"numbackends" help:"Number of backends currently connected to this database" metric:"backends,type:gauge"`
XactCommit int64 `pg:"xact_commit" help:"Number of transactions in this database that have been committed" metric:"xact_commited_total"`
XactRollback int64 `pg:"xact_rollback" help:"Number of transactions in this database that have been rolled back" metric:"xact_rolledback_total"`
BlksRead int64 `pg:"blks_read" help:"Number of disk blocks read in this database" metric:"blocks_read_total"`
BlksHit int64 `pg:"blks_hit" help:"Number of times disk blocks were found already in the buffer cache, so that a read was not necessary" metric:"blocks_hit_total"`
TupReturned int64 `pg:"tup_returned" help:"Number of rows returned by queries in this database" metric:"rows_returned_total"`
TupFetched int64 `pg:"tup_fetched" help:"Number of rows fetched by queries in this database" metric:"rows_fetched_total"`
TupInserted int64 `pg:"tup_inserted" help:"Number of rows inserted by queries in this database" metric:"rows_inserted_total"`
TupUpdated int64 `pg:"tup_updated" help:"Number of rows updated by queries in this database" metric:"rows_updated_total"`
TupDeleted int64 `pg:"tup_deleted" help:"Number of rows deleted by queries in this database" metric:"rows_deleted_total"`
Conflicts int64 `pg:"conflicts" help:"Number of queries canceled due to conflicts with recovery in this database" metric:"conflicts_total"`
TempFiles int64 `pg:"temp_files" help:"Number of temporary files created by queries in this database" metric:"temp_files_total"`
TempBytes int64 `pg:"temp_bytes" help:"Total amount of data written to temporary files by queries in this database" metric:"temp_bytes_total"`
Deadlocks int64 `pg:"deadlocks" help:"Number of deadlocks detected in this database" metric:"deadlocks_total"`
ChecksumFailures int64 `pg:"checksum_failures" help:"Number of data page checksum failures detected in this database" metric:"checksum_failures_count"` // new in PG12
ChecksumLastFailure time.Time `pg:"checksum_last_failure" help:"Time at which the last data page checksum failure was detected in this database" metric:"checksum_last_failure"` // new in PG12
BlkReadTime Milliseconds `pg:"blk_read_time" help:"Time spent reading data file blocks by backends in this database" metric:"blk_read_seconds_total"`
BlkWriteTime Milliseconds `pg:"blk_write_time" help:"Time spent writing data file blocks by backends in this database" metric:"blk_write_seconds_total"`
SessionTime Milliseconds `pg:"session_time" help:"Time spent by database sessions in this database, in milliseconds" metric:"session_time_total"` // new in PG14
ActiveTime Milliseconds `pg:"active_time" help:"Time spent executing SQL statements in this database, in milliseconds" metric:"active_time_total"` // new in PG14
IdleInTransactionTime Milliseconds `pg:"idle_in_transaction_time" help:"Time spent idling while in a transaction in this database, in milliseconds" metric:"idle_in_transaction_time_total"` // new in PG14
Sessions int64 `pg:"sessions" help:"Total number of sessions established to this database" metric:"sessions_count"` // new in PG14
SessionsAbandoned int64 `pg:"sessions_abandoned" help:"Number of database sessions to this database that were terminated because connection to the client was lost" metric:"sessions_abandoned_count"` // new in PG14
SessionsFatal int64 `pg:"sessions_fatal" help:"Number of database sessions to this database that were terminated by fatal errors" metric:"sessions_fatal_count"` // new in PG14
SessionsKilled int64 `pg:"sessions_killed" help:"Number of database sessions to this database that were terminated by operator intervention" metric:"sessions_killed_count"` // new in PG14
StatsReset time.Time `pg:"stats_reset" help:"Time at which these statistics were last reset"`
}
Loading

0 comments on commit 3dbe2ce

Please sign in to comment.