Search code examples
prometheusgrafanapromql

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


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.


Solution

  • 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)