mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-23 00:29:59 +02:00
add proc-pid-mountinfo parser (initial)
This commit is contained in:
@ -7,15 +7,15 @@ jc - JSON Convert `/proc/<pid>/io` file parser
|
|||||||
|
|
||||||
Usage (cli):
|
Usage (cli):
|
||||||
|
|
||||||
$ cat /proc/<pid>/io | jc --proc
|
$ cat /proc/1/io | jc --proc
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
$ jc /proc/<pid>/io
|
$ jc /proc/1/io
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
$ cat /proc/<pid>/io | jc --proc-pid-io
|
$ cat /proc/1/io | jc --proc-pid-io
|
||||||
|
|
||||||
Usage (module):
|
Usage (module):
|
||||||
|
|
||||||
|
132
docs/parsers/proc_pid_mountinfo.md
Normal file
132
docs/parsers/proc_pid_mountinfo.md
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||||
|
<a id="jc.parsers.proc_pid_mountinfo"></a>
|
||||||
|
|
||||||
|
# jc.parsers.proc\_pid\_mountinfo
|
||||||
|
|
||||||
|
jc - JSON Convert `/proc/<pid>/mountinfo` file parser
|
||||||
|
|
||||||
|
Usage (cli):
|
||||||
|
|
||||||
|
$ cat /proc/1/mountinfo | jc --proc
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
$ jc /proc/1/mountinfo
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
$ cat /proc/1/mountinfo | jc --proc-pid-mountinfo
|
||||||
|
|
||||||
|
Usage (module):
|
||||||
|
|
||||||
|
import jc
|
||||||
|
result = jc.parse('proc', proc_pid_mountinfo_file)
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
import jc
|
||||||
|
result = jc.parse('proc_pid_mountinfo', proc_pid_mountinfo_file)
|
||||||
|
|
||||||
|
Schema:
|
||||||
|
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"module": string,
|
||||||
|
"size": integer,
|
||||||
|
"used": integer,
|
||||||
|
"used_by": [
|
||||||
|
string
|
||||||
|
],
|
||||||
|
"status": string,
|
||||||
|
"location": string
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
$ cat /proc/1/mountinfo | jc --proc -p
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"module": "binfmt_misc",
|
||||||
|
"size": 24576,
|
||||||
|
"used": 1,
|
||||||
|
"used_by": [],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0ab4000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "vsock_loopback",
|
||||||
|
"size": 16384,
|
||||||
|
"used": 0,
|
||||||
|
"used_by": [],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0a14000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "vmw_vsock_virtio_transport_common",
|
||||||
|
"size": 36864,
|
||||||
|
"used": 1,
|
||||||
|
"used_by": [
|
||||||
|
"vsock_loopback"
|
||||||
|
],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0a03000"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
|
||||||
|
$ cat /proc/1/mountinfo | jc --proc_pid-mountinfo -p -r
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"module": "binfmt_misc",
|
||||||
|
"size": "24576",
|
||||||
|
"used": "1",
|
||||||
|
"used_by": [],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0ab4000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "vsock_loopback",
|
||||||
|
"size": "16384",
|
||||||
|
"used": "0",
|
||||||
|
"used_by": [],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0a14000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "vmw_vsock_virtio_transport_common",
|
||||||
|
"size": "36864",
|
||||||
|
"used": "1",
|
||||||
|
"used_by": [
|
||||||
|
"vsock_loopback"
|
||||||
|
],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0a03000"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
|
||||||
|
<a id="jc.parsers.proc_pid_mountinfo.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)
|
@ -115,6 +115,7 @@ parsers = [
|
|||||||
'proc-pid-fdinfo',
|
'proc-pid-fdinfo',
|
||||||
'proc-pid-io',
|
'proc-pid-io',
|
||||||
'proc-pid-maps',
|
'proc-pid-maps',
|
||||||
|
'proc-pid-mountinfo',
|
||||||
'proc-pid-numa-maps',
|
'proc-pid-numa-maps',
|
||||||
'ps',
|
'ps',
|
||||||
'route',
|
'route',
|
||||||
|
@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
Usage (cli):
|
Usage (cli):
|
||||||
|
|
||||||
$ cat /proc/<pid>/io | jc --proc
|
$ cat /proc/1/io | jc --proc
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
$ jc /proc/<pid>/io
|
$ jc /proc/1/io
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
$ cat /proc/<pid>/io | jc --proc-pid-io
|
$ cat /proc/1/io | jc --proc-pid-io
|
||||||
|
|
||||||
Usage (module):
|
Usage (module):
|
||||||
|
|
||||||
@ -50,7 +50,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/pid-io` file parser'
|
description = '`/proc/<pid>/io` file parser'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
compatible = ['linux']
|
compatible = ['linux']
|
||||||
|
190
jc/parsers/proc_pid_mountinfo.py
Normal file
190
jc/parsers/proc_pid_mountinfo.py
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
"""jc - JSON Convert `/proc/<pid>/mountinfo` file parser
|
||||||
|
|
||||||
|
Usage (cli):
|
||||||
|
|
||||||
|
$ cat /proc/1/mountinfo | jc --proc
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
$ jc /proc/1/mountinfo
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
$ cat /proc/1/mountinfo | jc --proc-pid-mountinfo
|
||||||
|
|
||||||
|
Usage (module):
|
||||||
|
|
||||||
|
import jc
|
||||||
|
result = jc.parse('proc', proc_pid_mountinfo_file)
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
import jc
|
||||||
|
result = jc.parse('proc_pid_mountinfo', proc_pid_mountinfo_file)
|
||||||
|
|
||||||
|
Schema:
|
||||||
|
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"module": string,
|
||||||
|
"size": integer,
|
||||||
|
"used": integer,
|
||||||
|
"used_by": [
|
||||||
|
string
|
||||||
|
],
|
||||||
|
"status": string,
|
||||||
|
"location": string
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
$ cat /proc/1/mountinfo | jc --proc -p
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"module": "binfmt_misc",
|
||||||
|
"size": 24576,
|
||||||
|
"used": 1,
|
||||||
|
"used_by": [],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0ab4000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "vsock_loopback",
|
||||||
|
"size": 16384,
|
||||||
|
"used": 0,
|
||||||
|
"used_by": [],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0a14000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "vmw_vsock_virtio_transport_common",
|
||||||
|
"size": 36864,
|
||||||
|
"used": 1,
|
||||||
|
"used_by": [
|
||||||
|
"vsock_loopback"
|
||||||
|
],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0a03000"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
|
||||||
|
$ cat /proc/1/mountinfo | jc --proc_pid-mountinfo -p -r
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"module": "binfmt_misc",
|
||||||
|
"size": "24576",
|
||||||
|
"used": "1",
|
||||||
|
"used_by": [],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0ab4000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "vsock_loopback",
|
||||||
|
"size": "16384",
|
||||||
|
"used": "0",
|
||||||
|
"used_by": [],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0a14000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "vmw_vsock_virtio_transport_common",
|
||||||
|
"size": "36864",
|
||||||
|
"used": "1",
|
||||||
|
"used_by": [
|
||||||
|
"vsock_loopback"
|
||||||
|
],
|
||||||
|
"status": "Live",
|
||||||
|
"location": "0xffffffffc0a03000"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
import re
|
||||||
|
from typing import List, Dict
|
||||||
|
import jc.utils
|
||||||
|
|
||||||
|
|
||||||
|
class info():
|
||||||
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
|
version = '1.0'
|
||||||
|
description = '`/proc/<pid>/mountinfo` 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 = {'size', 'used'}
|
||||||
|
|
||||||
|
for entry in proc_data:
|
||||||
|
for key in entry:
|
||||||
|
if key in int_list:
|
||||||
|
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||||
|
|
||||||
|
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):
|
||||||
|
|
||||||
|
line_pattern = re.compile(r'''
|
||||||
|
^(?P<mount_id>\d+)\s
|
||||||
|
(?P<parent_id>\d+)\s
|
||||||
|
(?P<maj>\d+):
|
||||||
|
(?P<min>\d+)\s
|
||||||
|
(?P<root>\S+)\s
|
||||||
|
(?P<mount_point>\S+)\s
|
||||||
|
(?P<mount_options>\S+)\s?
|
||||||
|
(?P<optional_fields>(?:\s?\S+:\S+\s?)*)\s?-\s
|
||||||
|
(?P<fs_type>\S+)\s
|
||||||
|
(?P<mount_source>\S+)\s
|
||||||
|
(?P<super_options>\S+)
|
||||||
|
''', re.VERBOSE
|
||||||
|
)
|
||||||
|
|
||||||
|
for line in filter(None, data.splitlines()):
|
||||||
|
|
||||||
|
line_match = line_pattern.search(line)
|
||||||
|
if line_match:
|
||||||
|
raw_output.append(line_match.groupdict())
|
||||||
|
|
||||||
|
return raw_output if raw else _process(raw_output)
|
7
man/jc.1
7
man/jc.1
@ -553,13 +553,18 @@ PLIST file parser
|
|||||||
.TP
|
.TP
|
||||||
.B
|
.B
|
||||||
\fB--proc-pid-io\fP
|
\fB--proc-pid-io\fP
|
||||||
`/proc/pid-io` file parser
|
`/proc/<pid>/io` file parser
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B
|
||||||
\fB--proc-pid-maps\fP
|
\fB--proc-pid-maps\fP
|
||||||
`/proc/<pid>/maps` file parser
|
`/proc/<pid>/maps` file parser
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B
|
||||||
|
\fB--proc-pid-mountinfo\fP
|
||||||
|
`/proc/<pid>/mountinfo` file parser
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B
|
||||||
\fB--proc-pid-numa-maps\fP
|
\fB--proc-pid-numa-maps\fP
|
||||||
|
Reference in New Issue
Block a user