7.4 KiB
How-to-deploy-postgres-exporter-on-SaaS-to-monitor-postgres-custom-query_704971984
The community repo of postgres-exporter is https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-postgres-exporter
The image verison of postgres-expoter we used is v0.12.0. we have scaned the image security.
Preparation steps:
Create a dedicated postgres read user to access database.
CREATE USER grafana_reader WITH PASSWORD '*****';
GRANT CONNECT ON DATABASE xservices_ems TO grafana_reader;
GRANT CONNECT ON DATABASE xservices_rms TO grafana_reader;
GRANT CONNECT ON DATABASE idm TO grafana_reader;
GRANT CONNECT ON DATABASE bo_ats TO grafana_reader;
\c xservices_ems
GRANT USAGE ON SCHEMA maas_admin TO grafana_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA maas_admin TO grafana_reader;
\c xservices_rms
GRANT USAGE ON SCHEMA maas_admin TO grafana_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA maas_admin TO grafana_reader;
\c idm
GRANT USAGE ON SCHEMA idm TO grafana_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA idm TO grafana_reader;
\c postgres
GRANT USAGE ON SCHEMA public TO grafana_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO grafana_reader;
\c bo_ats
GRANT USAGE ON SCHEMA bo_db_user TO grafana_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA bo_db_user TO grafana_reader;
GRANT pg_read_all_stats TO grafana_reader;
Create function based on the basic SQL query:
- To query the tenantID cross-database, use the dblink extension. The SELECT statement from dblink will return a table. Check if the extension has been created.
SELECT * FROM pg_extension WHERE extname = 'dblink';
CREATE EXTENSION dblink;
2. use maas_admin to login xservices_ems,and run below alert default command to let feature newly created table with select permission.
ALTER DEFAULT PRIVILEGES IN SCHEMA maas_admin GRANT SELECT ON TABLES TO grafana_reader;
3. Create functions in xservice_ems with postgres user. Here is the query definition.
For xservices_ems database: database_monitoring_functions_definition.txt
For xservices_rms database: database_monitoring_functions_definition_xservices_rms.txt
4. Create index for the query, this step is very important, please confirm this with expert.
create index "ops_transaction_context_<tenant_id>_timestamp" on transaction_context_<tenant_id> (transaction_timestamp);
create index ops_transaction_context_<tenant_id>_entity_type on transaction_context_<tenant_id> ((entity::jsonb ->> 'entity_type'));
This needs to be scripted and performed for every tenant in the farm.
Installation steps:
- Download the helm chart prometheus-postgres-exporter.zip
- Replace the <grafana_reader_password> and with actual value in the values_database_level.yaml,values_dead_tuple.yaml and values_instance_level.yaml.
- Add User query in values_database_level.yaml file.
userQueries: |- nascm_transaction_context_queue_alltenants: query: "select tid,row_count from get_transaction_context_counts();" master: true cache_seconds: 1200 metrics: - row_count: description: context queue count usage: GAUGE - tid: description: tenant id usage: LABEL nascm_transaction_context_queue_retries_alltenants: query: "select tid,row_count from get_transaction_context_queue_retries();" master: true cache_seconds: 1200 metrics: - row_count: description: context queue count usage: GAUGE - tid: description: tenant id usage: LABEL etl_job_queue_alltenants: query: "select tid,etl_job_name,row_count from get_transaction_etl_job_queue();" master: true cache_seconds: 1200 metrics: - row_count: description: job queue count usage: GAUGE - tid: description: tenant id usage: LABEL - etl_job_name: description: job name usage: LABEL etl_job_delay_time_alltenants: query: "select tid,etl_job_name,delay_time from get_transaction_etl_job_delay_time();" master: true cache_seconds: 1200 metrics: - delay_time: description: delay time usage: GAUGE - tid: description: tenant id usage: LABEL - etl_job_name: description: job name usage: LABEL - run helm install command to deploy postgres exporter
helm install prometheus-postgres-exporter-instance-level. -f values_instance_level.yaml --namespace=monitoring
helm install prometheus-postgres-exporter-database-level. -f values_database_level.yaml --namespace=monitoring
helm install prometheus-postgres-exporter-for-dtuple. -f values_dead_tuple.yaml --namespace=monitoring
Configure Grafana to show metrics:
The metrics name is consist of _<metrics_name>. eg:
Import Dashboard to Grafana:
Download the PostgresSQL RDS Monitoring Dashboard and import to Grafana.
Related pages
- Page: ESM Cloud Farm Version Tracking
- Page: How to get an Opentext Confluence account
- Page: ITOM APM AppPluse Cloud Farm Information
- Page: ITOM Cloud Service Ops Doc Management Process
- Page: ITOM ESM Cloud Service Catalog
- Page: ITOM OpsB NOM Cloud Service Catalog
- Page: OpsB and NOM Cloud Deployments Version Tracking
Attachments:
image-2025-5-26_14-53-21.png (image/png)
database_monitoring_functions_definition.txt (text/plain)
image-2025-5-26_15-15-4.png (image/png)
prometheus-postgres-exporter.zip (application/zip)
database_monitoring_functions_definition.txt (text/plain)
database_monitoring_functions_definition.txt (text/plain)
7. PostgreSQL RDS Monitoring-1751508520632.json (application/json)
7. PostgreSQL RDS Monitoring-1751508520632.json (application/json)
database_monitoring_functions_definition_xservices_rms.txt (text/plain)
database_monitoring_functions_definition_xservices_rms.txt (text/plain)

