We can see the postgres connections in the GCP console, so we presume that it can be queried via the monitoring API. The console gives us this MQL query:
fetch cloudsql_database
| metric 'cloudsql.googleapis.com/database/postgresql/num_backends'
| filter (resource.database_id == 'my-project-id:my-database-id')
| group_by 1m, [value_num_backends_mean: mean(value.num_backends)]
| every 1m
The monitoring API https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/query
says that the query parameter is required and the query is in the monitoring query language format. However, when I "Try this API" and attempt to set the query to what I got from the console above, I get an error that "Unexpected character encountered" for the | character. How can I properly format the query in a way to get the result I am looking for? I have looked through the Retrieving data with timeSeries.query documentation, and it does not mention the need to escape such characters.