Petra Barus
Petra Barus

Reputation: 4013

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

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?

Upvotes: 4

Views: 3097

Answers (4)

Cheng Hou
Cheng Hou

Reputation: 91

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())]

Upvotes: 1

kdima
kdima

Reputation: 98

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

Reference entry for the value operator

Upvotes: 1

Petra Barus
Petra Barus

Reputation: 4013

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

Upvotes: 7

cypherphage
cypherphage

Reputation: 298

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

Upvotes: 0

Related Questions