diff --git a/docs/parsers/proc.md b/docs/parsers/proc.md index 3c3aa392..38f977a1 100644 --- a/docs/parsers/proc.md +++ b/docs/parsers/proc.md @@ -5,26 +5,43 @@ jc - JSON Convert Proc file output parser -<> +This parser automatically identifies the Proc file and calls the +corresponding parser to peform the parsing. The specific parsers can also +be called directly, if desired and have a naming convention of +`proc-` (cli) or `proc_` (module). Usage (cli): - $ cat /proc/ | jc --procfile + $ cat /proc/meminfo | jc --proc + +or + + $ cat /proc/meminfo | jc --proc-memifno Usage (module): import jc - result = jc.parse('procfile', proc_file) + result = jc.parse('proc', proc_file) Schema: - [ - { - "procfile": string, - "bar": boolean, - "baz": integer - } - ] +See the specific Proc parser for the schema: + + $ jc --help --proc- + +For example: + + $ jc --help --proc-meminfo + +Specific Proc file parser names can be found with `jc -hh` or `jc -a`. + +Schemas can also be found online at: + + https://kellyjonbrazil.github.io/jc/docs/parsers/proc_ + +For example: + + https://kellyjonbrazil.github.io/jc/docs/parsers/proc_meminfo Examples: diff --git a/docs/parsers/proc_meminfo.md b/docs/parsers/proc_meminfo.md index 95891fe4..edf76d2e 100644 --- a/docs/parsers/proc_meminfo.md +++ b/docs/parsers/proc_meminfo.md @@ -9,28 +9,84 @@ Usage (cli): $ cat /proc/meminfo | jc --proc +or + + $ cat /proc/meminfo | jc --proc-meminfo + Usage (module): + import jc + result = jc.parse('proc', proc_meminfo_file) + +or + import jc result = jc.parse('proc_meminfo', proc_meminfo_file) Schema: - [ - { - "foo": string, - "bar": boolean, - "baz": integer - } - ] +All values are integers. + + { + integer + } Examples: - $ foo | jc --foo -p - [] - - $ foo | jc --foo -p -r - [] + $ cat /proc/meminfo | jc --proc -p + { + "MemTotal": 3997272, + "MemFree": 2760316, + "MemAvailable": 3386876, + "Buffers": 40452, + "Cached": 684856, + "SwapCached": 0, + "Active": 475816, + "Inactive": 322064, + "Active(anon)": 70216, + "Inactive(anon)": 148, + "Active(file)": 405600, + "Inactive(file)": 321916, + "Unevictable": 19476, + "Mlocked": 19476, + "SwapTotal": 3996668, + "SwapFree": 3996668, + "Dirty": 152, + "Writeback": 0, + "AnonPages": 92064, + "Mapped": 79464, + "Shmem": 1568, + "KReclaimable": 188216, + "Slab": 288096, + "SReclaimable": 188216, + "SUnreclaim": 99880, + "KernelStack": 5872, + "PageTables": 1812, + "NFS_Unstable": 0, + "Bounce": 0, + "WritebackTmp": 0, + "CommitLimit": 5995304, + "Committed_AS": 445240, + "VmallocTotal": 34359738367, + "VmallocUsed": 21932, + "VmallocChunk": 0, + "Percpu": 107520, + "HardwareCorrupted": 0, + "AnonHugePages": 0, + "ShmemHugePages": 0, + "ShmemPmdMapped": 0, + "FileHugePages": 0, + "FilePmdMapped": 0, + "HugePages_Total": 0, + "HugePages_Free": 0, + "HugePages_Rsvd": 0, + "HugePages_Surp": 0, + "Hugepagesize": 2048, + "Hugetlb": 0, + "DirectMap4k": 192320, + "DirectMap2M": 4001792, + "DirectMap1G": 2097152 + } diff --git a/docs/parsers/proc_modules.md b/docs/parsers/proc_modules.md index 658fa12f..7497d141 100644 --- a/docs/parsers/proc_modules.md +++ b/docs/parsers/proc_modules.md @@ -5,14 +5,21 @@ jc - JSON Convert `/proc/modules` command output parser -<> - Usage (cli): $ cat /proc/modules | jc --proc +or + + $ cat /proc/modules | jc --proc-modules + Usage (module): + import jc + result = jc.parse('proc', proc_modules_file) + +or + import jc result = jc.parse('proc_modules', proc_modules_file) diff --git a/jc/parsers/proc.py b/jc/parsers/proc.py index 4793bf9d..46735933 100644 --- a/jc/parsers/proc.py +++ b/jc/parsers/proc.py @@ -1,25 +1,42 @@ """jc - JSON Convert Proc file output parser -<> +This parser automatically identifies the Proc file and calls the +corresponding parser to peform the parsing. The specific parsers can also +be called directly, if desired and have a naming convention of +`proc-` (cli) or `proc_` (module). Usage (cli): - $ cat /proc/ | jc --procfile + $ cat /proc/meminfo | jc --proc + +or + + $ cat /proc/meminfo | jc --proc-memifno Usage (module): import jc - result = jc.parse('procfile', proc_file) + result = jc.parse('proc', proc_file) Schema: - [ - { - "procfile": string, - "bar": boolean, - "baz": integer - } - ] +See the specific Proc parser for the schema: + + $ jc --help --proc- + +For example: + + $ jc --help --proc-meminfo + +Specific Proc file parser names can be found with `jc -hh` or `jc -a`. + +Schemas can also be found online at: + + https://kellyjonbrazil.github.io/jc/docs/parsers/proc_ + +For example: + + https://kellyjonbrazil.github.io/jc/docs/parsers/proc_meminfo Examples: @@ -139,7 +156,7 @@ def parse( ioports_p: 'proc_ioports', loadavg_p: 'proc_loadavg', locks_p: 'proc_locks', - meminfo_p: 'proc_meminfo', ####### + meminfo_p: 'proc_meminfo', modules_p: 'proc_modules', mtrr_p: 'proc_mtrr', pagetypeinfo_p: 'proc_pagetypeinfo', diff --git a/jc/parsers/proc_meminfo.py b/jc/parsers/proc_meminfo.py index e9030084..f1571441 100644 --- a/jc/parsers/proc_meminfo.py +++ b/jc/parsers/proc_meminfo.py @@ -4,28 +4,84 @@ Usage (cli): $ cat /proc/meminfo | jc --proc +or + + $ cat /proc/meminfo | jc --proc-meminfo + Usage (module): + import jc + result = jc.parse('proc', proc_meminfo_file) + +or + import jc result = jc.parse('proc_meminfo', proc_meminfo_file) Schema: - [ - { - "foo": string, - "bar": boolean, - "baz": integer - } - ] +All values are integers. + + { + integer + } Examples: - $ foo | jc --foo -p - [] - - $ foo | jc --foo -p -r - [] + $ cat /proc/meminfo | jc --proc -p + { + "MemTotal": 3997272, + "MemFree": 2760316, + "MemAvailable": 3386876, + "Buffers": 40452, + "Cached": 684856, + "SwapCached": 0, + "Active": 475816, + "Inactive": 322064, + "Active(anon)": 70216, + "Inactive(anon)": 148, + "Active(file)": 405600, + "Inactive(file)": 321916, + "Unevictable": 19476, + "Mlocked": 19476, + "SwapTotal": 3996668, + "SwapFree": 3996668, + "Dirty": 152, + "Writeback": 0, + "AnonPages": 92064, + "Mapped": 79464, + "Shmem": 1568, + "KReclaimable": 188216, + "Slab": 288096, + "SReclaimable": 188216, + "SUnreclaim": 99880, + "KernelStack": 5872, + "PageTables": 1812, + "NFS_Unstable": 0, + "Bounce": 0, + "WritebackTmp": 0, + "CommitLimit": 5995304, + "Committed_AS": 445240, + "VmallocTotal": 34359738367, + "VmallocUsed": 21932, + "VmallocChunk": 0, + "Percpu": 107520, + "HardwareCorrupted": 0, + "AnonHugePages": 0, + "ShmemHugePages": 0, + "ShmemPmdMapped": 0, + "FileHugePages": 0, + "FilePmdMapped": 0, + "HugePages_Total": 0, + "HugePages_Free": 0, + "HugePages_Rsvd": 0, + "HugePages_Surp": 0, + "Hugepagesize": 2048, + "Hugetlb": 0, + "DirectMap4k": 192320, + "DirectMap2M": 4001792, + "DirectMap1G": 2097152 + } """ from typing import Dict import jc.utils diff --git a/jc/parsers/proc_modules.py b/jc/parsers/proc_modules.py index 4cc8593e..92bb82c4 100644 --- a/jc/parsers/proc_modules.py +++ b/jc/parsers/proc_modules.py @@ -1,13 +1,20 @@ """jc - JSON Convert `/proc/modules` command output parser -<> - Usage (cli): $ cat /proc/modules | jc --proc +or + + $ cat /proc/modules | jc --proc-modules + Usage (module): + import jc + result = jc.parse('proc', proc_modules_file) + +or + import jc result = jc.parse('proc_modules', proc_modules_file)