1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/docs/parsers/ps.md

240 lines
4.8 KiB
Markdown
Raw Normal View History

[Home](https://kellyjonbrazil.github.io/jc/)
2020-07-30 16:20:24 -07:00
2019-11-11 18:30:46 -08:00
# jc.parsers.ps
2020-08-05 16:51:58 -07:00
jc - JSON CLI output utility `ps` command output parser
`ps` options supported:
- `ef`
- `axu`
2019-11-11 18:30:46 -08:00
2020-08-05 13:32:59 -07:00
Usage (cli):
2019-12-12 09:47:14 -08:00
2020-08-05 16:51:58 -07:00
$ ps | jc --ps
or
2019-11-11 18:30:46 -08:00
2020-08-05 16:51:58 -07:00
$ jc ps
2019-11-11 18:30:46 -08:00
2020-08-05 13:32:59 -07:00
Usage (module):
2022-01-18 15:38:03 -08:00
import jc
result = jc.parse('ps', ps_command_output)
or
2020-08-05 13:32:59 -07:00
import jc.parsers.ps
result = jc.parsers.ps.parse(ps_command_output)
2021-04-08 15:52:49 -07:00
Schema:
[
{
"uid": string,
"pid": integer,
"ppid": integer,
"c": integer,
"stime": string,
"tty": string, # ? or ?? = Null
"tt": string, # ?? = Null
"time": string,
"cmd": string,
"user": string,
"cpu_percent": float,
"mem_percent": float,
"vsz": integer,
"rss": integer,
"stat": string,
"start": string,
"command": string
}
]
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",
2022-01-19 17:30:14 -08:00
"cmd": "/usr/lib/systemd/systemd --switched-root --system --dese..."
2019-11-11 18:30:46 -08:00
},
{
"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",
2022-01-19 17:30:14 -08:00
"cmd": "/usr/lib/systemd/systemd --switched-root --system --dese..."
2019-11-11 18:30:46 -08:00
},
{
"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",
2022-01-19 17:30:14 -08:00
"command": "/usr/lib/systemd/systemd --switched-root --system --..."
2019-11-11 18:30:46 -08:00
},
{
"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",
2022-01-19 17:30:14 -08:00
"command": "/usr/lib/systemd/systemd --switched-root --system --..."
2019-11-11 18:30:46 -08:00
},
{
"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]"
},
...
]
2020-07-30 16:20:24 -07:00
2019-12-14 23:35:42 -08:00
## info
```python
2020-07-30 16:20:24 -07:00
info()
2019-12-14 23:35:42 -08:00
```
2021-04-08 15:52:49 -07:00
Provides parser metadata (version, author, etc.)
2020-07-30 16:20:24 -07:00
2019-11-11 18:30:46 -08:00
## 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
2022-01-21 07:42:03 -08:00
raw: (boolean) unprocessed output if True
2019-11-12 11:18:00 -08:00
quiet: (boolean) suppress warning messages if True
Returns:
2021-01-04 18:01:16 -08:00
List of Dictionaries. Raw or processed structured data.
2019-11-11 18:30:46 -08:00
## Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
2021-12-01 16:12:51 -08:00
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)