'GCP MQL: Rename a line in monitoring chart
I have a simple Google Cloud Monitoring Query Language to show the count of all requests to all containers in kubernetes from log-based metrics. The query is below.
k8s_container::logging.googleapis.com/user/service-api-gateway-prod-request-in-count | sum
The widget will look like below
I would like to rename the long label for the line chart to something shorter like "request count". How do I do it?
Solution 1:[1]
So the best I can do is to add a new column to the table and map the column.
In my example, I add add [p: 'error count'] | map [p] to the line, and become like this.
k8s_container::logging.googleapis.com/user/service-api-gateway-prod-request-in-count | sum | add [p: 'error count'] | map [p]
This works in my case.
References
Solution 2:[2]
Instead of using MQL(Monitoring Query Language), try the Advanced tab. Just for an example I will be using a metric name mysite-container-exited, you can name it whatever you want.
- Select your resource type and metric that you created in log-based metric.
- Select No preprocessing step.
- Select alignment function as SUM. Now the widget will just show the name that you entered in the log-based metric details tab.
Solution 3:[3]
You can try renaming the value column with | value [request_count: val()].
Solution 4:[4]
The sum is actually a shortcut to group_by table operation with sum aggregator. Using the complete form of group_by allow you to control the output value column name.
k8s_container::logging.googleapis.com/user/service-api-gateway-prod-request-in-count
| group_by [], [request_count: sum(val())]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Petra Barus |
| Solution 2 | |
| Solution 3 | kdima |
| Solution 4 | Cheng Hou |



