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?
Image:
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:
I have two queries, here’s the write a read is similar:
SELECT
time_bucket('$resolution', time) AS "time",
(
CASE
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
END
) * 8 / extract(epoch from time - lag(time) OVER w) AS "Bits written",
name
FROM diskio join diskio_tag on diskio.tag_id = diskio_tag.tag_id
WHERE
$__timeFilter("time")
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)
ORDER BY 1
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.
No, but I don’t recall the exact wild card I tried to use (other than what I wrote in my original description) nor why it simplifies this - I think it meant I could get the sums via one transform.
I’m still wild carding on a “Filter by name” in the four different panels (write sums, writes, read sums and reads).
Commenting here since this is the first search result for “Grafana Add field from calculation regex”.
I had a slightly different use case, transforming a series of logs into a state timeline. I have a series of Extract Fields transformations to match certain patterns to states I want to visualize.
“started processing” would be extracted to “event_start”: “started processing”
“finished processing” would be extracted to “event_finished”: “finished processing”
Now, I wanted to use “Reduce row” without explicitly listing all the fields that should have been matched. I was able to use that transformation with different fields by adding a transform step
Type “Rename fields by regex”
With option Match set to “(event_.*)”
With option Replace set to “matched”
Using this configuration, I was able to feed that into “Add field from calculation”.