The source of the query is a MySQL database, and the table is like :
Field | Type |
---|---|
id | int(11) |
time | timestamp |
share | varchar(200) |
user | varchar(50) |
size | float |
The source of the query is a MySQL database, and the table is like :
Field | Type |
---|---|
id | int(11) |
time | timestamp |
share | varchar(200) |
user | varchar(50) |
size | float |
The ultimate goal is to have a time series with one line per user, showing the evolution of the occupied size for a specific share (filtered by share like '%blah%'
), along with the delta between the latest result and the previous one.
I have the graph displaying all of that, but I don't know how to include the delta somewhere. I don't want to plot the delta in order to keep the graph clean.
Ideally, I would like to change the display name to include the delta concatenated to the user name, but I haven’t found how to do that.
I tried to concat inside the SQL query, but it creates 2 users for each user (one without the delta, and one with it).
For now, the SQL query is like :
SELECT
date(time) AS time,
user,
SUM(size) AS total_size,
SUM(size) - LAG(SUM(size)) OVER (PARTITION BY user ORDER BY date(time) ASC) AS delta
FROM user_storage.storage
WHERE size > 150 AND share LIKE '/home%'
GROUP BY user, date(time)
ORDER BY time ASC
which returns data like :
Time | delta user1 | delta user2 | total_size user1 | total_size user2 |
---|---|---|---|---|
2025-03-17 01:00:00 | 100 | 252 | 1589 | 2089 |
2025-03-24 01:00:00 | 0 | 100 | 1589 | 2189 |
Any suggestions are welcome.
Share Improve this question edited Mar 25 at 8:56 Dale K 27.5k15 gold badges58 silver badges83 bronze badges asked Mar 24 at 21:54 DSXDSX 1516 bronze badges 8 | Show 3 more comments1 Answer
Reset to default 1Time Series seems to be stuck in the need for such a feature for at least 2022,
as proven by multiple discussions even on SO.
Some of those lead to feature request 73989 where 2 workarounds are cited:
- the vxiaobai-timeseries-panel plugin
- converting your timeline to numbers to be able to use an XY Chart instead of Time Series
Failed attempts
Exploration opened some pathways:
- an alternate solution in the conversation leading to the feature request uses JSON, but in the serie name instead of in its value;
thus it will generate one serie per value of delta, unless you restrain yourself to grouping on the last delta value for the user. Not that useful. - I tried outputting values as a JSON, then using the Extract Transformation to get only the
total_size
pushed to the graph; however what gets in the tooltip is what the graph received, not the original value - It seems that Value mappings are able to split Value from Text (the Value gets to the graph, the Text to the tooltip), thus we could theorically map
{"total_size":2189,"delta":100}
to a value of 2189 with a tooltip value of"2189 (+100)"
;
however:- a Value mapping by Value would force to define 1 mapping per (JSON) value, thus approximately 1 mapping per date per user,
so performance would be disastrous (and we don't want to define thousands of mappings, do we?) - a Value mapping by Regex only works on text fields (see multiple discussions), but gets applied after Transformations (particularly the one that could extract our
total_size
from the JSON… after we've removed thedelta
we want to display) - Dynamic Value Mapping, by adding a "Config from query results" Transformation before the Partition by values and Extract fields Transformations, seems to 1. not allow regex mapping, and 2. be ignored (be it by matching the full JSON with
select '{"size":1589}' Value, 'hey!' Text;
, or just'1589'
or1589
)
- a Value mapping by Value would force to define 1 mapping per (JSON) value, thus approximately 1 mapping per date per user,
total_size
), and you would like to have each plot additionally tagged with its delta, as a tooltip instead of as a separate graph line? – Guillaume Outters Commented Mar 25 at 7:51total_size
.delta
(see this fiddle), as the delta compared tototal_size
would then not be significant enough to disrupt the graph (less than 1 % of error induced, in the worst case of going from 51 to 150 which would be passed as150.99
instead of150
), but would Grafana interpret that number-looking string as a float? If not, the cast tofloat
done in SQL would remove trailing 0s (2189.100
rendered as2189.1
). – Guillaume Outters Commented Mar 25 at 8:12