使用 PromQL 查询计算网络设备能源使用情况

发布于 2025-01-14 04:31:35 字数 1729 浏览 2 评论 0原文

我有一个在 Grafana 上运行的电源 PromQL 查询,如下所示:

sum(rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"})/1000

该查询从具有 IP 地址的所有设备生成功耗图(以千瓦为单位):

192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108

根据上面的内容,我希望有另一个图来查看这些相同设备的能耗(千瓦时) IP 地址。

我生成了以下查询:

sum(rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"})/1000)*0.005555556

其中值采样时间为 20 秒 (1/180=0.005555556) 它每 20 秒显示一次能源使用情况。

现在我应该将所有值加在一起以接收当前的能源使用情况(使用 sum_over_time 函数):

sum_over_time(sum(rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"})/1000)*0.005555556

但是发生错误:

Error executing query: parse error at char 213: expected type range vector in call to function "sum_over_time", got instant vector

我还在下面添加了一个时间范围:

sum_over_time(sum(rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"})/1000)*0.005555556[24h]

发生另一个错误:

Error executing query: parse error at char 211: range specification must be preceded by a metric selector, but follows a *promql.NumberLiteral instead

有什么建议吗?

非常感谢。

I've got a power PromQL query working on Grafana below:

sum(rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"})/1000

This query generates power consumption graph (in kW) from all devices with ip addresses:

192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108

According above I would like to have another graph to see an energy consumption (kWh) for these same ip addresses.

I produced a query below:

sum(rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"})/1000)*0.005555556

where value sample time is 20 seconds (1/180=0.005555556)
And it displays energy usage for every 20s.

Now I should add all values together to receive current energy usage (using sum_over_time function):

sum_over_time(sum(rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"})/1000)*0.005555556

But error occurs:

Error executing query: parse error at char 213: expected type range vector in call to function "sum_over_time", got instant vector

I also added a time frame below:

sum_over_time(sum(rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"})/1000)*0.005555556[24h]

Another error occurs:

Error executing query: parse error at char 211: range specification must be preceded by a metric selector, but follows a *promql.NumberLiteral instead

Any suggestions?

Many thanks.

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

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

发布评论

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

评论(2

故事灯 2025-01-21 04:31:35

根据prometheus文档 查询函数 | Prometheus ,函数 sum_over_time(range-vector) 需要通过范围向量进行计算。请尝试

sum_over_time(
    rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"}[24h]
)/1000)*0.005555556

According to prometheus document Query Function | Prometheus , function sum_over_time(range-vector) need to calculate through range vector. please try

sum_over_time(
    rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"}[24h]
)/1000)*0.005555556

只是一片海 2025-01-21 04:31:35

如果每 20 秒对时间序列值进行一次采样,则以下查询应返回能源消耗摘要,单位为 焦耳 过去 24 小时(请参阅查询中的 [24h]):

sum(sum_over_time(
rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"}[24h]))*20

通过将结果除以 3600000,可以将以焦耳为单位的能耗转换为 kWh:

sum(sum_over_time(
rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"}[24h]))*20/3600000

更新:使用 VictoriaMetrics 时,sum_over_time(m[d])*20 可以替换为 integrate(m[d])integrate() 函数适用于样本之间的任意间隔。

If time series values are sampled every 20 seconds, then the following query should return summary energy consumption in Joules for the last 24 hours (see [24h] in the query):

sum(sum_over_time(
rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"}[24h]))*20

The energy consumption in Joules can be converted to kWh by dividing the result by 3600000:

sum(sum_over_time(
rPDUIdentDevicePowerWatts{instance=~"192.168.1.101|192.168.1.102|192.168.1.103|192.168.1.104|192.168.1.105|192.168.1.106|192.168.1.107|192.168.1.108", job="snmp",mib="apcups"}[24h]))*20/3600000

Update: the sum_over_time(m[d])*20 can be substituted with integrate(m[d]) when using VictoriaMetrics. The integrate() function works with arbitrary interval between samples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文