mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-13 01:20:24 +02:00
add buddyinfo parser and doc update
This commit is contained in:
124
docs/parsers/proc_buddyinfo.md
Normal file
124
docs/parsers/proc_buddyinfo.md
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||||
|
<a id="jc.parsers.proc_buddyinfo"></a>
|
||||||
|
|
||||||
|
# jc.parsers.proc\_buddyinfo
|
||||||
|
|
||||||
|
jc - JSON Convert `/proc/buddyinfo` file parser
|
||||||
|
|
||||||
|
Usage (cli):
|
||||||
|
|
||||||
|
$ cat /proc/buddyinfo | jc --proc
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
$ cat /proc/buddyinfo | jc --proc-buddyinfo
|
||||||
|
|
||||||
|
Usage (module):
|
||||||
|
|
||||||
|
import jc
|
||||||
|
result = jc.parse('proc', proc_buddyinfo_file)
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
import jc
|
||||||
|
result = jc.parse('proc_buddyinfo', proc_buddyinfo_file)
|
||||||
|
|
||||||
|
Schema:
|
||||||
|
|
||||||
|
All values are integers.
|
||||||
|
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"node": integer,
|
||||||
|
"zone": string,
|
||||||
|
"free_chunks": [
|
||||||
|
integer # [0]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
[0] array index correlates to the Order number.
|
||||||
|
E.g. free_chunks[0] is the value for Order 0
|
||||||
|
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
$ cat /proc/buddyinfo | jc --proc -p
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"node": 0,
|
||||||
|
"zone": "DMA",
|
||||||
|
"free_chunks": [
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
3
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"node": 0,
|
||||||
|
"zone": "DMA32",
|
||||||
|
"free_chunks": [
|
||||||
|
78,
|
||||||
|
114,
|
||||||
|
82,
|
||||||
|
52,
|
||||||
|
38,
|
||||||
|
25,
|
||||||
|
13,
|
||||||
|
9,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
629
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"node": 0,
|
||||||
|
"zone": "Normal",
|
||||||
|
"free_chunks": [
|
||||||
|
0,
|
||||||
|
22,
|
||||||
|
8,
|
||||||
|
10,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
11,
|
||||||
|
13,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
<a id="jc.parsers.proc_buddyinfo.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)
|
@ -85,6 +85,7 @@ parsers = [
|
|||||||
'plist',
|
'plist',
|
||||||
'postconf',
|
'postconf',
|
||||||
'proc',
|
'proc',
|
||||||
|
'proc-buddyinfo',
|
||||||
'proc-meminfo',
|
'proc-meminfo',
|
||||||
'proc-modules',
|
'proc-modules',
|
||||||
'ps',
|
'ps',
|
||||||
|
175
jc/parsers/proc_buddyinfo.py
Normal file
175
jc/parsers/proc_buddyinfo.py
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
"""jc - JSON Convert `/proc/buddyinfo` file parser
|
||||||
|
|
||||||
|
Usage (cli):
|
||||||
|
|
||||||
|
$ cat /proc/buddyinfo | jc --proc
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
$ cat /proc/buddyinfo | jc --proc-buddyinfo
|
||||||
|
|
||||||
|
Usage (module):
|
||||||
|
|
||||||
|
import jc
|
||||||
|
result = jc.parse('proc', proc_buddyinfo_file)
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
import jc
|
||||||
|
result = jc.parse('proc_buddyinfo', proc_buddyinfo_file)
|
||||||
|
|
||||||
|
Schema:
|
||||||
|
|
||||||
|
All values are integers.
|
||||||
|
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"node": integer,
|
||||||
|
"zone": string,
|
||||||
|
"free_chunks": [
|
||||||
|
integer # [0]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
[0] array index correlates to the Order number.
|
||||||
|
E.g. free_chunks[0] is the value for Order 0
|
||||||
|
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
$ cat /proc/buddyinfo | jc --proc -p
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"node": 0,
|
||||||
|
"zone": "DMA",
|
||||||
|
"free_chunks": [
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
3
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"node": 0,
|
||||||
|
"zone": "DMA32",
|
||||||
|
"free_chunks": [
|
||||||
|
78,
|
||||||
|
114,
|
||||||
|
82,
|
||||||
|
52,
|
||||||
|
38,
|
||||||
|
25,
|
||||||
|
13,
|
||||||
|
9,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
629
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"node": 0,
|
||||||
|
"zone": "Normal",
|
||||||
|
"free_chunks": [
|
||||||
|
0,
|
||||||
|
22,
|
||||||
|
8,
|
||||||
|
10,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
11,
|
||||||
|
13,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
from typing import List, Dict
|
||||||
|
import jc.utils
|
||||||
|
|
||||||
|
|
||||||
|
class info():
|
||||||
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
|
version = '1.0'
|
||||||
|
description = '`/proc/buddyinfo` file parser'
|
||||||
|
author = 'Kelly Brazil'
|
||||||
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
|
compatible = ['linux']
|
||||||
|
hidden = True
|
||||||
|
|
||||||
|
|
||||||
|
__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.
|
||||||
|
"""
|
||||||
|
int_list = {'node'}
|
||||||
|
|
||||||
|
for entry in proc_data:
|
||||||
|
for key in entry:
|
||||||
|
if key in int_list:
|
||||||
|
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||||
|
|
||||||
|
if 'free_chunks' in entry:
|
||||||
|
entry['free_chunks'] = [int(x) for x in entry['free_chunks']]
|
||||||
|
|
||||||
|
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()):
|
||||||
|
|
||||||
|
buddy_list = line.split()
|
||||||
|
|
||||||
|
raw_output.append(
|
||||||
|
{
|
||||||
|
'node': buddy_list[1][:-1],
|
||||||
|
'zone': buddy_list[3],
|
||||||
|
'free_chunks': buddy_list[4:]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return raw_output if raw else _process(raw_output)
|
@ -90,7 +90,7 @@ import jc.utils
|
|||||||
class info():
|
class info():
|
||||||
"""Provides parser metadata (version, author, etc.)"""
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
version = '1.0'
|
version = '1.0'
|
||||||
description = '`/proc/meminfo` command parser'
|
description = '`/proc/meminfo` file parser'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
compatible = ['linux']
|
compatible = ['linux']
|
||||||
|
@ -104,7 +104,7 @@ import jc.utils
|
|||||||
class info():
|
class info():
|
||||||
"""Provides parser metadata (version, author, etc.)"""
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
version = '1.0'
|
version = '1.0'
|
||||||
description = '`/proc/modules` command parser'
|
description = '`/proc/modules` file parser'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
compatible = ['linux']
|
compatible = ['linux']
|
||||||
|
9
man/jc.1
9
man/jc.1
@ -397,15 +397,20 @@ PLIST file parser
|
|||||||
\fB--proc\fP
|
\fB--proc\fP
|
||||||
`/proc/` file parser
|
`/proc/` file parser
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B
|
||||||
|
\fB--proc-buddyinfo\fP
|
||||||
|
`/proc/buddyinfo` file parser
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B
|
||||||
\fB--proc-meminfo\fP
|
\fB--proc-meminfo\fP
|
||||||
`/proc/meminfo` command parser
|
`/proc/meminfo` file parser
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B
|
||||||
\fB--proc-modules\fP
|
\fB--proc-modules\fP
|
||||||
`/proc/modules` command parser
|
`/proc/modules` file parser
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B
|
||||||
|
Reference in New Issue
Block a user