Documentation
¶
Index ¶
- Constants
- type AutoVacuum
- type BGWriter
- type Backend
- type Database
- type Deadlock
- type Extension
- type Index
- type Lock
- type Metadata
- type Model
- type PgBouncer
- type PgBouncerDatabase
- type PgBouncerPool
- type PgBouncerStat
- type Plan
- type Publication
- type RDS
- type ReplicationIn
- type ReplicationOut
- type ReplicationSlot
- type Role
- type Sequence
- type Setting
- type Statement
- type Subscription
- type SystemMetrics
- type Table
- type Tablespace
- type Trigger
- type UserFunction
- type VacuumProgressBackend
- type WALArchiving
Constants ¶
const ModelSchemaVersion = "1.8"
ModelSchemaVersion is the schema version of the "Model" data structure defined below. It is in the "semver" notation. Version history:
1.8 - AWS RDS/EnhancedMonitoring metrics, index defn, backend type counts, slab memory (linux), user agent 1.7 - query execution plans, autovacuum, deadlocks, table acl 1.6 - added highest WAL segment number 1.5 - add PID to replication_outgoing entries 1.4 - pgbouncer information 1.3 - locks information 1.2 - more table and index attributes 1.1 - added NotificationQueueUsage and Statements 1.0 - initial release
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AutoVacuum ¶ added in v1.8.0
type AutoVacuum struct { At int64 `json:"at"` // time when activity was logged, as seconds since epoch Table string `json:"table_name"` // fully qualified, db.schema.table Elapsed float64 `json:"elapsed"` // in seconds }
AutoVacuum contains information about a single autovacuum run. Added in schema 1.7.
type BGWriter ¶
type BGWriter struct { CheckpointsTimed int64 `json:"checkpoints_timed"` CheckpointsRequested int64 `json:"checkpoints_req"` CheckpointWriteTime float64 `json:"checkpoint_write_time"` CheckpointSyncTime float64 `json:"checkpoint_sync_time"` BuffersCheckpoint int64 `json:"buffers_checkpoint"` BuffersClean int64 `json:"buffers_clean"` MaxWrittenClean int64 `json:"maxwritten_clean"` BuffersBackend int64 `json:"buffers_backend"` BuffersBackendFsync int64 `json:"buffers_backend_fsync"` BuffersAlloc int64 `json:"buffers_alloc"` StatsReset int64 `json:"stats_reset"` }
type Backend ¶
type Backend struct { DBName string `json:"db_name"` RoleName string `json:"role_name"` ApplicationName string `json:"application_name"` PID int `json:"pid"` ClientAddr string `json:"client_addr"` BackendStart int64 `json:"backend_start"` XactStart int64 `json:"xact_start"` QueryStart int64 `json:"query_start"` StateChange int64 `json:"state_change"` WaitEventType string `json:"wait_event_type"` WaitEvent string `json:"wait_event"` State string `json:"state"` BackendXid int `json:"backend_xid"` BackendXmin int `json:"backend_xmin"` Query string `json:"query"` }
type Database ¶
type Database struct { OID int `json:"oid"` Name string `json:"name"` DatDBA int `json:"datdba"` DatTablespace int `json:"dattablespace"` DatConnLimit int `json:"datconnlimit"` AgeDatFrozenXid int `json:"age_datfrozenxid"` NumBackends int `json:"numbackends"` XactCommit int64 `json:"xact_commit"` XactRollback int64 `json:"xact_rollback"` BlksRead int64 `json:"blks_read"` BlksHit int64 `json:"blks_hit"` TupReturned int64 `json:"tup_returned"` TupFetched int64 `json:"tup_fetched"` TupInserted int64 `json:"tup_inserted"` TupUpdated int64 `json:"tup_updated"` TupDeleted int64 `json:"tup_deleted"` Conflicts int64 `json:"conflicts"` TempFiles int64 `json:"temp_files"` TempBytes int64 `json:"temp_bytes"` Deadlocks int64 `json:"deadlocks"` BlkReadTime float64 `json:"blk_read_time"` BlkWriteTime float64 `json:"blk_write_time"` StatsReset int64 `json:"stats_reset"` Size int64 `json:"size"` }
type Deadlock ¶ added in v1.8.0
type Deadlock struct { At int64 `json:"at"` // time when activity was logged, as seconds since epoch Detail string `json:"detail"` // information about the deadlocking processes }
Deadlock contains information about a single deadlock detection log. Added in schema 1.7.
type Index ¶
type Index struct { OID int `json:"oid"` DBName string `json:"db_name"` SchemaName string `json:"schema_name"` TableOID int `json:"table_oid"` TableName string `json:"table_name"` Name string `json:"name"` IdxScan int64 `json:"idx_scan"` IdxTupRead int64 `json:"idx_tup_read"` IdxTupFetch int64 `json:"idx_tup_fetch"` IdxBlksRead int64 `json:"idx_blks_read"` IdxBlksHit int64 `json:"idx_blks_hit"` Size int64 `json:"size"` Bloat int64 `json:"bloat"` // following fields present only in schema 1.2 and later RelNAtts int `json:"relnatts"` AMName string `json:"amname"` TablespaceName string `json:"tablespace_name"` // following fields present only in schema 1.8 and later Definition string `json:"def"` }
type Lock ¶ added in v1.5.1
type Lock struct { LockType string `json:"locktype"` DBName string `json:"db_name,omitempty"` PID int `json:"pid"` Mode string `json:"mode"` Granted bool `json:"granted"` RelationOID int `json:"relation_oid,omitempty"` }
Lock represents a single row from pg_locks. Added in schema 1.3.
type Metadata ¶
type Metadata struct { Version string `json:"version"` // schema version, "semver" format At int64 `json:"at"` // time when this report was started CollectedDBs []string `json:"collected_dbs"` // names of dbs we collected db-level stats from Local bool `json:"local"` // was connected to a local postgres server? UserAgent string `json:"user_agent"` // "pgmetrics/1.8.1" }
Metadata contains information about how to interpret the other fields in "Model" data structure.
type Model ¶
type Model struct { Metadata Metadata `json:"meta"` // metadata about this object StartTime int64 `json:"start_time"` // of postmaster SystemIdentifier string `json:"system_identifier"` // from pg_control // Checkpoint information CheckpointLSN string `json:"checkpoint_lsn"` PriorLSN string `json:"prior_lsn"` RedoLSN string `json:"redo_lsn"` TimelineID int `json:"timeline_id"` NextXid int `json:"next_xid"` OldestXid int `json:"oldest_xid"` OldestActiveXid int `json:"oldest_active_xid"` CheckpointTime int64 `json:"checkpoint_time"` // wal WALFlushLSN string `json:"wal_flush_lsn"` WALInsertLSN string `json:"wal_insert_lsn"` WALLSN string `json:"wal_lsn"` // Recovery IsInRecovery bool `json:"is_in_recovery"` IsWalReplayPaused bool `json:"is_wal_replay_paused"` LastWALReceiveLSN string `json:"last_wal_receive_lsn"` LastWALReplayLSN string `json:"last_wal_replay_lsn"` LastXActReplayTimestamp int64 `json:"last_xact_replay_timestamp"` // last committed transaction (needs track_commit_timestamp = on) LastXactXid int `json:"last_xact_xid"` LastXactTimestamp int64 `json:"last_xact_time"` // wal - settings, archival stats WALArchiving WALArchiving `json:"wal_archiving"` WALCount int `json:"wal_count"` WALReadyCount int `json:"wal_ready_count"` // NotificationQueueUsage is the fraction of the asynchronous notification // queue currently occupied. Postgres v9.6 and above only. Added in // schema version 1.1. NotificationQueueUsage float64 `json:"notification_queue_usage"` // replication ReplicationOutgoing []ReplicationOut `json:"replication_outgoing,omitempty"` ReplicationIncoming *ReplicationIn `json:"replication_incoming,omitempty"` ReplicationSlots []ReplicationSlot `json:"replication_slots,omitempty"` // other cluster-level stats BGWriter BGWriter `json:"bg_writer"` Backends []Backend `json:"backends"` VacuumProgress []VacuumProgressBackend `json:"vacuum_progress,omitempty"` // structural cluster-level information Roles []Role `json:"roles"` Databases []Database `json:"databases,omitempty"` Tablespaces []Tablespace `json:"tablespaces,omitempty"` // Database-specific Tables []Table `json:"tables,omitempty"` Indexes []Index `json:"indexes,omitempty"` Sequences []Sequence `json:"sequences,omitempty"` UserFunctions []UserFunction `json:"user_functions,omitempty"` Extensions []Extension `json:"extensions,omitempty"` DisabledTriggers []Trigger `json:"disabled_triggers,omitempty"` Statements []Statement `json:"statements,omitempty"` // System-level System *SystemMetrics `json:"system,omitempty"` // settings Settings map[string]Setting `json:"settings"` // all settings and their values // Logical replication (database-specific) Publications []Publication `json:"publications,omitempty"` Subscriptions []Subscription `json:"subscriptions,omitempty"` // Lock information Locks []Lock `json:"locks,omitempty"` BlockingPIDs map[int][]int `json:"blocking_pids,omitempty"` PgBouncer *PgBouncer `json:"pgbouncer,omitempty"` // the numerically highest wal segment number HighestWALSegment uint64 `json:"highwal,omitempty"` // query execution plans Plans []Plan `json:"plans,omitempty"` // autovacuum information AutoVacuums []AutoVacuum `json:"autovacuums,omitempty"` // deadlock information Deadlocks []Deadlock `json:"deadlocks,omitempty"` // metrics from AWS RDS RDS *RDS `json:"rds,omitempty"` // the types of running backends and their counts BackendTypeCounts map[string]int `json:"betypecounts,omitempty"` }
Model contains the entire information collected by a single run of pgmetrics. It can be converted to and from json without loss of precision.
func (*Model) DatabaseByOID ¶ added in v1.2.0
DatabaseByOID iterates over the databases in the model and returns the reference to a Database that has the given oid. If there is no such database, it returns nil.
func (*Model) IndexByName ¶
IndexByName iterates over the indexes in the model and returns the reference to an Index that has the given database, schema and index names. If there is no such index, it returns nil.
func (*Model) RoleByOID ¶ added in v1.2.0
RoleByOID iterates over the roles in the model and returns the reference to a Role that has the given oid. If there is no such role, it returns nil.
func (*Model) TableByName ¶
TableByName iterates over the tables in the model and returns the reference to a Table that has the given database, schema and table names. If there is no such table, it returns nil.
func (*Model) TableByOID ¶
TableByOID iterates over the tables in the model and returns the reference to a Table that has the given oid. If there is no such table, it returns nil.
type PgBouncer ¶ added in v1.6.1
type PgBouncer struct { Pools []PgBouncerPool `json:"pools,omitempty"` Stats []PgBouncerStat `json:"stats,omitempty"` Databases []PgBouncerDatabase `json:"dbs,omitempty"` SCActive int `json:"sc_active"` // no. of active server conns SCIdle int `json:"sc_idle"` // no. of idle server conns SCUsed int `json:"sc_used"` // no. of used server conns SCMaxWait float64 `json:"sc_maxwait"` // max wait time for server conns CCActive int `json:"cc_active"` // no. of active client conns CCWaiting int `json:"cc_waiting"` // no. of waiting client conns CCIdle int `json:"cc_idle"` // no. of idle client conns CCUsed int `json:"cc_used"` // no. of used client conns CCMaxWait float64 `json:"cc_maxwait"` // max wait time for *waiting* client conns CCAvgWait float64 `json:"cc_avgwait"` // avg wait time for *waiting* client conns }
PgBouncer contains information collected from the virtual "pgbouncer" database. Added in schema 1.4.
type PgBouncerDatabase ¶ added in v1.6.1
type PgBouncerDatabase struct { Database string `json:"db_name"` Host string `json:"host"` Port int `json:"port"` SourceDatabase string `json:"srcdb_name"` User string `json:"force_user"` MaxConn int `json:"max_connections"` CurrConn int `json:"current_connections"` Paused bool `json:"paused"` Disabled bool `json:"disabled"` }
PgBouncerDatabase contains information about one database of PgBouncer (one row from SHOW DATABASES).
type PgBouncerPool ¶ added in v1.6.1
type PgBouncerPool struct { Database string `json:"db_name"` UserName string `json:"user"` ClActive int `json:"cl_active"` ClWaiting int `json:"cl_waiting"` SvActive int `json:"sv_active"` SvIdle int `json:"sv_idle"` SvUsed int `json:"sv_used"` SvTested int `json:"sv_tested"` SvLogin int `json:"sv_login"` MaxWait float64 `json:"maxwait"` // seconds Mode string `json:"pool_mode"` }
PgBouncerPool contains information about one pool of PgBouncer (one row from SHOW POOLS).
type PgBouncerStat ¶ added in v1.6.1
type PgBouncerStat struct { Database string `json:"db_name"` TotalXactCount int64 `json:"total_xact_count"` TotalQueryCount int64 `json:"total_query_count"` TotalReceived int64 `json:"total_received"` // bytes TotalSent int64 `json:"total_sent"` // bytes TotalXactTime float64 `json:"total_xact_time"` // seconds TotalQueryTime float64 `json:"total_query_time"` // seconds TotalWaitTime float64 `json:"total_wait_time"` // seconds AvgXactCount int64 `json:"avg_xact_count"` AvgQueryCount int64 `json:"avg_query_count"` AvgReceived int64 `json:"avg_received"` // bytes AvgSent int64 `json:"avg_sent"` // bytes AvgXactTime float64 `json:"avg_xact_time"` // seconds AvgQueryTime float64 `json:"avg_query_time"` // seconds AvgWaitTime float64 `json:"avg_wait_time"` // seconds }
PgBouncerStat contains one row from SHOW STATS. Times are in seconds, averages are for the last second (as per PgBouncer docs).
type Plan ¶ added in v1.8.0
type Plan struct { Database string `json:"db_name"` // might be empty UserName string `json:"user"` // might be empty Format string `json:"format"` // text, json, yaml or xml At int64 `json:"at"` // time when plan was logged, as seconds since epoch Query string `json:"query"` // the sql query Plan string `json:"plan"` // the plan as a string }
Plan represents a query execution plan. Added in schema 1.7.
type Publication ¶ added in v1.4.0
type Publication struct { OID int `json:"oid"` Name string `json:"name"` DBName string `json:"db_name"` AllTables bool `json:"alltables"` Insert bool `json:"insert"` Update bool `json:"update"` Delete bool `json:"delete"` TableCount int `json:"table_count"` }
Publication represents a single v10+ publication. Added in schema 1.2.
type RDS ¶ added in v1.9.0
type RDS struct { Basic map[string]float64 `json:"basic"` // Basic Monitoring Metrics Enhanced map[string]interface{} `json:"enhanced,omitempty"` // Enhanced Monitoring }
RDS contains metrics collected from AWS RDS (also includes Aurora). Added in schema 1.8.
type ReplicationIn ¶
type ReplicationIn struct { Status string `json:"status"` ReceiveStartLSN string `json:"receive_start_lsn"` ReceiveStartTLI int `json:"receive_start_tli"` ReceivedLSN string `json:"received_lsn"` ReceivedTLI int `json:"received_tli"` LastMsgSendTime int64 `json:"last_msg_send_time"` LastMsgReceiptTime int64 `json:"last_msg_receipt_time"` Latency int64 `json:"latency_micros"` LatestEndLSN string `json:"latest_end_lsn"` LatestEndTime int64 `json:"latest_end_time"` SlotName string `json:"slot_name"` Conninfo string `json:"conninfo"` }
type ReplicationOut ¶
type ReplicationOut struct { RoleName string `json:"role_name"` ApplicationName string `json:"application_name"` ClientAddr string `json:"client_addr"` BackendStart int64 `json:"backend_start"` BackendXmin int `json:"backend_xmin"` State string `json:"state"` SentLSN string `json:"sent_lsn"` WriteLSN string `json:"write_lsn"` FlushLSN string `json:"flush_lsn"` ReplayLSN string `json:"replay_lsn"` WriteLag int `json:"write_lag"` // only in 10.x FlushLag int `json:"flush_lag"` // only in 10.x ReplayLag int `json:"replay_lag"` // only in 10.x SyncPriority int `json:"sync_priority"` SyncState string `json:"sync_state"` // following fields present only in schema 1.5 and later PID int `json:"pid,omitempty"` }
type ReplicationSlot ¶
type ReplicationSlot struct { SlotName string `json:"slot_name"` Plugin string `json:"plugin"` SlotType string `json:"slot_type"` DBName string `json:"db_name"` Active bool `json:"active"` Xmin int `json:"xmin"` CatalogXmin int `json:"catalog_xmin"` RestartLSN string `json:"restart_lsn"` ConfirmedFlushLSN string `json:"confirmed_flush_lsn"` Temporary bool `json:"temporary"` }
type Role ¶
type Role struct { OID int `json:"oid"` Name string `json:"name"` Rolsuper bool `json:"rolsuper"` Rolinherit bool `json:"rolinherit"` Rolcreaterole bool `json:"rolcreaterole"` Rolcreatedb bool `json:"rolcreatedb"` Rolcanlogin bool `json:"rolcanlogin"` Rolreplication bool `json:"rolreplication"` Rolbypassrls bool `json:"rolbypassrls"` Rolconnlimit int `json:"rolconnlimit"` Rolvaliduntil int64 `json:"rolvaliduntil"` MemberOf []string `json:"memberof"` }
type Statement ¶ added in v1.2.0
type Statement struct { UserOID int `json:"useroid"` // OID of user who executed the statement UserName string `json:"user"` // Name of the user corresponding to useroid (might be empty) DBOID int `json:"db_oid"` // OID of database in which the statement was executed DBName string `json:"db_name"` // Name of the database corresponding to db_oid QueryID int64 `json:"queryid"` // Internal hash code, computed from the statement's parse tree Query string `json:"query"` // Text of a representative statement Calls int64 `json:"calls"` // Number of times executed TotalTime float64 `json:"total_time"` // Total time spent in the statement, in milliseconds MinTime float64 `json:"min_time"` // Minimum time spent in the statement, in milliseconds MaxTime float64 `json:"max_time"` // Maximum time spent in the statement, in milliseconds StddevTime float64 `json:"stddev_time"` // Population standard deviation of time spent in the statement, in milliseconds Rows int64 `json:"rows"` // Total number of rows retrieved or affected by the statement LocalBlksHit int64 `json:"local_blks_hit"` // Total number of local block cache hits by the statement LocalBlksRead int64 `json:"local_blks_read"` // Total number of local blocks read by the statement LocalBlksDirtied int64 `json:"local_blks_dirtied"` // Total number of local blocks dirtied by the statement LocalBlksWritten int64 `json:"local_blks_written"` // Total number of local blocks written by the statement TempBlksRead int64 `json:"temp_blks_read"` // Total number of temp blocks read by the statement TempBlksWritten int64 `json:"temp_blks_written"` // Total number of temp blocks written by the statement BlkReadTime float64 `json:"blk_read_time"` // Total time the statement spent reading blocks, in milliseconds (if track_io_timing is enabled, otherwise zero) BlkWriteTime float64 `json:"blk_write_time"` // Total time the statement spent writing blocks, in milliseconds (if track_io_timing is enabled, otherwise zero) }
Statement represents a row of the pg_stat_statements view. Added in schema version 1.1.
type Subscription ¶ added in v1.4.0
type Subscription struct { OID int `json:"oid"` Name string `json:"name"` DBName string `json:"db_name"` Enabled bool `json:"enabled"` PubCount int `json:"pub_count"` TableCount int `json:"table_count"` WorkerCount int `json:"worker_count"` ReceivedLSN string `json:"received_lsn"` LatestEndLSN string `json:"latest_end_lsn"` LastMsgSendTime int64 `json:"last_msg_send_time"` LastMsgReceiptTime int64 `json:"last_msg_receipt_time"` LatestEndTime int64 `json:"latest_end_time"` Latency int64 `json:"latency_micros"` }
Subscription represents a single v10+ subscription. Added in schema 1.2.
type SystemMetrics ¶
type SystemMetrics struct { CPUModel string `json:"cpu_model,omitempty"` // model of the CPU NumCores int `json:"num_cores"` // number of cores LoadAvg float64 `json:"loadavg"` // 1-minute load average from the OS MemUsed int64 `json:"memused"` // used RAM, in bytes MemFree int64 `json:"memfree"` // free RAM, in bytes MemBuffers int64 `json:"membuffers"` // RAM used for buffers, in bytes MemCached int64 `json:"memcached"` // RAM used for cache, in bytes SwapUsed int64 `json:"swapused"` // used swap memory in bytes, 0 if no swap SwapFree int64 `json:"swapfree"` // free swap memory in bytes, 0 if no swap Hostname string `json:"hostname"` // hostname from the OS // following fields present only in schema 1.8 and later MemSlab int64 `json:"memslab"` // RAM used for slab in bytes }
type Table ¶
type Table struct { OID int `json:"oid"` DBName string `json:"db_name"` SchemaName string `json:"schema_name"` Name string `json:"name"` SeqScan int64 `json:"seq_scan"` SeqTupRead int64 `json:"seq_tup_read"` IdxScan int64 `json:"idx_scan"` IdxTupFetch int64 `json:"idx_tup_fetch"` NTupIns int64 `json:"n_tup_ins"` NTupUpd int64 `json:"n_tup_upd"` NTupDel int64 `json:"n_tup_del"` NTupHotUpd int64 `json:"n_tup_hot_upd"` NLiveTup int64 `json:"n_live_tup"` NDeadTup int64 `json:"n_dead_tup"` NModSinceAnalyze int64 `json:"n_mod_since_analyze"` LastVacuum int64 `json:"last_vacuum"` LastAutovacuum int64 `json:"last_autovacuum"` LastAnalyze int64 `json:"last_analyze"` LastAutoanalyze int64 `json:"last_autoanalyze"` VacuumCount int64 `json:"vacuum_count"` AutovacuumCount int64 `json:"autovacuum_count"` AnalyzeCount int64 `json:"analyze_count"` AutoanalyzeCount int64 `json:"autoanalyze_count"` HeapBlksRead int64 `json:"heap_blks_read"` HeapBlksHit int64 `json:"heap_blks_hit"` IdxBlksRead int64 `json:"idx_blks_read"` IdxBlksHit int64 `json:"idx_blks_hit"` ToastBlksRead int64 `json:"toast_blks_read"` ToastBlksHit int64 `json:"toast_blks_hit"` TidxBlksRead int64 `json:"tidx_blks_read"` TidxBlksHit int64 `json:"tidx_blks_hit"` Size int64 `json:"size"` Bloat int64 `json:"bloat"` // following fields present only in schema 1.2 and later RelKind string `json:"relkind"` RelPersistence string `json:"relpersistence"` RelNAtts int `json:"relnatts"` AgeRelFrozenXid int `json:"age_relfrozenxid"` RelIsPartition bool `json:"relispartition"` TablespaceName string `json:"tablespace_name"` ParentName string `json:"parent_name"` PartitionCV string `json:"partition_cv"` // partition constraint value // following fields present only in schema 1.7 and later ACL string `json:"acl,omitempty"` }
type Tablespace ¶
type Tablespace struct { OID int `json:"oid"` Name string `json:"name"` Owner string `json:"owner"` Location string `json:"location"` Size int64 `json:"size"` DiskUsed int64 `json:"disk_used"` DiskTotal int64 `json:"disk_total"` InodesUsed int64 `json:"inodes_used"` InodesTotal int64 `json:"inodes_total"` }
type UserFunction ¶
type VacuumProgressBackend ¶
type VacuumProgressBackend struct { DBName string `json:"db_name"` TableOID int `json:"table_oid"` TableName string `json:"table_name"` Phase string `json:"phase"` HeapBlksTotal int64 `json:"heap_blks_total"` HeapBlksScanned int64 `json:"heap_blks_scanned"` HeapBlksVacuumed int64 `json:"heap_blks_vacuumed"` IndexVacuumCount int64 `json:"index_vacuum_count"` MaxDeadTuples int64 `json:"max_dead_tuples"` NumDeadTuples int64 `json:"num_dead_tuples"` }
type WALArchiving ¶
type WALArchiving struct { ArchivedCount int `json:"archived_count"` LastArchivedWAL string `json:"last_archived_wal"` LastArchivedTime int64 `json:"last_archived_time"` FailedCount int `json:"failed_count"` LastFailedWAL string `json:"last_failed_wal"` LastFailedTime int64 `json:"last_failed_time"` StatsReset int64 `json:"stats_reset"` }