Search code examples
sumologic

SumoLogic — Plotting data from a "status" json message in the log


I have a service that accepts and processes tasks. A Task has a status: queued, running, failed, cancelled or finished. Once in a while the service spits out a log entry with the json, like this:

2021-09-09 00:30:46,742 [Timer-0] INFO - { "env": "test_environment", "capacity": 10, "available_ec2": 10, "failed_ec2": 0, "running_tasks": 0, "queued_tasks": 0, "finished_tasks": 0, "failed_tasks": 0, "cancelled_tasks": 3,"queue_wait_minutes" : { "max": 0, "mean": -318990, "max_started": 0, "mean_started": -29715 },"processing_time": {"max": 0, "mean": 0} }

I would like to plot a pie chart that would show the breakdown of the tasks by status ("running_tasks", "queued_tasks", "finished_tasks", "failed_tasks":, "cancelled_tasks" in the json message). So far I have failed to do so, because I cannot come up with how to construct a table out of such message. Any clues would be highly appreciated — thanks in advance!


Solution

  • Try something like this. Basically, you have to de-transpose the data. I hope this makes sense!

    ...
    | parse field=some_log_line "INFO - *" as jsonMessage
    | json field=jsonMessage "running_tasks"
    | json field=jsonMessage "queued_tasks"
    | json field=jsonMessage "finished_tasks"
    | "running_tasks,queued_tasks,finished_tasks," as message_keys
    | parse regex field=message_keys "(?<message_key>.*?)," multi
    | if (message_key="running_tasks", running_tasks, 0) as message_value
    | if (message_key="queued_tasks", queued_tasks, message_value) as message_value
    | if (message_key="finished_tasks", finished_tasks, message_value) as message_value
    | fields message_key, message_value
    | max(message_value) by message_key