Can I use a regex in a transform for field name selection?

  • What Grafana version and what operating system are you using?
    Docker image for grafana v9.0.9

  • What are you trying to achieve?
    I’d like to show sums of linux block device write and read rates, and select the block devices by regular expression so adding additional storage does not require modifying the dashboard. And also try to use one query for multiple panels.

  • How are you trying to achieve it?
    I added a Transform, “Add field from calculation”, but the field name only allows selecting from existing fields. I tried manually modifying the json, but could not get that to work.

I also played with other transforms, but I’d like to have sums of reads and writes in one panel, along with each block device in another panel using one query.

  • Can you copy/paste the configuration(s) that you are having problems with?

Used with this json (not sure how to attach the full json text), where I tried using “pattern” in place of a list. I’ve tried various regexes here too but they all just match all field names:

      "id": "calculateField",
      "options": {
        "mode": "reduceRow",
        "reduce": {
          "reducer": "sum",
          "include": {
            "pattern": "Bits written sda"
        "alias": "Failed Regex Total Writes"

what is your data source?

Postgresql timescale.

I have two queries, here’s the write a read is similar:

  time_bucket('$resolution', time) AS "time",
      WHEN write_bytes >= lag(write_bytes) OVER w
        THEN write_bytes - lag(write_bytes) OVER w
      WHEN lag(write_bytes) OVER w IS NULL THEN NULL
      ELSE write_bytes
  ) * 8 / extract(epoch from time - lag(time) OVER w) AS "Bits written",
FROM diskio join diskio_tag on diskio.tag_id = diskio_tag.tag_id
  AND write_bytes > 0
  AND ( name ~ 'sd[a-z]+$' or name ~ 'nvme[a-z]+$' )
WINDOW w AS (partition by diskio.tag_id ORDER BY time)
1 Like

If anyone figures out a nice way to do this, or how to use regexs in a “Add field from calculations” let me know.

For now I went ahead and used 2 panels for this, using the same / shared write and read queries (via “Data source” Dashboard), and then added a transform to wildcard write or read values, and then another transform to sum the results. And then an override to hide the individual block device results.

And then added two other panels using the same query to show each block device - basically the sum panel without the sums, one for reads and one for writes, no overrides needed.

This visual:

And the read totals panel showing the transform with wild card: