From d3727ea0906d6167aa48c340519242b010469d98 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 9 Mar 2022 16:09:35 -0800 Subject: [PATCH] doc update --- CHANGELOG | 3 +- README.md | 1 + docs/parsers/pidstat_s.md | 91 +++++++++++++++++++++++++++++++++++++++ man/jc.1 | 5 +++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 docs/parsers/pidstat_s.md diff --git a/CHANGELOG b/CHANGELOG index 163f9ced..cd899fe9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,8 @@ jc changelog 20220309 v1.18.6 (in progress) -- Add pidstat parser tested on linux +- Add pidstat command parser tested on linux +- Add pidstat command streaming parser tested on linux 20220305 v1.18.5 - Fix date parser to ensure AM/PM period string is always uppercase diff --git a/README.md b/README.md index 3732ab20..354e373d 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,7 @@ option. - `--ntpq` enables the `ntpq -p` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ntpq)) - `--passwd` enables the `/etc/passwd` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/passwd)) - `--pidstat` enables the `pidstat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/pidstat)) +- `--pidstat-s` enables the `pidstat` command streaming parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/pidstat_s)) - `--ping` enables the `ping` and `ping6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ping)) - `--ping-s` enables the `ping` and `ping6` command streaming parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ping_s)) - `--pip-list` enables the `pip list` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/pip_list)) diff --git a/docs/parsers/pidstat_s.md b/docs/parsers/pidstat_s.md new file mode 100644 index 00000000..cc049b34 --- /dev/null +++ b/docs/parsers/pidstat_s.md @@ -0,0 +1,91 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.parsers.pidstat\_s + +jc - JSON Convert `pidstat` command output streaming parser + +> This streaming parser outputs JSON Lines + +<> + +Usage (cli): + + $ pidstat | jc --pidstat-s + +Usage (module): + + import jc + # result is an iterable object (generator) + result = jc.parse('pidstat_s', pidstat_command_output.splitlines()) + for item in result: + # do something + + or + + import jc.parsers.pidstat_s + # result is an iterable object (generator) + result = jc.parsers.pidstat_s.parse(pidstat_command_output.splitlines()) + for item in result: + # do something + +Schema: + + { + "pidstat": string, + + # Below object only exists if using -qq or ignore_exceptions=True + + "_jc_meta": + { + "success": boolean, # false if error parsing + "error": string, # exists if "success" is false + "line": string # exists if "success" is false + } + } + +Examples: + + $ pidstat | jc --pidstat-s + {example output} + ... + + $ pidstat | jc --pidstat-s -r + {example output} + ... + + + +### parse + +```python +@add_jc_meta +def parse(data: Iterable[str], + raw: bool = False, + quiet: bool = False, + ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple] +``` + +Main text parsing generator function. Returns an iterator object. + +Parameters: + + data: (iterable) line-based text data to parse + (e.g. sys.stdin or str.splitlines()) + + raw: (boolean) unprocessed output if True + quiet: (boolean) suppress warning messages if True + ignore_exceptions: (boolean) ignore parsing exceptions if True + +Yields: + + Dictionary. Raw or processed structured data. + +Returns: + + Iterator object (generator) + +### Parser Information +Compatibility: linux + +Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/man/jc.1 b/man/jc.1 index cd19fb2a..ff95eb80 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -277,6 +277,11 @@ Key/Value file parser \fB--pidstat\fP `pidstat` command parser +.TP +.B +\fB--pidstat-s\fP +`pidstat` command streaming parser + .TP .B \fB--ping\fP