| sidebar_position | 18 |
|---|
The query-exporter service monitors the OpenRemote PostgreSQL database and exposes metrics on port 9560 for Prometheus scraping. It uses query-exporter to collect database health metrics.
pg_table_bloat_count- Number of tables/indexes with bloat exceeding thresholdspg_table_bloat_ratio- Bloat ratio per table/index (1.0 = no bloat, 2.0 = 100% bloat)pg_table_bloat_bytes- Estimated bloat size in bytes per table/indexpg_table_bloat_wasted_mb- Estimated wasted space in megabytes per table/index
pg_autovacuum_workers_active- Number of currently active autovacuum workerspg_autovacuum_workers_max- Maximum number of autovacuum workers configuredpg_autovacuum_running- Running autovacuum processes (labels: database, table_schema, table_name, phase)
pg_datapoint_query_duration_seconds- Histogram of execution times for the attribute that is automatically identified as having the highest datapoint countpg_datapoint_count- Total number of datapoints for the attribute that is automatically identified as having the highest datapoint count
pg_database_size_megabytes- Total database size in megabytespg_connections_active- Number of active connectionspg_connections_idle- Number of idle connectionspg_locks_count- Number of locks by type
The service uses the following environment variables (automatically configured in profile/deploy.yml):
Database Connection:
POSTGRES_HOST- Database host (default:postgresql)POSTGRES_PORT- Database port (default:5432)POSTGRES_DB- Database name (default:openremote)POSTGRES_USER- Database user (default:postgres)POSTGRES_PASSWORD- Database password (default:postgres)
Bloat Thresholds:
TABLE_BLOAT_THRESHOLD- Table bloat ratio threshold (default:1.2= 20% bloat)INDEX_BLOAT_THRESHOLD- Index bloat ratio threshold (default:1.5= 50% bloat)
:::note
Indexes typically bloat faster than tables, so the default index threshold is higher.
:::
Set environment variables before starting services:
export TABLE_BLOAT_THRESHOLD=1.3 # 30% table bloat
export INDEX_BLOAT_THRESHOLD=2.0 # 100% index bloat- Table bloat queries: Every 5 minutes
- Autovacuum queries: Every 30 seconds
- Datapoint performance: Every 60 seconds (samples 100 most recent datapoints)
- Database size: Every 5 minutes
- Connection/lock stats: Every 30 seconds
curl http://localhost:9560/metricsTo expose on a private network in production, uncomment this line in profile/deploy.yml:
- "${PRIVATE_IP:-127.0.0.1}:9560:9560"Add this scrape configuration to your Prometheus config:
scrape_configs:
- job_name: 'openremote-postgres'
static_configs:
- targets: ['query-exporter:9560'] # Use service name in Docker network
# - targets: ['localhost:9560'] # Use localhost if Prometheus runs on host
scrape_interval: 30s:::note
When Prometheus runs in the same Docker network as OpenRemote, use the service name query-exporter:9560. Only use localhost:9560 if Prometheus is running directly on the host machine.
:::
To modify queries or add new metrics:
- Edit the
config.yamlfile in thequery-exporterconfiguration directory.- Default host path:
/deployment/query-exporter/config.yaml - Container path (Docker volume mount):
/config/config.yaml - For the exact host path in your environment, see the
query-exportervolume mapping inprofile/deploy.yml.
- Default host path:
- Restart the service:
docker-compose -f profile/deploy.yml restart query-exporterdocker-compose -f profile/deploy.yml logs -f query-exporterdocker-compose -f profile/deploy.yml exec query-exporter sh
apk add postgresql-client
psql -h $POSTGRES_HOST -U $POSTGRES_USER -d $POSTGRES_DBcurl http://localhost:9560/metricsIf bloat detection queries impact database performance:
- Increase query interval - Change from 300s to 600s or higher in
config.yaml - Limit to specific schemas - Modify queries to target specific schemas only
- Schedule off-peak runs - Use
scheduleoption instead ofinterval - Reduce sample size - Lower the datapoint query sample size (default: 100)
- Bloat detection scans
pg_statsandpg_classcatalogs (limited to top 50 results) - Datapoint performance uses a sample size of 100 recent datapoints from the largest attribute (configurable)
- All queries exclude PostgreSQL system schemas (
pg_%andinformation_schema)
1.0- No bloat (optimal size)1.2- 20% bloat (default table threshold)1.5- 50% bloat (default index threshold)2.0- 100% bloat (object is twice the optimal size)
- Tables > 1.2 - Run
VACUUM FULLduring maintenance window - Indexes > 1.5 - Run
REINDEXon affected indexes - Critical bloat (> 2.0) - Immediate maintenance recommended
The bloat detection queries use these PostgreSQL internal constants:
1048576- Bytes per megabyte (1024 × 1024)8- Bits per byte (for null bitmap calculation)20- Page header size in bytes12- Index header overhead in bytes4- Item pointer size in bytes23- Typical tuple header size for PostgreSQL 14+ on Linux (this value may differ for other PostgreSQL versions or operating systems; verify for your deployment)4- Memory alignment for Linux containers