Kubernetes Cluster CPU and Memory Chart

484 views
Skip to first unread message

vsa...@gmail.com

unread,
Oct 29, 2020, 11:31:47 AM10/29/20
to Google Stackdriver Discussion Forum
Hi Team,

I tried creating custom Charts for Kubernetes Cluster and Nodes which is not showing value in percentage. 

Need is to show values in percentage on the Charts and not the numbers which is not understood by users.

It is easy to understand the value percentage rather than a number, like cpu usage 55% and rather than 5.50

When i select the resource_type = Kubernetes Nodes
Metric = CPU Allocatable Utilisation
It shows number and not the percentage on the chart.

I do not see any Metric type which display value in percentage.

Can anyone guide on how to show percentage on the charts rather than values.

Regards,
Vikram

Igor Peshansky

unread,
Oct 29, 2020, 1:39:14 PM10/29/20
to vsa...@gmail.com, Google Stackdriver Discussion Forum
Vikram,

The way the value is displayed is determined by the unit annotation on the metric descriptor. As mentioned in the documentation [1], the unit for your metric is "1". The units are documented in [2]. To be displayed as percentage, the unit should be '%'.

One way to adjust the unit to your liking is to use the MQL [3] (specifically, the cast_units function [4] — you might need to also scale the value accordingly).

Hope this helps,
        Igor


--
© 2020 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Stackdriver Discussion Google Group (google-stackdr...@googlegroups.com) to participate in discussions with other members of the GoogleStackdriver community.
---
You received this message because you are subscribed to the Google Groups "Google Stackdriver Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-stackdriver-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-stackdriver-discussion/def9e01e-4fb2-4a0e-a3da-aac1eea01ca3n%40googlegroups.com.

Vikram Saggu

unread,
Oct 30, 2020, 8:11:29 AM10/30/20
to Igor Peshansky, Google Stackdriver Discussion Forum
Thanks Igor for your quick response, really appreciate it

I read your shared reference pages and tried to add cast_unit function but it does to get fit to MQL for Kubernetes. Though I used the cpu also under metric type but failed to accept.
I tried Google to see any supporting examples but nobody tried and even explained on showing the percentage over cpu and memory usage charts.  

Can anyone from your team help me to get this fit into my MQL, or if you can share any relevant snippet where Charts are showing values in percentage.

Below here is Kuberentes MQL
fetch k8s_node
| filter (resource.cluster_name == 'dp-api-bld-01-kcl-01-euwe2')
| group_by 1m, [value_used_bytes_mean: mean(value.used_bytes)]
| every 1m
| group_by [resource.node_name],
    [value_used_bytes_mean_aggregate: aggregate(value_used_bytes_mean)]

Thanks & Regards,
Vikram
--
Regards,
Vikram Saggu

Igor Peshansky

unread,
Oct 30, 2020, 8:36:01 AM10/30/20
to Vikram Saggu, Google Stackdriver Discussion Forum
Ah, you weren't originally asking about node/memory/used_bytes — you were asking about utilization, which is already a fraction that just needed to be converted to percentage. The equivalent for memory would be node/memory/allocatable_utilization. Have you tried using cast_units on a utilization metric?

For node/memory/used_bytes, which is an absolute number, you have to first convert it to a fraction, which means you have to divide it by some capacity metric. The two that could be used here are node/memory/total_bytes and node/memory/allocatable_bytes (the latter would probably make this operation equivalent to node/memory/allocatable_utilization). Then you can follow the ratio examples for MQL [1].
        Igor

Igor Peshansky

unread,
Nov 2, 2020, 9:46:38 AM11/2/20
to Vikram Saggu, Google Stackdriver Discussion Forum
Adding back +Google Stackdriver Discussion Forum.

Hi, Vikram. Let's keep these discussions on the list, so they can help others as well.

cast_units() simply forces the unit to be whatever you tell it. As I said earlier, you'd also need to scale your values. Fortunately, the scale() function does exactly that, and understands units (as described in [1]). So, to get your query to work as you wanted, you'll need to append "| scale('%')" at the end. When I do that on my clusters, I see the resulting values in percent.

Also note that you can aggregate finer-grained resources, so, for example, if you start with container-level metrics, you could aggregate away container and pod (and namespace) information to get cluster-level data, or group by metadata.system_labels.node_name to get per-node data.

Hope this helps.
        Igor



On Mon, Nov 2, 2020 at 2:59 AM Vikram Saggu <vsa...@gmail.com> wrote:
Hi Igor, 

We have deployed our application on K8s and wanted to know the CPU and Memory utilization when traffic is sent. 

So ideally would need the utilization of K8s cluster level, node level, pod and container level in % to know the capacity of usage.

I tried adding cast_unit on utilization metric but failed. I tried on different locations but no success. Below is what i am trying to do for ALLOCATABLE and REQUEST utiization

| filter (resource.cluster_name == 'dp-api-bld-01-kcl-01-euwe2')
| group_by 1m,
    [value_allocatable_utilization_mean: mean(value.allocatable_utilization)]
| every 1m
| group_by [resource.node_name],
    [value_allocatable_utilization_mean_aggregate:
       aggregate(value_allocatable_utilization_mean)]


--
Regards,
Vikram Saggu

Vikram Saggu

unread,
Nov 4, 2020, 2:03:27 AM11/4/20
to Igor Peshansky, Google Stackdriver Discussion Forum
Thats awesome Igor. Thank you very much.

It worked on the Chart and started displaying values in percentage. 

fetch k8s_node
| filter (resource.cluster_name == 'dp-api-bld-01-kcl-01-euwe2')
| group_by 1m,
    [value_allocatable_utilization_mean: mean(value.allocatable_utilization)]
| every 1m
| group_by [resource.node_name],
    [value_allocatable_utilization_mean_aggregate:
       aggregate(value_allocatable_utilization_mean)]
| value
    [value_allocatable_utilization_mean_aggregate_scale:
       scale(value_allocatable_utilization_mean_aggregate, '%')]
--
Regards,
Vikram Saggu
Reply all
Reply to author
Forward
0 new messages