Sorry, ignore that. You want one if it's present, *or* the other.

On Wednesday, 3 May 2023 at 18:16:01 UTC+1 Brian Candler wrote:

> Another approach is to turn it around using the "unless" operator. This 
> will *only* give timeseries from the vector on the LHS, and will suppress 
> any which have matching label sets on the RHS.
>
> sum by (nodename) (....) unless on (nodename) machine_cpu_cores
>
> [assuming that machine_cpu_cores has a "nodename" label]
>
> On Wednesday, 3 May 2023 at 17:18:37 UTC+1 Brian Candler wrote:
>
>> 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 prometheus-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/5dd1ed7a-3f77-4df9-bd48-151937d5ecb6n%40googlegroups.com.

Reply via email to