Connect Google Cloud Platform instances to PMM¶
PMM can monitor MySQL or PostgreSQL instances hosted on the Google Cloud Platform.
The connection can be direct, or indirect using Cloud SQL Proxy.
MySQL¶
To add a MySQL instance on Google Cloud:
-
The database server must be accessible by PMM Client. If PMM Client is not also hosted on GCP, you will need to add a network interface with a public interface.
-
Configure Performance Schema on the MySQL server. Using the GCP console’s Cloud Shell or your own
gcloudinstallation, run:gcloud sql instances patch <instance_name> --database-flags performance_schema=on -
(Optional) For SSL/TLS connections, download the server CA certificate from the GCP Console under your Cloud SQL instance > Connections > Security.
-
Log into the PMM user interface.
-
Select PMM Configuration > PMM Inventory > Service > Add Service > MySQL.
-
Fill in the details for the remote MySQL instance and make sure to enable the Use performance schema option.
-
Click Add service.
-
Go to Dashboards and check for values in the MySQL Instance Summary dashboard and in Query Analytics.
Direct connection with TLS¶
For secure direct connections to Google Cloud SQL MySQL instances, you can use TLS with partial certificate support.
Google Cloud SQL MySQL requires only the CA certificate for TLS connections. Client certificate and key are optional and only needed if you’ve explicitly configured client certificate authentication.
To add a GCP Cloud SQL MySQL instance with TLS via the UI:
- Go to PMM Configuration > PMM Inventory > Add Service > MySQL.
- Fill in the connection details (host, port, username, password).
- Enable Use performance schema option.
- Check Use TLS for database connections.
- Paste the server CA certificate content in the TLS CA field.
- Click Add service.
With TLS (CA certificate only - recommended):
pmm-admin add mysql \
--username=pmm \
--password=secure \
--host=<YOUR_GCP_SQL_IP> \
--port=3306 \
--service-name=MySQL-GCP \
--query-source=perfschema \
--tls \
--tls-ca=/path/to/server-ca.pem
With TLS and client authentication (if configured):
pmm-admin add mysql \
--username=pmm \
--password=secure \
--host=<YOUR_GCP_SQL_IP> \
--port=3306 \
--service-name=MySQL-GCP \
--query-source=perfschema \
--tls \
--tls-ca=/path/to/server-ca.pem \
--tls-cert=/path/to/client-cert.pem \
--tls-key=/path/to/client-key.pem
Without TLS:
pmm-admin add mysql \
--username=pmm \
--password=secure \
--host=<YOUR_GCP_SQL_IP> \
--port=3306 \
--service-name=MySQL-GCP \
--query-source=perfschema
Certificate file location¶
When using TLS certificates with Google Cloud SQL MySQL, make sure to:
- store the downloaded server CA certificate file on the server where PMM Client is installed
- provide the full path to the certificate in the
--tls-caparameter - use
--tls-skip-verifyonly in development/testing environments to skip hostname validation
PostgreSQL¶
To add a PostgreSQL instance on Google Cloud:
-
The database server must be accessible by PMM Client. If PMM Client is not also hosted on GCP, you will need to add a network interface with a public interface.
-
Configure
pg_stat_statements. Open an interactive SQL session with your GCP PostgreSQL server and run:CREATE EXTENSION pg_stat_statements; -
Log into the PMM user interface.
-
Select PMM Configuration > PMM Inventory > Services > Add Service > PostgreSQL.
-
Fill in the details for the remote PostgreSQL instance and make sure to PG Stat Statements option under Stat tracking options.
-
Click Add service.
-
Go to Dashboards and check for values in the PostgreSQL Instances Overview and Query Analytics.
Cloud SQL Proxy¶
MySQL¶
To add a MySQL instance:
-
Create instance on GCP.
-
Note connection as
<project_id>:<zone>:<db_instance_name>. -
Enable Admin API and download the JSON credential file.
-
Enable Performance Schema.
-
Run Cloud SQL Proxy (runs on PMM Client node).
docker run -d \ -v ~/path/to/admin-api-file.json:/config \ -p 127.0.0.1:3306:3306 \ gcr.io/cloudsql-docker/gce-proxy:1.19.1 \ /cloud_sql_proxy \ -instances=example-project-NNNN:us-central1:mysql-for-pmm=tcp:0.0.0.0:3306 \ -credential_file=/configwget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy chmod +x cloud_sql_proxy ./cloud_sql_proxy -instances=example-project-NNNN:us-central1:mysql-for-pmm=tcp:3306 \ -credential_file=/path/to/credential-file.json -
Add instance:
pmm-admin add mysql --host=127.0.0.1 --port=3306 \ --username=root --password=secret \ --service-name=MySQLGCP --query-source=perfschema
PostgreSQL¶
To add a PostgreSQL instance:
-
Create instance on GCP.
-
Note connection as
<project_id>:<zone>:<db_instance_name>. -
Enable Admin API and download the JSON credential file.
-
Run Cloud SQL Proxy:
./cloud_sql_proxy -instances=example-project-NNNN:us-central1:pg-for-pmm=tcp:5432 \ -credential_file=/path/to/credential-file.json -
Log into PostgreSQL.
-
Load extension:
CREATE EXTENSION pg_stat_statements; -
Add service:
pmm-admin add postgresql --host=127.0.0.1 --port=5432 \ --username="postgres" --password=secret --service-name=PGGCP