Google Cloud SQL
Monitor Google Cloud SQL database metrics for MySQL, PostgreSQL, and SQL Server using OpenTelemetry collector with Last9
Use OpenTelemetry to collect Google CloudSQL metrics and send telemetry data to Last9.
This integration supports following CloudSQL databases:
- MySQL
- PostgreSQL
- SQL Server
Prerequisites
Before setting up Google Cloud SQL monitoring, ensure you have:
- Google Cloud account with administrative privileges or CloudSQL Admin privileges
- Access to a project in Google Cloud Platform (GCP)
- Google CloudSQL APIs enabled - follow this guide to enable APIs
- Virtual Machine where you can run OpenTelemetry Collector to collect data from Google CloudSQL and send to Last9
-
Setting up Service Account for Monitoring
Create a Service Account:
- Navigate to Google Cloud Console: https://console.cloud.google.com/
- Go to “IAM & Admin” > “Service Accounts” in the left sidebar
- Click “CREATE SERVICE ACCOUNT” at the top
- Enter a name (e.g., “otel-collector”)
- Optionally add a description (e.g., “Service account for OpenTelemetry Collector”)
- Click “CREATE AND CONTINUE”
Assign Required Roles:
- Add the following roles:
- “Monitoring Viewer” (for reading metrics)
- “Monitoring Metric Reader” (for accessing metric data)
- Click “CONTINUE” and then “DONE”
Attach Service Account to VM Instance:
- Navigate to “Compute Engine” > “VM instances”
- For an existing VM:
- Select the instance, click “STOP”
- Once stopped, click “EDIT”
- Under “Service account”, select your newly created service account
- Click “SAVE” and restart the instance
- For a new VM:
- When creating the instance, select your service account under the “Identity and API access” section
Alternative: Using Application Default Credentials:
- If you cannot change the VM’s service account, you can configure Application Default Credentials
- In the Service Account page, select your service account
- Click on “KEYS” tab
- Click “ADD KEY” > “Create new key”
- Select JSON format and click “CREATE”
- Upload the key file to your VM
- Set the environment variable before starting the collector:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json"
For more detailed information about authentication using service accounts, refer to Google Cloud’s Application Default Credentials documentation.
-
Install OpenTelemetry Collector
You can install either
rpmordebpackage depending on flavor of operating system you are using.Note: systemd is required for automatic service configuration.
Installing rpm package:
wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.118.0/otelcol-contrib_0.118.0_linux_amd64.rpmsudo rpm -ivh otelcol-contrib_0.118.0_linux_amd64.rpmInstalling deb package:
wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.118.0/otelcol-contrib_0.118.0_linux_amd64.debsudo dpkg -i otelcol-contrib_0.118.0_linux_amd64.debMore installation options can be found here.
-
Configure Collector
Use the following configuration for Otel Collector:
receivers:googlecloudmonitoring:collection_interval: 60sproject_id: gcp-project-idmetrics_list:# Filter for specific metrics such cloudsql- metric_descriptor_filter: 'metric.type = starts_with("cloudsql.googleapis.com")'processors:batch:timeout: 20ssend_batch_size: 100000send_batch_max_size: 100000resourcedetection/gcp:detectors: ["gcp"]exporters:otlp/last9:endpoint: "{{ .Logs.WriteURL }}"headers:"Authorization": "{{ .Logs.AuthValue }}"debug:verbosity: detailedservice:pipelines:metrics:receivers: [googlecloudmonitoring]processors: [batch, resourcedetection/gcp]exporters: [otlp/last9]Note: Replace
gcp-project-idwith your actual Google Cloud project ID.The complete list of supported metrics for CloudSQL MySQL can be found here.
The complete list of supported metrics for CloudSQL PostgreSQL can be found here.
The complete list of supported metrics for CloudSQL SQL Server can be found here.
Read more about the Google Cloud monitoring receiver configuration options here.
-
Start Collector
Run the otel collector using
systemctlcommand:sudo systemctl start otelcol-contribsudo systemctl status otelcol-contribsudo systemctl restart otelcol-contrib -
Check Collector Logs
Monitor the collector logs to ensure it’s working correctly:
sudo journalctl -u otelcol-contrib -f
Verification
To verify the setup is working:
- Check that the collector service is running
- Review the collector logs for any errors
- Log into your Last9 account to confirm CloudSQL metrics are being received
Need Help?
If you encounter any issues or have questions:
- Join our Discord community for real-time support
- Contact our support team at support@last9.io