Grafana Stat and Table visualization does not parse \n as new line

  • 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?

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.

  1. Create a variable that queries the Text data from MYSQL
  2. Create Text visualization
  3. Since Text visualization cannot use the MYSQL query, thats why we use the variable that we created in step 1.
  4. Text visualization displays the text with \n without any issues:

1 Like