使用 PromQL 查询计算网络设备能源使用情况
我有一个在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据prometheus文档 查询函数 | Prometheus ,函数 sum_over_time(range-vector) 需要通过范围向量进行计算。请尝试
According to prometheus document Query Function | Prometheus , function sum_over_time(range-vector) need to calculate through range vector. please try
如果每 20 秒对时间序列值进行一次采样,则以下查询应返回能源消耗摘要,单位为 焦耳 过去 24 小时(请参阅查询中的
[24h]
):通过将结果除以
3600000
,可以将以焦耳为单位的能耗转换为 kWh:更新:使用 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):The energy consumption in Joules can be converted to kWh by dividing the result by
3600000
:Update: the
sum_over_time(m[d])*20
can be substituted withintegrate(m[d])
when using VictoriaMetrics. The integrate() function works with arbitrary interval between samples.