1

I am trying to rewrite a query from InfluxDB Query to PromQL:

SELECT non_negative_derivative("wait_time_ms", 1s) FROM "sqlserver_waitstats" WHERE ("sql_instance" =~ /^$InstanceName$/) AND ("wait_type" =~ /HADR/) AND $timeFilter GROUP BY "wait_type"

Would anyone be able to help?

Akash Masand
  • 1,441
  • 14
  • 30

1 Answers1

0

The corresponding PromQL query should look like the following:

rate(sqlserver_waitstats_wait_time_ms{sql_instance=~"$InstanceName", wait_type=~".*HADR.*"}[5m])

It is assumed that the following translation is performed when converting Influx lines to Prometheus metrics:

  • measurement name is prepended to every field name in order to get Prometheus-compatible metric name. For instance, if measurement is sqlserver_waitstats, while field name is wait_time_ms, then the resulting Prometheus metric name would be sqlserver_waitstats_wait_time_ms as shown in the query above.
  • All the tags are translated as is to Prometheus labels. For example, sql_instance=foobar tag from Influx line is translated to sql_instance="foobar" Prometheus label.

This is the default translation used by VictoriaMetrics when accepting Influx line protocol data - see these docs for details.

Notet that regular expressions in PromQL label matchers are bound to the beginning and the end of label value by default. So there is no need in setting ^ and $ in the regexp for sql_instance above, while we need to add .* to wait_type regexp, so it matches any value containing HADR instead of exact matching.

I'd suggest also reading PromQL tutorial for beginners in order to feel better the difference between PromQL and InfluxQL.

valyala
  • 11,669
  • 1
  • 59
  • 62