'GKE metrics comparsion

Does anyone know how can I compare my query result to some value? For example, I have such query:

fetch k8s_container
| { metric 'kubernetes.io/container/cpu/core_usage_time'
| filter
    (metadata.user_labels.project =~ '.*')
| align rate(1m)
| every 1m
| group_by [resource.container_name],[value_core_usage_time_aggregate: aggregate(value.core_usage_time)];
metric 'kubernetes.io/container/cpu/limit_cores'
| filter
    (metadata.user_labels.project =~ '.*')
| group_by 1m, [value_limit_cores_mean: mean(value.limit_cores)]
| every 1m }
| outer_join 0
| div

And I want to get only those result that bigger than 0.5. How can I do it?

Using PromQL it's easy, like

some_metric/other_metric > 0.5

Or even boolean result

some_metric/other_metric > 0.5

This query returns 0 or 1.

But with GKE metrics it isn't easy at all



Solution 1:[1]

Finally, I resolve the issue with the next query

fetch k8s_node
| { 
    t_0:
    metric 'kubernetes.io/node/ephemeral_storage/used_bytes'
    | group_by 1m, [value_used_bytes_mean: mean(value.used_bytes)]
    | every 1m
    ; t_1:
    metric 'kubernetes.io/node/ephemeral_storage/total_bytes'
    | group_by 1m, [value_total_bytes_mean: mean(value.total_bytes)]
    | every 1m
}
| outer_join 0
| value val(0)/val(1)
| map rename[node : resource.node_name]

Solution 2:[2]

You're probably looking for something like the gt function.

It should be as simple as using gt(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 Sergey Petrov
Solution 2 kwiesmueller