2

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

enter image description here

I would like to rename the long label for the line chart to something shorter like "request count". How do I do it?

kdima
  • 53
  • 4
Petra Barus
  • 3,815
  • 8
  • 48
  • 87

4 Answers4

4

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

Petra Barus
  • 3,815
  • 8
  • 48
  • 87
  • This worked for me as well and appears to be the most straightforward way to rename the line with an arbitrary string. Please consider accepting your own answer as the solution! Thanks. – Linus Arver Jul 17 '23 at 19:13
1

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.

enter image description here enter image description here

cypherphage
  • 170
  • 1
  • 1
  • 10
1

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())]
Cheng Hou
  • 81
  • 1
0

You can try renaming the value column with | value [request_count: val()].

Reference entry for the value operator

kdima
  • 53
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 05 '22 at 18:52