Open zmoog opened 8 months ago
I am creating a new PostgreSQL Flexible server to collect metrics from:
I selected the "Development" workload type, I think it will be okay for this purpose.
With a new PostgreSQL Flexible server up and running, we can start taking a look at the metrics on the Azure Portal.
For example, here are the value for the Active Connections mertric:
From the enhanced metrics docs:
You can use enhanced metrics for Azure Database for PostgreSQL flexible server to get fine-grained monitoring and alerting on databases. You can configure alerts on the metrics. Some enhanced metrics include a Dimension parameter that you can use to split and filter metrics data by using a dimension like database name or state.
Enabling the enhanced metrics seems easy:
Most of these new metrics are disabled by default. There are a few exceptions though, which are enabled by default. Rightmost column in the following tables indicates whether each metric is enabled by default or not. To enable those metrics which are not enabled by default, set the server parameter metrics.collector_database_activity to ON. This parameter is dynamic and doesn't require an instance restart.
On the Azure Portal, visit Settings > Server parameters and search for parameter names containing "metrics":
I am setting all the metrics.*
parameters to "ON".
Here are a few resources about metrics for the PostgreSQL Flexible server service:
We now have a PostgreSQL Flexible server instance, so the next step is open the metric reference for the PostgreSQL Flexible server service an look for interesting metrics.
Visit the Supported metrics for Microsoft.DBforPostgreSQL/flexibleServers list.
We can start with the Active Connections metric:
Here's the sample config from the generic Azure Monitor integration:
- resource_query: "resourceType eq 'Microsoft.DocumentDb/databaseAccounts'"
metrics:
- name: ["DataUsage", "DocumentCount", "DocumentQuota"]
namespace: "Microsoft.DocumentDb/databaseAccounts"
We can use it as a starting point.
Using the information at Supported metrics for Microsoft.DBforPostgreSQL/flexibleServers, we can rewrite the configuration for the PostgreSQL Flexible server metrics.
resource_query
selecting the resources with type Microsoft.DBforPostgreSQL/flexibleServers
Microsoft.DBforPostgreSQL/flexibleServers
as a namespace
- resource_query: "resourceType eq 'Microsoft.DBforPostgreSQL/flexibleServers'"
metrics:
- name:
- "active_connections"
namespace: "Microsoft.DBforPostgreSQL/flexibleServers"
Before adding more metrics and options, let's give this configuration a try.
Let's create a brand new agent policy for this test:
Pick an existing agent or install a new one, and assign the "Azure Metrics (PostgreSQL Flexible server)" policy to it.
After a couple of minutes, we can see new documents with the "Active Connections" metrics show up:
Using the same list of Supported metrics for Microsoft.DBforPostgreSQL/flexibleServers, we can add more metrics to the configuration:
- resource_query: "resourceType eq 'Microsoft.DBforPostgreSQL/flexibleServers'"
metrics:
- name:
- "active_connections"
- "memory_percent"
- "storage_free"
namespace: "Microsoft.DBforPostgreSQL/flexibleServers"
Here are the metrics in Discover:
Up until now, we added new metrics without specifying any dimension. Let's try adding another metric definition that includes a dimension.
- resource_query: "resourceType eq 'Microsoft.DBforPostgreSQL/flexibleServers'"
metrics:
- name:
- "active_connections"
- "memory_percent"
- "storage_free"
namespace: "Microsoft.DBforPostgreSQL/flexibleServers"
- name:
- "numbackends"
dimensions:
- name: "DatabaseName"
value: "*"
namespace: "Microsoft.DBforPostgreSQL/flexibleServers"
The new numbackends
metric definition brings two new fields:
azure.metrics.numbackends.max
metric field.azure.dimensions.database_name
dimension field.
I want to collect the following metrics:
from the following namespaces:
Using the generic Azure Monitor integration.
Overview
Here are the steps