Answer the question
In order to leave comments, you need to log in
What is the correct way to convert bash output to JSON with {#PROCNAME} key?
I'm trying to get JSON from the top 5 processes from memory.
I want to send this JSON to Zabbix and draw the top 5 processes from memory.
I get the top 5 processes by memory with the command:
ps axho comm --sort -rss | head -5
node
mongod
kubelet
dockerd
systemd-journal
{
"data": [
{
"{#PROCNAME}": "node"
},
{
"{#PROCNAME}": "mongod"
},
{
"{#PROCNAME}": "kubelet"
},
{
"{#PROCNAME}": "dockerd"
},
{
"{#PROCNAME}": "systemd-journal"
}
]
}
Answer the question
In order to leave comments, you need to log in
ps axho comm --sort -rss | head -5 | jq -Rn '{data: [inputs|{"{#PROCNAME}":.}]}'
{
"data": [
{
"{#PROCNAME}": "node"
},
{
"{#PROCNAME}": "mongod"
},
{
"{#PROCNAME}": "kubelet"
},
{
"{#PROCNAME}": "dockerd"
},
{
"{#PROCNAME}": "systemd-journal"
}
]
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question