Sample Header Ad - 728x90

How convert the output of "ps" and "head" to JSON with key "{#PROCNAME}"?

2 votes
3 answers
1833 views
I'm trying to get a JSON document with the top 5 processes by memory. This JSON I want to send to Zabbix and draw the top 5 processes by memory. I get the top 5 processes by memory by the following command: ps axho comm --sort -rss | head -5 node mongod kubelet dockerd systemd-journal How to convert the output of ps+head to JSON with key {#PROCNAME} to get this structure:
{
  "data": [
    {
      "{#PROCNAME}": "node"
    },
    {
      "{#PROCNAME}": "mongod"
    },
    {
      "{#PROCNAME}": "kubelet"
    },
    {
      "{#PROCNAME}": "dockerd"
    },
    {
      "{#PROCNAME}": "systemd-journal"
    }
  ]
}
https://www.zabbix.com/documentation/current/manual/config/macros/lld_macros There is a type of macro used within the low-level discovery (LLD) function: {#MACRO}
Asked by Anton Patsev (145 rep)
Feb 26, 2019, 12:52 PM
Last activity: Jun 17, 2022, 07:25 PM