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

initial add mpstat parser

This commit is contained in:
Kelly Brazil
2022-03-11 12:37:17 -08:00
parent 6c3e0e2aa0
commit bc97052ed4
3 changed files with 109 additions and 0 deletions

View File

@ -3,6 +3,7 @@ jc changelog
20220309 v1.18.6 (in progress) 20220309 v1.18.6 (in progress)
- Add pidstat command parser tested on linux - Add pidstat command parser tested on linux
- Add pidstat command streaming parser tested on linux - Add pidstat command streaming parser tested on linux
- Add mpstat command parser tested on linux
20220305 v1.18.5 20220305 v1.18.5
- Fix date parser to ensure AM/PM period string is always uppercase - Fix date parser to ensure AM/PM period string is always uppercase

View File

@ -59,6 +59,7 @@ parsers = [
'lsof', 'lsof',
'lsusb', 'lsusb',
'mount', 'mount',
'mpstat',
'netstat', 'netstat',
'nmcli', 'nmcli',
'ntpq', 'ntpq',

107
jc/parsers/mpstat.py Normal file
View File

@ -0,0 +1,107 @@
"""jc - JSON Convert `mpstat` command output parser
<<Short mpstat description and caveats>>
Usage (cli):
$ mpstat | jc --mpstat
or
$ jc mpstat
Usage (module):
import jc
result = jc.parse('mpstat', mpstat_command_output)
Schema:
[
{
"mpstat": string,
"bar": boolean,
"baz": integer
}
]
Examples:
$ mpstat | jc --mpstat -p
[]
$ mpstat | jc --mpstat -p -r
[]
"""
from typing import List, Dict
import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.0'
description = '`mpstat` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux']
magic_commands = ['mpstat']
__version__ = info.version
def _process(proc_data: List[Dict]) -> List[Dict]:
"""
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
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
return proc_data
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.
"""
jc.utils.compatibility(__name__, info.compatible, quiet)
jc.utils.input_type_check(data)
raw_output: List = []
if jc.utils.has_data(data):
for line in filter(None, data.splitlines()):
# parse the content here
# check out helper functions in jc.utils
# and jc.parsers.universal
pass
return raw_output if raw else _process(raw_output)