对具有不同结果的两个聚合求和并保留所有

Sum two aggregations with different results and keep all

我想创建一个包含所有服务器的列表并按团队汇总它们。如果我使用单个指标执行此操作,这很容易:

对于Linux:count(node_uname_info) by (team)
并且 Windows:count(wmi_os_info) by (team)

但现在我想将这两个查询聚合为一个,因为我想按团队计算服务器总数。

通常我会这样做:
count(node_uname_info) by (team) + count(wmi_os_info) by (team)

但现在我只得到同时拥有 Linux 和 Windows 服务器的团队。
有没有办法假设一个值不存在则为零?

我尝试过的查询:

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)

谢谢!

如有关 binary operators 的文档中所述,不匹配的元素不是结果的一部分:

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.

但您可以使用 __name__ 内部标签(参见 selectors)select 多个指标,并将 count 应用于结果向量:

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