Getting Data In

how to sum the machine OS in a JSON file

garumaru
Explorer

Hi Guys,

I have a JSON file for OS type in some cluster like below:

{
"clusterA": ubuntu,
"clusterA": ubuntu,
"clusterA": rhel5,
"clusterA": sles11,
"clusterB": sles11,
"clusterB": sles11,
"clusterB": ubuntu,
"clusterC": centos,
"clusterC": ubuntu
...
}

I'd like sum the OS type for each cluster, like in above sample, 2 ubuntu in clusterA, 1 rhel5 in clusterA etc.
Would you please kindly help out?

Thank you!

0 Karma

vnravikumar
Champion

Hi

Check this

| makeresults 
| eval json="{\"clusterA\": ubuntu,
 \"clusterA\": ubuntu,
 \"clusterA\": rhel5,
 \"clusterA\": sles11,
 \"clusterB\": sles11,
 \"clusterB\": sles11,
 \"clusterB\": ubuntu,
 \"clusterC\": centos,
 \"clusterC\": ubuntu}" 
| eval json=replace(json,"\"|{|\s|}","") 
| makemv delim="," json 
| mvexpand json 
| eval temp=split(json,":"),cluster=mvindex(temp,0),os=mvindex(temp,1) 
| stats count by cluster,os
0 Karma

to4kawa
Ultra Champion
| makeresults 
| eval _raw="{\"clusterA\": ubuntu,
\"clusterA\": ubuntu,
\"clusterA\": rhel5,
\"clusterA\": sles11,
\"clusterB\": sles11,
\"clusterB\": sles11,
\"clusterB\": ubuntu,
\"clusterC\": centos,
\"clusterC\": ubuntu}"
| rex mode=sed "s/: (\w+)/: \"\1\"/g"
| spath
| foreach cluster* [ eval <<FIELD>> = mvjoin('<<FIELD>>' , ",")]
| untable _time cluster OS
| eval OS = split(OS,",")
| mvexpand OS
| stats count by OS cluster
| sort cluster
0 Karma
Did you miss .conf21 Virtual?

Good news! The event's keynotes and many of its breakout sessions are now available online, and still totally FREE!