Getting Data In

JSON element names contains dynamic part - how to create table

pszpor
New Member

My JSON log file contains metrics - below message example. Json elements name and number are not fixed. As you can see element meters.bytesInPerSec.APPLICATION_NAME can be repeated for all applications dynamically.

How should I configure props.conf and how should I write query to get following table:

application, m5_rate
my-application-name-a, 0
my-application-name-b, 0
my-application-name-c, 18.081537604791322
my-application-name-d, 0

If such question was already answered please point me to proper doc/answer.

Eg message:
{
"time": 1512637302765,
"meters": {
"bytesInPerSec.my-application-name-a": {
"count": 0,
"m1_rate": 0,
"m5_rate": 0,
"m15_rate": 0,
"mean_rate": 0,
"units": "bytes/SECONDS"
},
"bytesInPerSec.my-application-name-b": {
"count": 0,
"m1_rate": 0,
"m5_rate": 0,
"m15_rate": 0,
"mean_rate": 0,
"units": "bytes/SECONDS"
},
"bytesInPerSec.my-application-name-c": {
"count": 152503217,
"m1_rate": 16.733471413145928,
"m5_rate": 17.948078497437745,
"m15_rate": 18.081537604791322,
"mean_rate": 39.63002548338987,
"units": "bytes/SECONDS"
},
"bytesInPerSec.my-application-name-d": {
"count": 0,
"m1_rate": 0,
"m5_rate": 0,
"m15_rate": 0,
"mean_rate": 0,
"units": "bytes/SECONDS"
}
}
}

Tags (2)
0 Karma

harsmarvania57
Ultra Champion

Hi @pszpor,

You can achieve this via search query based on sample data you have provided please try below query (First 2 lines are used to generate dummay data)

| makeresults
| eval _raw="{ \"time\": 1512637302765, \"meters\": { \"bytesInPerSec.my-application-name-a\": { \"count\": 0, \"m1_rate\": 0, \"m5_rate\": 0, \"m15_rate\": 0, \"mean_rate\": 0, \"units\": \"bytes/SECONDS\" }, \"bytesInPerSec.my-application-name-b\": { \"count\": 0, \"m1_rate\": 0, \"m5_rate\": 0, \"m15_rate\": 0, \"mean_rate\": 0, \"units\": \"bytes/SECONDS\" }, \"bytesInPerSec.my-application-name-c\": { \"count\": 152503217, \"m1_rate\": 16.733471413145928, \"m5_rate\": 17.948078497437745, \"m15_rate\": 18.081537604791322, \"mean_rate\": 39.63002548338987, \"units\": \"bytes/SECONDS\" }, \"bytesInPerSec.my-application-name-d\": { \"count\": 0, \"m1_rate\": 0, \"m5_rate\": 0, \"m15_rate\": 0, \"mean_rate\": 0, \"units\": \"bytes/SECONDS\" } } }"
| spath
| rename meters.bytesInPerSec.my-application-name-*.m15_rate AS my-application-name-*
| table my-application-name*
| transpose column_name=application
| rename "row 1" AS m15_rate

I hope this helps.

Thanks,
Harshil

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...