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

doc update

This commit is contained in:
Kelly Brazil
2022-03-09 14:06:34 -08:00
parent 3389eb5deb
commit ae754a84bf
3 changed files with 264 additions and 34 deletions

View File

@ -145,4 +145,4 @@ Returns:
### Parser Information
Compatibility: linux, aix, freebsd, darwin
Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.9 by Kelly Brazil (kellyjonbrazil@gmail.com)

156
docs/parsers/pidstat.md Normal file
View File

@ -0,0 +1,156 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.pidstat"></a>
# jc.parsers.pidstat
jc - JSON Convert `pidstat` command output parser
Must use the `-h` option in `pidstat`. All other `pidstat` options are
supported in combination with `-h`.
Usage (cli):
$ pidstat -h | jc --pidstat
or
$ jc pidstat -h
Usage (module):
import jc
result = jc.parse('pidstat', pidstat_command_output)
or
import jc.parsers.pidstat
result = jc.parsers.pidstat.parse(pidstat_command_output)
Schema:
[
{
"time": integer,
"uid": integer,
"pid": integer,
"percent_usr": float,
"percent_system": float,
"percent_guest": float,
"percent_cpu": float,
"cpu": integer,
"minflt_s": float,
"majflt_s": float,
"vsz": integer,
"rss": integer,
"percent_mem": float,
"stksize": integer,
"stkref": integer,
"kb_rd_s": float,
"kb_wr_s": float,
"kb_ccwr_s": float,
"cswch_s": float,
"nvcswch_s": float,
"command": string
}
]
Examples:
$ pidstat -hl | jc --pidstat -p
[
{
"time": 1646859134,
"uid": 0,
"pid": 1,
"percent_usr": 0.0,
"percent_system": 0.03,
"percent_guest": 0.0,
"percent_cpu": 0.03,
"cpu": 0,
"command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
},
{
"time": 1646859134,
"uid": 0,
"pid": 6,
"percent_usr": 0.0,
"percent_system": 0.0,
"percent_guest": 0.0,
"percent_cpu": 0.0,
"cpu": 0,
"command": "ksoftirqd/0"
},
{
"time": 1646859134,
"uid": 0,
"pid": 2263,
"percent_usr": 0.0,
"percent_system": 0.0,
"percent_guest": 0.0,
"percent_cpu": 0.0,
"cpu": 0,
"command": "kworker/0:0"
}
]
$ pidstat -hl | jc --pidstat -p -r
[
{
"time": "1646859134",
"uid": "0",
"pid": "1",
"percent_usr": "0.00",
"percent_system": "0.03",
"percent_guest": "0.00",
"percent_cpu": "0.03",
"cpu": "0",
"command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
},
{
"time": "1646859134",
"uid": "0",
"pid": "6",
"percent_usr": "0.00",
"percent_system": "0.00",
"percent_guest": "0.00",
"percent_cpu": "0.00",
"cpu": "0",
"command": "ksoftirqd/0"
},
{
"time": "1646859134",
"uid": "0",
"pid": "2263",
"percent_usr": "0.00",
"percent_system": "0.00",
"percent_guest": "0.00",
"percent_cpu": "0.00",
"cpu": "0",
"command": "kworker/0:0"
}
]
<a id="jc.parsers.pidstat.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict]
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@ -1,14 +1,15 @@
"""jc - JSON Convert `pidstat` command output parser
Must use the `-h` option in `pidstat`.
Must use the `-h` option in `pidstat`. All other `pidstat` options are
supported in combination with `-h`.
Usage (cli):
$ pidstat | jc --pidstat
$ pidstat -h | jc --pidstat
or
$ jc pidstat
$ jc pidstat -h
Usage (module):
@ -24,37 +25,105 @@ Schema:
[
{
"time": "1646857494",
"uid": "1000",
"pid": "2201",
"percent_usr": "0.00",
"percent_system": "0.00",
"percent_guest": "0.00",
"percent_cpu": "0.00",
"cpu": "0",
"minflt_s": "0.09",
"majflt_s": "0.00",
"vsz": "108328",
"rss": "1040",
"percent_mem": "0.03",
"stksize": "132",
"stkref": "20",
"kb_rd_s": "0.00",
"kb_wr_s": "0.00",
"kb_ccwr_s": "0.00",
"cswch_s": "0.00",
"nvcswch_s": "0.00",
"command": "pidstat -dlrsuwh"
"time": integer,
"uid": integer,
"pid": integer,
"percent_usr": float,
"percent_system": float,
"percent_guest": float,
"percent_cpu": float,
"cpu": integer,
"minflt_s": float,
"majflt_s": float,
"vsz": integer,
"rss": integer,
"percent_mem": float,
"stksize": integer,
"stkref": integer,
"kb_rd_s": float,
"kb_wr_s": float,
"kb_ccwr_s": float,
"cswch_s": float,
"nvcswch_s": float,
"command": string
}
]
Examples:
$ pidstat | jc --pidstat -p
[]
$ pidstat -hl | jc --pidstat -p
[
{
"time": 1646859134,
"uid": 0,
"pid": 1,
"percent_usr": 0.0,
"percent_system": 0.03,
"percent_guest": 0.0,
"percent_cpu": 0.03,
"cpu": 0,
"command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
},
{
"time": 1646859134,
"uid": 0,
"pid": 6,
"percent_usr": 0.0,
"percent_system": 0.0,
"percent_guest": 0.0,
"percent_cpu": 0.0,
"cpu": 0,
"command": "ksoftirqd/0"
},
{
"time": 1646859134,
"uid": 0,
"pid": 2263,
"percent_usr": 0.0,
"percent_system": 0.0,
"percent_guest": 0.0,
"percent_cpu": 0.0,
"cpu": 0,
"command": "kworker/0:0"
}
]
$ pidstat | jc --pidstat -p -r
[]
$ pidstat -hl | jc --pidstat -p -r
[
{
"time": "1646859134",
"uid": "0",
"pid": "1",
"percent_usr": "0.00",
"percent_system": "0.03",
"percent_guest": "0.00",
"percent_cpu": "0.03",
"cpu": "0",
"command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
},
{
"time": "1646859134",
"uid": "0",
"pid": "6",
"percent_usr": "0.00",
"percent_system": "0.00",
"percent_guest": "0.00",
"percent_cpu": "0.00",
"cpu": "0",
"command": "ksoftirqd/0"
},
{
"time": "1646859134",
"uid": "0",
"pid": "2263",
"percent_usr": "0.00",
"percent_system": "0.00",
"percent_guest": "0.00",
"percent_cpu": "0.00",
"cpu": "0",
"command": "kworker/0:0"
}
]
"""
from typing import List, Dict
import jc.utils
@ -87,11 +156,16 @@ def _process(proc_data: List[Dict]) -> List[Dict]:
List of Dictionaries. Structured to conform to the schema.
"""
# process the data here
# rebuild output for added semantic information
# use helper functions in jc.utils for int, float, bool
# conversions and timestamps
int_list = ['time', 'uid', 'pid', 'cpu', 'vsz', 'rss', 'stksize', 'stkref']
float_list = ['percent_usr', 'percent_system', 'percent_guest', 'percent_cpu',
'minflt_s', 'majflt_s', 'percent_mem', 'kb_rd_s', 'kb_wr_s',
'kb_ccwr_s', 'cswch_s', 'nvcswch_s']
for entry in proc_data:
for key in entry:
if key in int_list:
entry[key] = jc.utils.convert_to_int(entry[key])
if key in float_list:
entry[key] = jc.utils.convert_to_float(entry[key])
return proc_data