I think you need to describe:
* what you actually see
* what you would like to see instead
* the results of each of the subexpressions (i.e. left and right of "or") 
in the PromQL browser

Then it should be clearer how to combine them to achieve the result you 
want.

For more info on how the "or" operator works, 
see: 
https://prometheus.io/docs/prometheus/latest/querying/operators/#logical-set-binary-operators

The most important thing to note is that it's not a boolean: it's a union.  
An expression like "a or b" has a vector of values for "a" and a vector of 
values for "b". The result combines both timeseries a and b into the result 
set.  However, if there are any metrics from "a" and "b" which match 
*exactly* the same set of label values, then only the "a" one will be 
included in the result set.

You can restrict the set of labels used for matching using "on(labels...)" 
or "ignoring(labels...)"

In your example: the subexpressions "sum by (nodename) (...)" will only 
have a single label {nodename="XXX"}, whilst the subexpression 
"machine_cpu_cores" very likely has more labels than that (job, instance 
etc) and may not have a "nodename" label at all.  Since the labels of the 
LHS and RHS of "or" don't match, both sides are included in the result.

On Wednesday, 3 May 2023 at 15:19:09 UTC+1 Anuj Kumar wrote:

> HI All,
>
> I am using the below query but getting output for the two queries . I need 
> to get the output for each query. Any help would be appreciated.
>
> machine_cpu_cores or sum by(nodename) 
> (irate(node_cpu_seconds_total{mode="idle"}[5m]) * on(instance) 
> group_left(nodename) node_uname_info) or sum by(nodename) 
> (irate(node_cpu_seconds_total{mode!="idle"}[5m]) * on(instance) 
> group_left(nodename) node_uname_info)
>
> Thanks,
> Anuj Kumar
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/8c505178-b54f-45c1-b96d-3188bfb69f9fn%40googlegroups.com.

Reply via email to