What Grafana version and what operating system are you using?
Grafana v11.2.0 (c57667e448)
What are you trying to achieve?
Display logs in text format form MYSQL database
How are you trying to achieve it?
Using Table or Stat visualization
What happened?
Grafana Table/Stat visualization does not interpret \n as a new line
What did you expect to happen?
\n to be interpreted as new line
In MYSQL db, I am saving logs in the format shown below:
In Grafana, I want to be able to read the Log text and display it nicely. For example the Log data may contain:
'R3,198862.55 - 219795.45,215791 \r\n R4,11754.35 - 12991.65,12496 \r\n C20,0.001 - 0.002,0.001610\n
In Grafana query I do the following:
SELECT 'R3,198862.55 - 219795.45,215791 \r\n R4,11754.35 - 12991.65,12496 \r\n C20,0.001 - 0.002,0.001610\n' AS Log;
The following data is displayed:
I have also tried the same using Stat visualization:
As you can see from screenshots above, the Log is displayed in a single line even though I have \n\r to separate the text in separate lines.
How can I ensure that Grafana parses new line properly?
yosiasz
September 10, 2024, 1:18pm
2
What does the raw data look like in the Log column without the \r\n
and what standard is this log data in the Log column? I find your data and the design approach used very suspect.
It is a simple text. For example:
R3,198862.55-219795.45,216152
R4,11754.35-12991.6,12000.35
Regarding the standard, I believe it is UTF8 (is that what you are asking?)
long story short:
I have simple text format logs written to MYSQL DB and I want to be able to display them nicely in Grafana (including \n)
I do not understand how did you achieve this in Panel but I was not able to, I have found a workaround though.
Create a variable that queries the Text data from MYSQL
Create Text visualization
Since Text visualization cannot use the MYSQL query, thats why we use the variable that we created in step 1.
Text visualization displays the text with \n without any issues:
2 Likes
Just one more workaround but it works only in State Timeline visualization panels
Create a custom type variable with the multiline text including two strings that starts from the non-space symbol:
_
_
Use the variable created in step #1 as a separator in the legend like so:
{{alertname}}${newLine}{{severity}}${newLine}{{source}}
Profit, at least it works with the Prometheus and State Timeline panel, but for example it doesn’t work in the similar panel like Bar Chart with the horizontal orientation.
PS:
Instead of underscore, you can use a Unicode whispaces symbols like this one U+180E MONGOLIAN VOWEL SEPARATOR - Unicode Explorer