Customize generated label names in time series visualization

Using Grafana OSS 11.5.1 I have this Postgres query:

SELECT 
    b.date_booked AS "time",
    s."name" as service_name,
    COUNT(*) AS metric
FROM 
    bookings b
JOIN 
    services s ON b.service_id = s.id
WHERE 
    -- $__timeFilter(b.date_booked) and
    b.status != 'X'
GROUP BY 
    b.date_booked, s."name"
ORDER BY 
    b.date_booked, metric DESC;

Using Transformations → Prepare Time Series → Multi-frame time series I get almost the output I want, with one metric per service displayed in the graph. The labels however look like this:

total_bookings Escalade Summer

… and I cannot figure out how to strip the "total_bookings " prefix??

Rename fields by regex apparently only works on raw query fields, not on the fields generated by the Prepare time series transformation.
Field override → Display Name supports regex bu apparently not back references to capture groups.

What is the right way to go about this?

Thanks!

  • What Grafana version and what operating system are you using?
    OSS 11.5.1

  • What are you trying to achieve?
    Display multiple time series on the Time Series visualization, with dynamic labels coming from the DB

  • How are you trying to achieve it?
    Using Prepare Time Series transformation to create a multi-frame time series, then a Rename field by regex to rename the new fields

  • What happened?
    The transformation is not applied to generated fields.

  • What did you expect to happen?
    The regex transform being applied to the fields generated by the Prepare time series step.

Hi @franck102

Rename fiends by regex transformation like this should work:
Match: ^total_bookings\s(.+)
Replace: $1

In action…

Data with no transformation:

and after applying this:

1 Like

Indeed, I swear I tried the transformation and somehow it didn’t affect my labels.

Thanks!

I believe you. Regex is really finicky and just the slightest omission or extra space will render nothing. Glad you are off and running now.

another way of doing it. You have the metric and value swapped. then no need for transformation if you choose Time Series Format.

SELECT 
    date_booked AS "time",
    "name" as metric,
    COUNT(*) AS value
FROM bookings b
1 Like

My keyboard is set up as US international, and the caret is a weird non-ascii character waiting to change into an ê or î until I hit space… that’s what tripped me :frowning:

Thanks for this, lots of things coming together thanks to your post, I had been really struggling with time series & Postgres (no timescaledb) so far.
The documentation didn’t help much, the page that describes time series (here) only has examples with multiple values on the same row.

Franck