Help Center/ Cloud Application Engine/ Best Practices/ Configuring PromQL to Implement Custom Auto Scaling
Updated on 2024-08-30 GMT+08:00

Configuring PromQL to Implement Custom Auto Scaling

Assume that there is a component named my_component, its environment is my_environment, and the application is my_application.

Assume that the component provides the custom metric http_requests_total, which indicates the total number of HTTP requests. This section uses this metric as an example to describe how to use PromQL.

Querying Metrics

Run the following PromQL statement to query the latest metric:

http_requests_total{environment_name="my_environment",application_name="my_application",component_name="my_component"}

Run the following command to query all metrics in the last 5 minutes:

http_requests_total{environment_name="my_environment",application_name="my_application",component_name="my_component"}[5m]

Processing Queried Metrics

Querying Metrics contains multiple metrics queried. For example, if a component has multiple instances, there are multiple pieces of metrics; if metrics have been queried for a period of time, there are multiple pieces of metrics.

PromQL in an AS policy must return a single value. Therefore, you need to process the queried metrics to obtain a single value. Example:

Query the latest metric and calculate the average value to obtain the average value of the total number of HTTP requests of all instances.

avg(http_requests_total{environment_name="my_environment",application_name="my_application",component_name="my_component"})

Query all metrics in the last 5 minutes, obtain the change (increased value), and calculate the average value to obtain the average number of increased HTTP requests of each instance in the last 5 minutes.

avg(delta(http_requests_total{environment_name="my_environment",application_name="my_application",component_name="my_component"}[5m]))

For more information, see PromQL document and PromQL example.