排序promql,以使所有带有一个lebel的指标在结果中首先出现
我想执行此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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用 sort_by_label victoriametrics的功能)以下面的方式:
它应按照他们的公制名称对返回的时间序列进行排序。
如果您需要使用具有标准的度量名称按其值对时间序列进行排序,请尝试以下 Metricsql 查询:
它使用附加函数 - sort - 用于按值排序时间序列,在按公制名称进行分类时间序列。
Try using sort_by_label function from VictoriaMetrics (I'm the author of this Prometheus-like system) in the following way:
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:
It uses an additional function - sort - for sorting time series by values, before sorting time series by metric names.
您可以使用操作员“或”加入PROMQLS,如下:
这将加入两个指标,首先列出“ CPU_USAGE_VALUE”元素,然后再加入“ Memory_usage_vale”元素。
但是...
如“或”运算符文档中所示:
将仅列出“ Memory_usage_value”度量标准的元素,该元素在“ CPU_USAGE_VALUE”一个中没有匹配的标签集。
为了解决此问题,请使用“ label_replace”函数,在“ memory_usage_value”度量标准中添加一个额外的标签,如下:
You can use the operator "or" to join the PromQLs, like the following:
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:
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: