排序promql,以使所有带有一个lebel的指标在结果中首先出现

发布于 2025-02-06 00:47:40 字数 187 浏览 2 评论 0原文

我想执行此promql即时查询,

{__name__=~"cpu_usage_value|memory_usage_value|request_rate"}

我希望结果以{__ name __ =“ cpu_usage_value”}以结果和排序顺序出现的所有指标。

I want to perform this promql Instant query

{__name__=~"cpu_usage_value|memory_usage_value|request_rate"}

I want the result in such a way that all metrics with {__name__="cpu_usage_value"} appear first in result and in sorted order.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

网名女生简单气质 2025-02-13 00:47:42

尝试使用 sort_by_label victoriametrics的功能)以下面的方式:

sort_by_label({__name__=~"foo|bar|baz"}, "__name__")

它应按照他们的公制名称对返回的时间序列进行排序。

如果您需要使用具有标准的度量名称按其值对时间序列进行排序,请尝试以下 Metricsql 查询:

sort_by_label(
  sort({__name__=~"foo|bar|baz"}),
  "__name__"
)

它使用附加函数 - sort - 用于按值排序时间序列,在按公制名称进行分类时间序列。

Try using sort_by_label function from VictoriaMetrics (I'm the author of this Prometheus-like system) in the following way:

sort_by_label({__name__=~"foo|bar|baz"}, "__name__")

It should sort the returned time series by their metric names.

If you need to sort time series with idenrical metric names by their value, then try the following MetricsQL query:

sort_by_label(
  sort({__name__=~"foo|bar|baz"}),
  "__name__"
)

It uses an additional function - sort - for sorting time series by values, before sorting time series by metric names.

花落人断肠 2025-02-13 00:47:42

您可以使用操作员“或”加入PROMQLS,如下:

{__name__=~"cpu_usage_value} or {__name__=~"memory_usage_value"}

这将加入两个指标,首先列出“ CPU_USAGE_VALUE”元素,然后再加入“ Memory_usage_vale”元素。

但是...

如“或”运算符文档中所示:

vector1或vector2导致包含所有原始的向量
vector1的元素(标签集 +值)及其所有
vector2的元素在vector1

中没有匹配标签集的元素

将仅列出“ Memory_usage_value”度量标准的元素,该元素在“ CPU_USAGE_VALUE”一个中没有匹配的标签集。

为了解决此问题,请使用“ label_replace”函数,在“ memory_usage_value”度量标准中添加一个额外的标签,如下:

{__name__=~"cpu_usage_value} or label_replace({__name__=~"memory_usage_value"}, "foo", "boo", "", "")

You can use the operator "or" to join the PromQLs, like the following:

{__name__=~"cpu_usage_value} or {__name__=~"memory_usage_value"}

This will join the two metrics listing the "cpu_usage_value" elements first and then the "memory_usage_vale" ones.

But...

As shown in the "or" operator documentation:

vector1 or vector2 results in a vector that contains all original
elements (label sets + values) of vector1 and additionally all
elements of vector2 which do not have matching label sets in vector1

Prometheus will list only the elements of the "memory_usage_value" metric which do not have matching label sets in the "cpu_usage_value" one.

To workaround this, add an extra label to the "memory_usage_value" metric, using the "label_replace" function, like the following:

{__name__=~"cpu_usage_value} or label_replace({__name__=~"memory_usage_value"}, "foo", "boo", "", "")
薄荷梦 2025-02-13 00:47:42
sort({__name__=~"foo.*|bar.*|baz.*"})
sort({__name__=~"foo.*|bar.*|baz.*"})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文