Metrics details

A variety of metrics are collected by the BigAnimal instance and made available to the customer's Azure subscription for dashboarding, alerting, querying and other analytics.

See Monitoring and logging for an introduction to the available monitoring capabilities.

This section explains how to find and interpret the available metrics and logs. It also lists and describes the individual metrics provided.

Understanding BigAnimal logs and metrics

You can see example queries over these metrics by editing the predefined dashboard panels in the default shared dashboard. Some pre-defined queries and/or functions may also be available in the Log Analytics queries panel. The Azure Monitor Metrics Explorer provides a useful entry point for discovering the available metrics.

In-depth advice on the details of querying these metrics is beyond the scope of this documentation. Refer to The Azure Log Analytics and Azure Monitor documentation and to the documentation on the Kusto query language used by Azure Monitor. A wide variety of analytics capabilities are available including time-series functions, seasonally adjusted statistics, alert generation and more.

Available logs and metrics

The following tables in the Customer Log Analytic workspace contain entries specific to BigAnimal:

Table nameDescription
PostgresLogs_CLLogs of the Customer clusters databases (all postgres related logs)
PostgresAuditLogs_CLAudit Logs of the Customer clusters databases, if enabled
InsightsMetricsMetrics streams from BigAnimal Prometheus and Azure Monitor. BigAnimal metrics have namespace == "prometheus"

You can use the KQL Query editor in the Log Workspace view to compose queries over these tables.

Logs

Postgres logs are added to the PostgresLogs_CL table.

Logs are split into structured fields matching those of the Postgres csvlog format with a record_ prefix and a type-suffix. For example the application_name is in the record_application_name_s log field.

The pg_cluster_id_s field identifies the specific Postgres cluster that originated the log message.

Metrics overview

BigAnimal collects a wide set of metrics about Postgres instances into the InsightsMetrics log analytics table. Most of these metrics are acquired directly from Postgres system tables, views, and functions. The Postgres documentation serves as the main reference for these metrics.

KQL can be used to analyze time-series metrics, report latest samples of metrics, etc by querying the InsightsMetrics table.

Some data from Postgres monitoring system views, tables and functions are transformed to be easier to consume in Prometheus metrics format. For example, timestamp fields are generally converted to unix epoch time and/or accompanied by a relative time-interval metric. Other metrics are aggregated into categories by label dimensions to limit the number of very specific and narrowly scoped individual metrics emitted. It would be not be very useful to report the inactivity period of every single backend, for example, so backend statistics are aggregated by database, user, application_name and backend state.

Prometheus Labels are mapped to Azure metrics Dimensions. Dimensions vary depending on the individual metric, and are documented separately for each group of related metrics.

The forwarded Prometheus metrics use structured json fields, particularly for the Tags field. Effective use of them will require use of the todynamic() function in queries.

The available set of metrics is subject to change. Metrics may be added, removed or renamed. Where feasible an effort will be made not to change the meaning or type of existing metrics without also changing the metric name.

At time of writing all metrics forwarded from Prometheus are in the prometheus namespace. This may change in a future release.

Effective use of the available metrics requires an understanding of Azure time-series data, metrics dimensions, and of the tagging conventions used in the metrics streams.

Metrics tags

All Postgres metrics share a common tagging scheme. Entries will generally have at least the following tags:

NameDescription
addressIP address of the host the metric originated from
postgresqlBigAnimal postgres cluster identifier e.g. p-abcdef012345
rolePostgres instance role, "primary" or "replica"
datnamePostgres database name (where applicable)
pod_namek8s pod name
hostNameAKS node host name
container.azm.ms/clusterNameAKS cluster name

When querying for tags best performance is achieved when any filters that do not require inspection of tags (e.g. filters by metric name) are applied before any tag-based filters.

The Tags field of a metrics entry is a json-typed field that may be queried for individual values with todynamic(Tags).keyname in KQL. Some uses of values may require explicit casts to another type e.g. tostring(...).

Example usage:

InsightsMetrics
| where Namespace == "prometheus" and Name startswith "cnp_"
| extend t = todynamic(Tags)
| where t.role == "primary"
| project postgres_cluster_id = tostring(t.postgresql), dbname = tostring(t.datname)
| where not (dbname has_any("template0", "template1"))
| distinct postgres_cluster_id, dbname

Group cnp_backends

Backend counts from pg_stat_activity aggregated by the listed label dimensions. Useful for identifying busy applications, excessive idle backends, etc.

Derived from the pg_stat_activity view.

Metrics
MetricUsageDescription
cnp_backends_totalGAUGENumber of backends
cnp_backends_max_tx_duration_secondsGAUGEMaximum duration of a transaction in seconds
Labels

The above metrics may have these labels, represented as dimensions in Azure Monitor:

LabelDescription
datnameName of the database
usenameName of the user
application_nameName of the application
stateState of the backend

Group cnp_backends_waiting

Postgres-instance-level aggregate information on backends that are blocked waiting for locks. Does not count I/O waits or other reasons backends might wait or be blocked.

Derived from the pg_locks view.

Metrics
MetricUsageDescription
cnp_backends_waiting_totalGAUGETotal number of backends that are currently waiting on other queries

Group cnp_pg_database

Per-database metrics for each database in the postgres instance. Includes per-database vacuum progress information.

Derived from the pg_database catalog.

See also cnp_pg_stat_database.

Metrics
MetricUsageDescription
cnp_pg_database_size_bytesGAUGEDisk space used by the database
cnp_pg_database_xid_ageGAUGENumber of transactions from the frozen XID to the current one
cnp_pg_database_mxid_ageGAUGENumber of multiple transactions (Multixact) from the frozen XID to the current one
Labels

The above metrics may have these labels, represented as dimensions in Azure Monitor:

LabelDescription
datnameName of the database

Group cnp_pg_postmaster

Data on the postgres instance's managing "postmaster" process.

Derived from the pg_postmaster_start_time() function.

Metrics
MetricUsageDescription
cnp_pg_postmaster_start_timeGAUGETime at which postgres started (based on epoch)

Group cnp_pg_replication

Physical replication details for a standby postgres instance as captured from the standby itself.

Derived from the pg_last_xact_replay_timestamp() function.

Only relevant on standby servers.

See also cnp_pg_stat_replication, cnp_pg_replication_slots.

Metrics
MetricUsageDescription
cnp_pg_replication_lagGAUGEReplication lag behind primary in seconds
cnp_pg_replication_in_recoveryGAUGEWhether the instance is in recovery

Group cnp_pg_replication_slots

Details about replication slots on a postgres instance. In most configurations only the primary server will have active replication clients, but other nodes may still have replication slots.

Note that logical replication slots are specific to a database, whereas physical replication slots will have an empty "database" label as they apply to the postgres instance as a whole.

Derived from the pg_replication_slots view.

See also cnp_pg_stat_replication, cnp_pg_replication.

Metrics
MetricUsageDescription
cnp_pg_replication_slots_activeGAUGEFlag indicating if the slot is active
cnp_pg_replication_slots_pg_wal_lsn_diffGAUGEReplication lag in bytes
Labels

The above metrics may have these labels, represented as dimensions in Azure Monitor:

LabelDescription
slot_nameName of the replication slot
databaseName of the database

Group cnp_pg_stat_archiver

Progress information about WAL archiving. Only the currently active primary server will generally be performing WAL archiving.

WAL archiving is important for backup and restore. If WAL archiving is delayed or failing for too long, the point-in-time recovery backups for a postgres cluster will not be up to date. This has disaster recovery implications and can potentially also affect failover.

Occasional WAL archiving failures are normal, but a growing delay in the time since the last successful WAL archiving operation should be taken seriously.

Metrics in this section are reset when a postgres stats reset is issued on the db server.

Derived from the pg_stat_archiver view.

Metrics
MetricUsageDescription
cnp_pg_stat_archiver_archived_countCOUNTERNumber of WAL files that have been successfully archived
cnp_pg_stat_archiver_failed_countCOUNTERNumber of failed attempts for archiving WAL files
cnp_pg_stat_archiver_seconds_since_last_archivalGAUGESeconds since the last successful archival operation
cnp_pg_stat_archiver_seconds_since_last_failureGAUGESeconds since the last failed archival operation
cnp_pg_stat_archiver_last_archived_timeGAUGEEpoch of the last time WAL archiving succeeded
cnp_pg_stat_archiver_last_failed_timeGAUGEEpoch of the last time WAL archiving failed
cnp_pg_stat_archiver_last_archived_wal_start_lsnGAUGEArchived WAL start LSN
cnp_pg_stat_archiver_last_failed_wal_start_lsnGAUGELast failed WAL LSN
cnp_pg_stat_archiver_stats_reset_timeGAUGETime at which these statistics were last reset

Group cnp_pg_stat_bgwriter

Stats for the postgres background writer and checkpointer processes, which are instance-wide and shared across all databases in a postgres instance.

Very long delays between checkpoints on a busy system will increase the time taken for it to return to read/write availability if crash recovery is required. Excessively frequent checkpoints can increase I/O load and the size of the WAL stream for backup and replication.

The postgres documentation discusses checkpoints, dirty writeback, and checkpoint tuning in detail.

Metrics in this section are reset when a postgres stats reset is issued on the db server.

Derived from the pg_stat_bgwriter catalog.

Metrics
MetricUsageDescription
cnp_pg_stat_bgwriter_checkpoints_timedCOUNTERNumber of scheduled checkpoints that have been performed
cnp_pg_stat_bgwriter_checkpoints_reqCOUNTERNumber of requested checkpoints that have been performed
cnp_pg_stat_bgwriter_checkpoint_write_timeCOUNTERTotal amount of time that has been spent in the portion of checkpoint processing where files are written to disk, in milliseconds
cnp_pg_stat_bgwriter_checkpoint_sync_timeCOUNTERTotal amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk, in milliseconds
cnp_pg_stat_bgwriter_buffers_checkpointCOUNTERNumber of buffers written during checkpoints
cnp_pg_stat_bgwriter_buffers_cleanCOUNTERNumber of buffers written by the background writer
cnp_pg_stat_bgwriter_maxwritten_cleanCOUNTERNumber of times the background writer stopped a cleaning scan because it had written too many buffers
cnp_pg_stat_bgwriter_buffers_backendCOUNTERNumber of buffers written directly by a backend
cnp_pg_stat_bgwriter_buffers_backend_fsyncCOUNTERNumber of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write)
cnp_pg_stat_bgwriter_buffers_allocCOUNTERNumber of buffers allocated

Group cnp_pg_stat_database

This metrics group directly exposes the summary data postgres collects in its own pg_stat_database view. It contains statistical counters maintained by postgres itself for database activity.

Metrics in this section are reset when a postgres stats reset is issued on the db server.

Derived from the pg_stat_database catalog.

See also cnp_pg_database.

Metrics
MetricUsageDescription
cnp_pg_stat_database_xact_commitCOUNTERNumber of transactions in this database that have been committed
cnp_pg_stat_database_xact_rollbackCOUNTERNumber of transactions in this database that have been rolled back
cnp_pg_stat_database_blks_readCOUNTERNumber of disk blocks read in this database
cnp_pg_stat_database_blks_hitCOUNTERNumber of times disk blocks were found already in the buffer cache, so that a read was not necessary (this only includes hits in the PostgreSQL buffer cache, not the operating system's file system cache)
cnp_pg_stat_database_tup_returnedCOUNTERNumber of rows returned by queries in this database
cnp_pg_stat_database_tup_fetchedCOUNTERNumber of rows fetched by queries in this database
cnp_pg_stat_database_tup_insertedCOUNTERNumber of rows inserted by queries in this database
cnp_pg_stat_database_tup_updatedCOUNTERNumber of rows updated by queries in this database
cnp_pg_stat_database_tup_deletedCOUNTERNumber of rows deleted by queries in this database
cnp_pg_stat_database_conflictsCOUNTERNumber of queries canceled due to conflicts with recovery in this database
cnp_pg_stat_database_temp_filesCOUNTERNumber of temporary files created by queries in this database
cnp_pg_stat_database_temp_bytesCOUNTERTotal amount of data written to temporary files by queries in this database
cnp_pg_stat_database_deadlocksCOUNTERNumber of deadlocks detected in this database
cnp_pg_stat_database_blk_read_timeCOUNTERTime spent reading data file blocks by backends in this database, in milliseconds
cnp_pg_stat_database_blk_write_timeCOUNTERTime spent writing data file blocks by backends in this database, in milliseconds
Labels

The above metrics may have these labels, represented as dimensions in Azure Monitor:

LabelDescription
datnameName of this database

Group cnp_pg_stat_database_conflicts

These metrics provide information on conflicts between queries on a standby and the standby's replay of the change-stream from the primary. These are called recovery conflicts.

These metrics are unrelated to "INSERT ... ON CONFLICT" conflicts, or multi-master replication row conflicts. They are only relevant on standby servers.

Metrics in this section are reset when a postgres stats reset is issued on the db server.

Only defined on standby servers.

Derived from the pg_stat_database_conflicts view.

Metrics
MetricUsageDescription
cnp_pg_stat_database_conflicts_confl_tablespaceCOUNTERNumber of queries in this database that have been canceled due to dropped tablespaces
cnp_pg_stat_database_conflicts_confl_lockCOUNTERNumber of queries in this database that have been canceled due to lock timeouts
cnp_pg_stat_database_conflicts_confl_snapshotCOUNTERNumber of queries in this database that have been canceled due to old snapshots
cnp_pg_stat_database_conflicts_confl_bufferpinCOUNTERNumber of queries in this database that have been canceled due to pinned buffers
cnp_pg_stat_database_conflicts_confl_deadlockCOUNTERNumber of queries in this database that have been canceled due to deadlocks
Labels

The above metrics may have these labels, represented as dimensions in Azure Monitor:

LabelDescription
datnameName of the database

Group cnp_pg_stat_user_tables

Access and usage statistics maintained by postgres on non-system tables.

Metrics in this section are reset when a postgres stats reset is issued on the db server.

Derived from the pg_stat_user_tables view.

See also cnp_pg_statio_user_tables.

Metrics
MetricUsageDescription
cnp_pg_stat_user_tables_seq_scanCOUNTERNumber of sequential scans initiated on this table
cnp_pg_stat_user_tables_seq_tup_readCOUNTERNumber of live rows fetched by sequential scans
cnp_pg_stat_user_tables_idx_scanCOUNTERNumber of index scans initiated on this table
cnp_pg_stat_user_tables_idx_tup_fetchCOUNTERNumber of live rows fetched by index scans
cnp_pg_stat_user_tables_n_tup_insCOUNTERNumber of rows inserted
cnp_pg_stat_user_tables_n_tup_updCOUNTERNumber of rows updated
cnp_pg_stat_user_tables_n_tup_delCOUNTERNumber of rows deleted
cnp_pg_stat_user_tables_n_tup_hot_updCOUNTERNumber of rows HOT updated (i.e., with no separate index update required)
cnp_pg_stat_user_tables_n_live_tupGAUGEEstimated number of live rows
cnp_pg_stat_user_tables_n_dead_tupGAUGEEstimated number of dead rows
cnp_pg_stat_user_tables_n_mod_since_analyzeGAUGEEstimated number of rows changed since last analyze
cnp_pg_stat_user_tables_last_vacuumGAUGELast time at which this table was manually vacuumed (not counting VACUUM FULL)
cnp_pg_stat_user_tables_last_autovacuumGAUGELast time at which this table was vacuumed by the autovacuum daemon
cnp_pg_stat_user_tables_last_analyzeGAUGELast time at which this table was manually analyzed
cnp_pg_stat_user_tables_last_autoanalyzeGAUGELast time at which this table was analyzed by the autovacuum daemon
cnp_pg_stat_user_tables_vacuum_countCOUNTERNumber of times this table has been manually vacuumed (not counting VACUUM FULL)
cnp_pg_stat_user_tables_autovacuum_countCOUNTERNumber of times this table has been vacuumed by the autovacuum daemon
cnp_pg_stat_user_tables_analyze_countCOUNTERNumber of times this table has been manually analyzed
cnp_pg_stat_user_tables_autoanalyze_countCOUNTERNumber of times this table has been analyzed by the autovacuum daemon
Labels

The above metrics may have these labels, represented as dimensions in Azure Monitor:

LabelDescription
datnameName of current database
schemanameName of the schema that this table is in
relnameName of this table

Group cnp_pg_stat_replication

Realtime information about replication connections to this postgres instance, their progress and activity.

Metrics in this section are not reset when a postgres stats reset is issued on the db server. The "stat" in the name is a historic artefact from postgres development.

Derived from the pg_stat_replication view.

See also cnp_pg_replication_slots, cnp_pg_replication.

Metrics
MetricUsageDescription
cnp_pg_stat_replication_backend_startCOUNTERTime when this process was started
cnp_pg_stat_replication_backend_xmin_ageCOUNTERThe age of this standby's xmin horizon
cnp_pg_stat_replication_sent_diff_bytesGAUGEDifference in bytes from the last write-ahead log location sent on this connection
cnp_pg_stat_replication_write_diff_bytesGAUGEDifference in bytes from the last write-ahead log location written to disk by this standby server
cnp_pg_stat_replication_flush_diff_bytesGAUGEDifference in bytes from the last write-ahead log location flushed to disk by this standby server
cnp_pg_stat_replication_replay_diff_bytesGAUGEDifference in bytes from the last write-ahead log location replayed into the database on this standby server
cnp_pg_stat_replication_write_lag_secondsGAUGETime elapsed between flushing recent WAL locally and receiving notification that this standby server has written it
cnp_pg_stat_replication_flush_lag_secondsGAUGETime elapsed between flushing recent WAL locally and receiving notification that this standby server has written and flushed it
cnp_pg_stat_replication_replay_lag_secondsGAUGETime elapsed between flushing recent WAL locally and receiving notification that this standby server has written, flushed and applied it
Labels

The above metrics may have these labels, represented as dimensions in Azure Monitor:

LabelDescription
usenameName of the replication user
application_nameName of the application
client_addrClient IP address

Group cnp_pg_statio_user_tables

I/O activity statistics maintained by postgres on non-system tables.

Metrics in this section are reset when a postgres stats reset is issued on the db server.

Derived from the pg_statio_user_tables view.

See also cnp_pg_stat_user_tables.

Metrics
MetricUsageDescription
cnp_pg_statio_user_tables_heap_blks_readCOUNTERNumber of disk blocks read from this table
cnp_pg_statio_user_tables_heap_blks_hitCOUNTERNumber of buffer hits in this table
cnp_pg_statio_user_tables_idx_blks_readCOUNTERNumber of disk blocks read from all indexes on this table
cnp_pg_statio_user_tables_idx_blks_hitCOUNTERNumber of buffer hits in all indexes on this table
cnp_pg_statio_user_tables_toast_blks_readCOUNTERNumber of disk blocks read from this table's TOAST table (if any)
cnp_pg_statio_user_tables_toast_blks_hitCOUNTERNumber of buffer hits in this table's TOAST table (if any)
cnp_pg_statio_user_tables_tidx_blks_readCOUNTERNumber of disk blocks read from this table's TOAST table indexes (if any)
cnp_pg_statio_user_tables_tidx_blks_hitCOUNTERNumber of buffer hits in this table's TOAST table indexes (if any)
Labels

The above metrics may have these labels, represented as dimensions in Azure Monitor:

LabelDescription
datnameName of current database
schemanameName of the schema that this table is in
relnameName of this table

Group cnp_pg_settings

Expose the subset of postgres server settings that can be represented as Prometheus compatible metrics - any integer, boolean or real number. Text-format settings, list-valued settings and enumeration-typed settings are not captured or reported.

This set of metrics does not expose per-database settings assigned with ALTER DATABASE ... SET ..., per-user settings assigned with ALTER USER ... SET ..., or per-session values. It only shows the database-system-wide global values. You can explore other settings interactively using postgres system views.

Derived from the pg_settings view.

Metrics
MetricUsageDescription
cnp_pg_settings_settingGAUGESetting value
Labels

The above metrics may have these labels, represented as dimensions in Azure Monitor:

LabelDescription
nameName of the setting

Other metrics streams

In addition to postgres metrics from the Cloud Native PostgreSQL operator that manages databases in BigAnimal, additional metrics about Kubernetes cluster state and other details may be streamed to the Log Workspace. Any such metrics are generally well-known metrics from widely used tools, documented by the upstream vendor of the component.

Details on individual metrics from such sources will not be listed in this document. Refer to the documentation of the tool or project that defines the metrics.

See also:

Additional streams of metrics may be supplied by the cloud platform itself directly to the customer's metrics, analytics and dashboarding endpoint.

Dive deeper

Other capabilities available in the Azure portal, outside the scope of this documentation, include the ability to:

  • Discover metrics in the Azure Monitor Metrics Explorer (Monitor -> Metrics)
  • Query logs and metrics from the Azure Monitor Logs view (Monitor -> Logs)
  • Create dashboards backed by metrics queries in the Portal
  • Define alerting rules to trigger notifications based on queries
  • Use AI-assisted analytics assistant capabilities ("Metrics Advisers") to find patterns in metrics
  • Apply complex analytic tools for time-series data in Application Insights, including seasonally adjusted statistics to discover patterns, anomalies and trends.