Data processing from graph's output

Hello, I am using Grafana v10.0.3 and I am trying to extract data from a blob of text from a Loki datasource. I want to process the data to generate a graph.

The problem with this blob of text is that it contains inconsistent data and the output I extract from it has a few random commas:

3, 2, 1, 1, 1, 1,1
103, 99, 197, 308 95 123, 120
83, 30 140, 225, 14, 38, 8
231 248, 327 41, 233, 231 131

What I’d like to do with this is some calculation and generate a graph as such, considering that the output it a table:

Sum of (Line 1 * line 2)
Sum of (Line 1 * line 3)
Sum of (Line 1 * line 4)

Then, return the name of the line with the lowest value: line 2, line 3 or line 4.

For example, from the output above, it would be:

Line_1 = 3 * 103 + 2 * 99 + 1 * 197 + 1 * 308 + 1 * 95 + 1 * 123 + 1 * 120 = 1350
Line_2 = 3 * 83 + 2 * 30 + 1 * 140 + 1 * 225 + 1 * 14 + 1 * 38 + 1 * 8 = 734
Line_3 = 3 * 231 + 2 * 248 + 1 * 327 + 1 * 41 + 1 * 233 + 1 * 231 + 1 * 131 = 2152

So the result for this output would be Line_2, since it is the lowest of the 3.
That’s what I’d like to create a graph for, displaying the lowest of those 3 lines for each of those blobs that Loki catches.

What I am struggling with are those annoying commas that I would like to remove in order to obtain a clean set of numbers that I think would be more handy to process.
If anyone knows how to get rid of those commas, I think that would put me on the right path to then be able to create the graph that I want, processing those values as numbers.

I am not sure if this is relevant, but here is a bit more context:
Here is a sample of the blob of text and the queries I am using to extract them

  "Message": "Fetch Data -> { \"data\": { \"dataId\": \"2024-03-22T12:02:06.105239\", \"dataProfile\": \"test.Default.61537\", \"dataFunction\": \"basic\", \"tickets\": [ { \"id\": \"test\", \"searchFields\": { \"doubleArgs\": { \"Ping_test.na.myapplication.com:500\": 80, \"Ping_test.eu.myapplication.com:500\": 156, \"Ping_test.hk.myapplication.com:500\": 199, \"NumOfUsers\": 2 }, \"stringArgs\": { \"applicationmode\": \"mode.normal\", \"userdataType\": \"Default\", \"Banner\": \"Random\", \"RatingGroup\": \"unranked\", \"BuildId\": \"test\" }, \"tags\": [ \"test\", \"modeofplay\", \"typeofplay\" ] }, \"extensions\": { \"user1_PlatformId\": { \"@type\": \"test\", \"@value\": \"test==\" }, \"user0_Platform\": { \"@type\": \"test\", \"@value\": \"test==\" }, \"user1_Minions\": { \"@type\": \"test\", \"@value\": \"test==\" }, \"user1_SkillMean\": { \"@type\": \"test\", \"@value\": \"test\" }, \"CreationTime\": { \"@type\": \"test\", \"@value\": \"test\" }, \"EncryptionBypass\": { \"@type\": \"test\", \"@value\": \"test==\" }, \"SkillMean\": { \"@type\": \"test\", \"@value\": \"test\" }, \"user0_DisplayName\": { \"@type\": \"test\", \"@value\": \"test=\" }, \"IsRanked\": { \"@type\": \"test\", \"@value\": \"\" }, \"user0_SkillMean\": { \"@type\": \"test\", \"@value\": \"test\" }, \"user0_Username\": { \"@type\":
.
.
\"MapName\": { \"@type\": \"test\", \"@value\": \"\" } }, \"createTime\": \"2024-06-28T19:02:08.967383458Z\" }, { \"id\": \"test\", \"searchFields\": { \"doubleArgs\": { \"Ping_test.na.myapplication.com:500\": 148, \"Ping_test.eu.myapplication.com:500\": 217, \"Ping_test.hk.myapplication.com:500\": 326, \"NumOfUsers\": 1 }, \"stringArgs\": { \"applicationmode\": 

I am trying to collect these values, generating a label for each occurence, with a maximum of 10 occurrences for each of them:

"NumOfUsers":
"Ping_test.eu.myapplication.com:500":
"Ping_test.hk.myapplication.com:500":
"Ping_test.na.myapplication.com:500":

Here are 2 of the queries I have:

{namespace=“my-namespace”} |~ Fetch Data | pattern <_>dataId<_>NumOfUsers<_> <NumUsers_1> <_>NumOfUsers<_> <NumUsers_2> <_>NumOfUsers<_> <NumUsers_3> <_>NumOfUsers<_> <NumUsers_4> <_>NumOfUsers<_> <NumUsers_5> <_>NumOfUsers<_> <NumUsers_6> <_>NumOfUsers<_> <NumUsers_7> <_>NumOfUsers<_> <NumUsers_8> <_>NumOfUsers<_> <NumUsers_9> <_>NumOfUsers<_> <NumUsers_10> <_> | line_format {{.NumUsers_1}} {{.NumUsers_2}} {{.NumUsers_3}} {{.NumUsers_4}} {{.NumUsers_5}} {{.NumUsers_6}} {{.NumUsers_7}} {{.NumUsers_8}} {{.NumUsers_9}} {{.NumUsers_10}}

{namespace=“my-namespace”} |~ Fetch Data | pattern <_>dataId<_><_>Ping_test.eu.myapplication.com:500<_> <eu1> <_>Ping_test.eu.myapplication.com:500<_> <eu2> <_>Ping_test.eu.myapplication.com:500<_> <eu3> <_>Ping_test.eu.myapplication.com:500<_> <eu4> <_>Ping_test.eu.myapplication.com:500<_> <eu5> <_>Ping_test.eu.myapplication.com:500<_> <eu6> <_>Ping_test.eu.myapplication.com:500<_> <eu7> <_>Ping_test.eu.myapplication.com:500<_> <eu8> <_>Ping_test.eu.myapplication.com:500<_> <eu9> <_>Ping_test.eu.myapplication.com:500<_> <eu10> <_> | line_format {{.eu1}} {{.eu2}} {{.eu3}} {{.eu4}} {{.eu5}} {{.eu6}} {{.eu7}} {{.eu8}} {{.eu9}} {{.eu10}}

That is how I end up with the output provided earlier, that I can’t process the way I want.

I am not sure if I should try to strip those commas when I am running the queries to extract the output, or if it is better to deal with those in the data processing graph that I am trying to create.

In any case, I would appreciate any guidance to help me with this problem.

1 Like