简体   繁体   中英

Sum two aggregations with different results and keep all

I would like create a list of all servers and aggregate them by teams. If I do this with a single metric this is easy:

For Linux: count(node_uname_info) by (team)
And Windows: count(wmi_os_info) by (team)

But now I want to aggregate this two queries to one as I want to get count of total servers by team.

Normally I would do it like that:
count(node_uname_info) by (team) + count(wmi_os_info) by (team)

But now I get only the teams which own both Linux and Windows servers.
Is there a way to assume that a value is zero if it is not existent?

Queries I have tried:

count(node_uname_info) by (team) + count(wmi_os_info) by (team)
count(node_uname_info) by (team) + (count(wmi_os_info) by (team) > 0)
count(node_uname_info) by (team) + on(team) count(wmi_os_info) by (team)

Thanks!

As indicated in the documentation about binary operators , the elements that do not match are not part of the result:

Between two instant vectors, a binary arithmetic operator is applied to each entry in the left-hand side vector and its matching element in the right-hand vector[...] Entries for which no matching entry in the right-hand vector can be found are not part of the result.

But you can select multiple metrics using the __name__ internal label (see selectors ) and the apply the count on the resulting vector:

count({__name__=~"node_uname_info|wmi_os_info"}) by (team)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM