2019-11-11 18:30:46 -08:00
|
|
|
# jc.parsers.ps
|
|
|
|
jc - JSON CLI output utility ps Parser
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
specify --ps as the first argument if the piped input is coming from ps
|
|
|
|
|
|
|
|
ps options supported:
|
|
|
|
- ef
|
|
|
|
- axu
|
|
|
|
|
2019-12-12 09:35:42 -08:00
|
|
|
Compatibility:
|
|
|
|
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
|
|
|
|
2019-11-11 18:30:46 -08:00
|
|
|
Examples:
|
|
|
|
|
|
|
|
$ ps -ef | jc --ps -p
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"uid": "root",
|
|
|
|
"pid": 1,
|
|
|
|
"ppid": 0,
|
|
|
|
"c": 0,
|
|
|
|
"stime": "Nov01",
|
|
|
|
"tty": null,
|
|
|
|
"time": "00:00:11",
|
|
|
|
"cmd": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uid": "root",
|
|
|
|
"pid": 2,
|
|
|
|
"ppid": 0,
|
|
|
|
"c": 0,
|
|
|
|
"stime": "Nov01",
|
|
|
|
"tty": null,
|
|
|
|
"time": "00:00:00",
|
|
|
|
"cmd": "[kthreadd]"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uid": "root",
|
|
|
|
"pid": 4,
|
|
|
|
"ppid": 2,
|
|
|
|
"c": 0,
|
|
|
|
"stime": "Nov01",
|
|
|
|
"tty": null,
|
|
|
|
"time": "00:00:00",
|
|
|
|
"cmd": "[kworker/0:0H]"
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
|
|
|
|
$ ps -ef | jc --ps -p -r
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"uid": "root",
|
|
|
|
"pid": "1",
|
|
|
|
"ppid": "0",
|
|
|
|
"c": "0",
|
|
|
|
"stime": "Nov01",
|
|
|
|
"tty": "?",
|
|
|
|
"time": "00:00:11",
|
|
|
|
"cmd": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uid": "root",
|
|
|
|
"pid": "2",
|
|
|
|
"ppid": "0",
|
|
|
|
"c": "0",
|
|
|
|
"stime": "Nov01",
|
|
|
|
"tty": "?",
|
|
|
|
"time": "00:00:00",
|
|
|
|
"cmd": "[kthreadd]"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uid": "root",
|
|
|
|
"pid": "4",
|
|
|
|
"ppid": "2",
|
|
|
|
"c": "0",
|
|
|
|
"stime": "Nov01",
|
|
|
|
"tty": "?",
|
|
|
|
"time": "00:00:00",
|
|
|
|
"cmd": "[kworker/0:0H]"
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
|
|
|
|
$ ps axu | jc --ps -p
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"user": "root",
|
|
|
|
"pid": 1,
|
2019-11-12 15:05:21 -08:00
|
|
|
"cpu_percent": 0.0,
|
|
|
|
"mem_percent": 0.1,
|
|
|
|
"vsz": 128072,
|
|
|
|
"rss": 6784,
|
2019-11-11 18:30:46 -08:00
|
|
|
"tty": null,
|
|
|
|
"stat": "Ss",
|
|
|
|
"start": "Nov09",
|
2019-11-12 15:05:21 -08:00
|
|
|
"time": "0:08",
|
2019-11-11 18:30:46 -08:00
|
|
|
"command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"user": "root",
|
|
|
|
"pid": 2,
|
2019-11-12 15:05:21 -08:00
|
|
|
"cpu_percent": 0.0,
|
|
|
|
"mem_percent": 0.0,
|
|
|
|
"vsz": 0,
|
|
|
|
"rss": 0,
|
2019-11-11 18:30:46 -08:00
|
|
|
"tty": null,
|
|
|
|
"stat": "S",
|
|
|
|
"start": "Nov09",
|
|
|
|
"time": "0:00",
|
|
|
|
"command": "[kthreadd]"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"user": "root",
|
|
|
|
"pid": 4,
|
2019-11-12 15:05:21 -08:00
|
|
|
"cpu_percent": 0.0,
|
|
|
|
"mem_percent": 0.0,
|
|
|
|
"vsz": 0,
|
|
|
|
"rss": 0,
|
2019-11-11 18:30:46 -08:00
|
|
|
"tty": null,
|
|
|
|
"stat": "S<",
|
|
|
|
"start": "Nov09",
|
|
|
|
"time": "0:00",
|
|
|
|
"command": "[kworker/0:0H]"
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
|
|
|
|
$ ps axu | jc --ps -p -r
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"user": "root",
|
|
|
|
"pid": "1",
|
|
|
|
"cpu_percent": "0.0",
|
|
|
|
"mem_percent": "0.1",
|
|
|
|
"vsz": "128072",
|
2019-11-12 15:05:21 -08:00
|
|
|
"rss": "6784",
|
2019-11-11 18:30:46 -08:00
|
|
|
"tty": "?",
|
|
|
|
"stat": "Ss",
|
|
|
|
"start": "Nov09",
|
2019-11-12 15:05:21 -08:00
|
|
|
"time": "0:08",
|
2019-11-11 18:30:46 -08:00
|
|
|
"command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"user": "root",
|
|
|
|
"pid": "2",
|
|
|
|
"cpu_percent": "0.0",
|
|
|
|
"mem_percent": "0.0",
|
|
|
|
"vsz": "0",
|
|
|
|
"rss": "0",
|
|
|
|
"tty": "?",
|
|
|
|
"stat": "S",
|
|
|
|
"start": "Nov09",
|
|
|
|
"time": "0:00",
|
|
|
|
"command": "[kthreadd]"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"user": "root",
|
|
|
|
"pid": "4",
|
|
|
|
"cpu_percent": "0.0",
|
|
|
|
"mem_percent": "0.0",
|
|
|
|
"vsz": "0",
|
|
|
|
"rss": "0",
|
|
|
|
"tty": "?",
|
|
|
|
"stat": "S<",
|
|
|
|
"start": "Nov09",
|
|
|
|
"time": "0:00",
|
|
|
|
"command": "[kworker/0:0H]"
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
|
|
|
|
## process
|
|
|
|
```python
|
|
|
|
process(proc_data)
|
|
|
|
```
|
|
|
|
|
2019-11-12 11:28:10 -08:00
|
|
|
Final processing to conform to the schema.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
2019-11-13 08:04:40 -08:00
|
|
|
proc_data: (dictionary) raw structured data to process
|
2019-11-12 11:28:10 -08:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
dictionary structured data with the following schema:
|
2019-11-11 18:30:46 -08:00
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"uid": string,
|
|
|
|
"pid": integer,
|
|
|
|
"ppid": integer,
|
|
|
|
"c": integer,
|
|
|
|
"stime": string,
|
|
|
|
"tty": string, # ? = Null
|
|
|
|
"time": string,
|
|
|
|
"cmd": string,
|
|
|
|
"user": string,
|
|
|
|
"cpu_percent": float,
|
|
|
|
"mem_percent": float,
|
|
|
|
"vsz": integer,
|
|
|
|
"rss": integer,
|
|
|
|
"stat": string,
|
|
|
|
"start": string,
|
|
|
|
"command": string
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
## parse
|
|
|
|
```python
|
|
|
|
parse(data, raw=False, quiet=False)
|
|
|
|
```
|
|
|
|
|
2019-11-12 11:18:00 -08:00
|
|
|
Main text parsing function
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2019-11-12 11:18:00 -08:00
|
|
|
Parameters:
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2019-11-12 11:18:00 -08:00
|
|
|
data: (string) text data to parse
|
|
|
|
raw: (boolean) output preprocessed JSON if True
|
|
|
|
quiet: (boolean) suppress warning messages if True
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
dictionary raw or processed structured data
|
2019-11-11 18:30:46 -08:00
|
|
|
|