Step 3: Configure and Deploy the Collector
Deploying the collector with Helm
The pganalyze collector runs as an ordinary container in your cluster. There’s nothing
CNPG-specific about how the collector itself is deployed. It just needs network connectivity to
the CNPG cluster’s -rw Service, the same way any other application in the cluster would connect.
Prerequisites
kubectlis configured for your cluster- The Helm CLI v3 or above is installed
- CNPG is already installed, and you have a
Clusterwith the monitoring role andpg_stat_statementsset up from the previous two steps
Fetch the Helm chart’s example values
helm repo add pganalyze https://charts.pganalyze.com/
helm repo update
helm show values pganalyze/pganalyze-collector > collector-values.yamlBelow, you’ll edit collector-values.yaml to configure the collector, including your pganalyze
API key and the connection details for the database you want to monitor.
We name it collector-values.yaml rather than the default values.yaml so it doesn’t collide with
other charts’ values files in the same directory, such as Vector’s in the Log Insights setup.
Configure the connection settings
Update the extraEnv section of collector-values.yaml:
extraEnv:
PGA_API_KEY: your-organization-api-key
# PGA_API_BASE_URL: http://your-pganalyze-enterprise-server.internal
DB_HOST: my-cluster-rw
DB_NAME: app
DB_USERNAME: pganalyze
DB_PASSWORD: your_monitoring_role_password-
The
PGA_API_KEYcan be found in the pganalyze Settings page for your organization, under the API Access tab - The
PGA_API_BASE_URLis only needed if you’re using pganalyze Enterprise Server. Otherwise, leave it commented out. - The
DB_HOSTshould be the CNPG-rwService for your cluster:<cluster-name>-rwif the collector is deployed in the same namespace as theCluster, or<cluster-name>-rw.<namespace>.svcif it’s in a different namespace. This Service always points at the current primary, so the collector keeps working across failovers without reconfiguration. - The
DB_NAMEis the database on the cluster you want to monitor.appis CNPG’s default application database name unless you customized.spec.bootstrap.initdb.database. To monitor more than one database on this cluster, use a comma-separated list instead, starting with the primary one, e.g.app,other_db, or end the list with*(e.g.app,*) to monitor every database on the cluster. See the collector settings reference for details - The
DB_USERNAMEandDB_PASSWORDare the credentials from thepganalyze-monitoring-userSecret you created in Step 1
extraEnv is fine for a first test, but since DB_PASSWORD is a credential, we recommend moving to
a Kubernetes Secret-based config once you’ve confirmed things work. Save the following as pganalyze-collector-config.yaml:
apiVersion: v1
kind: Secret
metadata:
name: pganalyze-secrets
stringData:
pganalyze-collector.conf: |
[pganalyze]
api_key = your_api_key
# api_base_url = http://your-pganalyze-enterprise-server.internal
[my-cluster]
db_host = my-cluster-rw
db_name = app
db_username = pganalyze
db_password = your_monitoring_role_passwordThen apply it:
kubectl apply -f pganalyze-collector-config.yamlFinally, in collector-values.yaml, remove the extraEnv section and mount the Secret at /config instead:
volumes:
- name: scratch
emptyDir: {}
- name: config-volume
secret:
secretName: pganalyze-secrets
volumeMounts:
- mountPath: /tmp
name: scratch
subPath: tmp
- mountPath: /state
name: scratch
subPath: state
- mountPath: /config
name: config-volumeNote: The pganalyze collector supports more optional settings
(multiple database names, log forwarding via db_log_otel_server, etc.) that you can add to the
[my-cluster] section above.
Install the Helm chart
helm upgrade --install my-collector pganalyze/pganalyze-collector --values=collector-values.yamlAdjust the namespace if needed. You can run the same command again whenever you change
collector-values.yaml.
To verify the install went well, check the deployment and pod logs:
kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
my-collector-pganalyze-collector 1/1 1 1 1m10s
kubectl logs deploy/my-collector-pganalyze-collector
I [my-cluster] Submitted compact snapshots successfully: 6 activityThe Submitted compact snapshots successfully message indicates the collector is running
correctly.
Your setup is complete. The dashboard will start showing data within a few minutes.
Once you’ve confirmed the install is successful and you’re receiving query data in pganalyze, we recommend setting up Log Insights as a follow-up step, to automatically track log events in your database.
(Optional) Running tests
You can run the collector’s built-in test using docker-entrypoint.sh inside the running pod:
kubectl exec deploy/my-collector-pganalyze-collector -- /home/pganalyze/docker-entrypoint.sh testCouldn't find what you were looking for or want to talk about something specific?
Start a conversation with us →