将两个或更多列的Prometheus指标投影到一个字段中,并在值之间添加字符。

huangapple go评论48阅读模式
英文:

Project two or more columns with Prometheus metrics into one field and add characters between the values

问题

  • mssql_server_uptime_days - >=0
  • mssql_server_uptime_hours - >=0 <24
  • mssql_server_uptime_minutes - >=0 <60

我有3个由sql_exporter生成的指标,显示相应的SQL实例运行时间部分。

我希望在Grafana中显示实例的总运行时间。最好的格式是 dd hh:mm

我尝试过使用"Concatenate fields" 转换来将它们连接在一起,但没有成功。

是否可以使用Prometheus作为数据源来完成这个任务?

附注:我知道可以查询数据库管理系统以轻松获取此结果。但我希望保持仪表板的单一数据源:Prometheus。

英文:

I have 3 metrics generated by sql_exporter that are showing corresponding SQL instance uptime part:

  • mssql_server_uptime_days - >=0
  • mssql_server_uptime_hours - >=0 <24
  • mssql_server_uptime_minutes - >=0 <60

I'd like to show total uptime of instance in Grafana. Preferably in format dd hh:mm.

I tried to concatenate them with the transformation Concatenate fields with no success.

Could it be done using Prometheus as data source?

P.S. I now that I can query DBMS to get this result easily. But I'd like not to, to keep single data source for this dashboard: Prometheus.

答案1

得分: 2

你可以将你的度量单位转换为秒:

mssql_server_uptime_days * 24 * 60 * 60 +
mssql_server_uptime_hours * 60 * 60 +
mssql_server_uptime_minutes * 60

并将列的单位设置为时间(标准选项 > 单位),使用 duration (d hh:mm:ss)

英文:

You can convert you metrics into value in seconds:

mssql_server_uptime_days * 24 * 60 * 60 +
 mssql_server_uptime_hours * 60 * 60 +
  mssql_server_uptime_minutes * 60 

And set units of column (Standard options > Unit) to Time > duration (d hh:mm:ss)

huangapple
  • 本文由 发表于 2023年3月31日 19:00:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75897774.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定