Overview
In addition to PostgreSQL database metrics, the exporter exposes metrics about its own operation. These metrics help monitor the health and performance of the exporter itself. All exporter self-monitoring metrics use the following prefixes:pg_exporter_*- Exporter-specific metricspg_scrape_*- Per-collector scrape metricspostgres_exporter_*- Configuration reload metrics
Connection Status Metrics
pg_up
Type: Gauge Labels: None (can have constant labels if configured) Description: Indicates whether the last scrape was able to connect to the PostgreSQL server. Values:1- Successfully connected to PostgreSQL0- Failed to connect to PostgreSQL
- Primary health check for PostgreSQL connectivity
- Alerting on database unavailability
- Uptime monitoring
Scrape Performance Metrics
pg_exporter_last_scrape_duration_seconds
Type: Gauge Labels: None (can have constant labels if configured) Description: Duration of the last scrape of metrics from PostgreSQL in seconds. Use cases:- Monitoring exporter performance
- Identifying slow metric collection
- Capacity planning
pg_exporter_scrapes_total
Type: Counter Labels: None (can have constant labels if configured) Description: Total number of times PostgreSQL was scraped for metrics. Use cases:- Monitoring scrape frequency
- Calculating error rates
- Verifying exporter is running
pg_exporter_last_scrape_error
Type: Gauge Labels: None (can have constant labels if configured) Description: Whether the last scrape of metrics from PostgreSQL resulted in an error. Values:1- Last scrape encountered an error0- Last scrape was successful
- Detecting metric collection failures
- Alerting on persistent errors
- Debugging exporter issues
Per-Collector Metrics
These metrics are exposed for each enabled collector, allowing fine-grained monitoring of individual collector performance.pg_scrape_collector_duration_seconds
Type: Gauge Labels:collector- Name of the collector (e.g., “database”, “stat_database”, “locks”)
- Identifying slow collectors
- Optimizing collector performance
- Troubleshooting specific collectors
- Fast collectors (<0.1s):
database,replication,postmaster - Medium collectors (0.1 to 1s):
stat_database,stat_bgwriter,locks - Slow collectors (>1s):
stat_user_tables,stat_statements(especially on busy systems)
pg_scrape_collector_success
Type: Gauge Labels:collector- Name of the collector
1- Collector succeeded0- Collector failed
- Detecting collector-specific failures
- Monitoring collector health
- Identifying permission or compatibility issues
- Permission errors: Collector queries require specific PostgreSQL privileges
- Version incompatibility: Collector not supported on current PostgreSQL version
- Extension missing: Collector requires an extension that isn’t installed (e.g.,
pg_stat_statements) - Configuration error: Invalid collector-specific configuration
Configuration Reload Metrics
These metrics track the status of configuration file reloads.postgres_exporter_config_last_reload_successful
Type: Gauge Labels: None Description: Whether the last configuration reload was successful. Values:1- Configuration loaded successfully0- Configuration load failed
- Detecting configuration errors
- Verifying configuration changes
- Alerting on misconfigurations
postgres_exporter_config_last_reload_success_timestamp_seconds
Type: Gauge Labels: None Description: Timestamp of the last successful configuration reload (Unix time). Use cases:- Tracking when configuration was last changed
- Correlating configuration changes with issues
- Verifying configuration updates
User Queries Metrics
When custom user queries are configured via--extend.query-path (deprecated feature):
pg_exporter_user_queries_load_error
Type: Gauge Labels:filename- Path to the user queries filehashsum- SHA256 hash of the file contents
1- User queries file failed to load or parse0- User queries file loaded successfully
- Detecting errors in custom query files
- Verifying custom query deployments
- Troubleshooting custom metrics
Monitoring Best Practices
Essential Alerts
Every PostgreSQL exporter deployment should monitor:-
Database connectivity:
-
Exporter health:
-
Collector failures:
-
Slow scrapes:
Grafana Dashboard
Recommended panels for an exporter health dashboard:- Connection status:
pg_up(stat panel) - Scrape duration: Graph of
pg_exporter_last_scrape_duration_seconds - Error rate: Graph of
rate(pg_exporter_last_scrape_error[5m]) - Collector performance: Table showing
pg_scrape_collector_duration_secondsby collector - Collector health: Heatmap of
pg_scrape_collector_successby collector over time
Debugging Exporter Issues
Whenpg_scrape_collector_success == 0 for a collector:
- Check exporter logs for detailed error messages
- Verify PostgreSQL permissions:
- Test collector queries manually using psql
- Verify PostgreSQL version compatibility for the collector
- Check if required extensions are installed:
Metric Retention and Cardinality
Exporter self-metrics have low cardinality:- Connection metrics: 1 timeseries per exporter instance
- Scrape metrics: 1 timeseries per exporter instance
- Collector metrics: ~10-20 timeseries per exporter instance (depends on enabled collectors)
- Config metrics: 1-2 timeseries per exporter instance
See Also
- Metrics Overview - All PostgreSQL metrics
- Collectors Guide - Detailed collector documentation
- Configuration Reference - Exporter configuration options