This page is not yet available in Spanish. We are working on its translation. If you have any questions or feedback about our current translation project, feel free to reach out to us!
To collect custom metrics with the Postgres integration, use the custom_queries option in the conf.d/postgres.d/conf.yaml file at the root of your Agent’s configuration directory. See the sample postgres.d/conf.yaml for more details.
Note: When generating custom metrics that require querying additional tables, you may need to grant the SELECT permission on those tables to the Postgres user. Example: grant SELECT on <TABLE_NAME> to <USER>;
Required: Yes Each metric starts with the chosen prefix.
query
Required: Yes The SQL to execute. It can be a simple statement or a multi-line script. All of the rows of the results are evaluated. Use the pipe if you require a multi-line script.
columns
Required: Yes A list representing each column ordered sequentially from left to right. There are 2 required pieces of data: - name: The suffix to append to the metric_prefix to form the full metric name. If the type is specified as tag, the column is instead applied as a tag to every metric collected by this query. - type: The submission method (for example, gauge, count, rate, etc.). This can also be set to tag to tag each metric in the row with the name and value (<name>:<row_value>) of the item in this column.
tags
Required: No A list of static tags to apply to each metric.
At least one of the items in defined columns should be a metric type (gauge, count, rate, etc.). For more information about metrics submission from an Agent Check, see Metrics Types.
The number of items defined in columns must equal the number of columns returned in the query.
The order in which the items in columns are defined must be same order returned in the query.
custom_queries:- query:Select F3, F2, F1 from Table;columns:- {name: f3_metric_alias, type:gauge}- {name: f2_tagkey , type:tag }- {name: f1_metric_alias, type:count}[...]
The goal is to capture the age and salary of Paul as metric values with his name and address as tags.
SQL query:
SELECT age,salary,name,address FROM company WHERE name = 'Paul'
Corresponding custom_queries YAML configuration:
custom_queries:- metric_prefix:postgresqlquery:SELECT age,salary,name,address FROM company WHERE name = 'Paul'columns:- name:employee_agetype:gauge- name:employee_salarytype:gauge- name:nametype:tag- name:localisationtype:tagtags:- query:custom