1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-09 01:05:53 +02:00

fix stats doc

This commit is contained in:
Kelly Brazil
2019-11-14 17:23:44 -08:00
parent 8f77d1de09
commit 340635cad5
3 changed files with 408 additions and 111 deletions

View File

@ -22,7 +22,7 @@ pydocmd simple jc.parsers.netstat+ > ../docs/parsers/netstat.md
pydocmd simple jc.parsers.ps+ > ../docs/parsers/ps.md pydocmd simple jc.parsers.ps+ > ../docs/parsers/ps.md
pydocmd simple jc.parsers.route+ > ../docs/parsers/route.md pydocmd simple jc.parsers.route+ > ../docs/parsers/route.md
pydocmd simple jc.parsers.ss+ > ../docs/parsers/ss.md pydocmd simple jc.parsers.ss+ > ../docs/parsers/ss.md
pydocmd simple jc.parsers.stat+ > ../docs/parsers/ss.md pydocmd simple jc.parsers.stat+ > ../docs/parsers/stat.md
pydocmd simple jc.parsers.uname+ > ../docs/parsers/uname.md pydocmd simple jc.parsers.uname+ > ../docs/parsers/uname.md
pydocmd simple jc.parsers.uptime+ > ../docs/parsers/uptime.md pydocmd simple jc.parsers.uptime+ > ../docs/parsers/uptime.md
pydocmd simple jc.parsers.w+ > ../docs/parsers/w.md pydocmd simple jc.parsers.w+ > ../docs/parsers/w.md

View File

@ -1,100 +1,245 @@
# jc.parsers.stat # jc.parsers.ss
jc - JSON CLI output utility stats Parser jc - JSON CLI output utility ss Parser
Usage: Usage:
specify --stats as the first argument if the piped input is coming from stats specify --ss as the first argument if the piped input is coming from ss
Limitations:
Extended information options like -e and -p are not supported and may cause parsing irregularities
Examples: Examples:
$ stat /bin/* | jc --stat -p $ sudo ss -a | jc --ss -p
[ [
{ {
"file": "/bin/bash", "netid": "nl",
"size": 1113504, "state": "UNCONN",
"blocks": 2176, "recv_q": 0,
"io_blocks": 4096, "send_q": 0,
"type": "regular file", "peer_address": "*",
"device": "802h/2050d", "channel": "rtnl:kernel"
"inode": 131099, },
"links": 1, {
"access": "0755", "netid": "nl",
"flags": "-rwxr-xr-x", "state": "UNCONN",
"uid": 0, "recv_q": 0,
"user": "root", "send_q": 0,
"gid": 0, "peer_address": "*",
"group": "root", "pid": 893,
"access_time": "2019-11-14 08:18:03.509681766 +0000", "channel": "rtnl:systemd-resolve"
"modify_time": "2019-06-06 22:28:15.000000000 +0000", },
"change_time": "2019-08-12 17:21:29.521945390 +0000", ...
"birth_time": "-" {
}, "netid": "p_raw",
{ "state": "UNCONN",
"file": "/bin/btrfs", "recv_q": 0,
"size": 716464, "send_q": 0,
"blocks": 1400, "peer_address": "*",
"io_blocks": 4096, "link_layer": "LLDP",
"type": "regular file", "interface": "ens33"
"device": "802h/2050d", },
"inode": 131100, {
"links": 1, "netid": "u_dgr",
"access": "0755", "state": "UNCONN",
"flags": "-rwxr-xr-x", "recv_q": 0,
"uid": 0, "send_q": 0,
"user": "root", "local_port": "93066",
"gid": 0, "peer_address": "*",
"group": "root", "peer_port": "0",
"access_time": "2019-11-14 08:18:28.990834276 +0000", "path": "/run/user/1000/systemd/notify"
"modify_time": "2018-03-12 23:04:27.000000000 +0000", },
"change_time": "2019-08-12 17:21:29.545944399 +0000", {
"birth_time": "-" "netid": "u_seq",
}, "state": "LISTEN",
... "recv_q": 0,
] "send_q": 128,
"local_port": "20699",
"peer_address": "*",
"peer_port": "0",
"path": "/run/udev/control"
},
...
{
"netid": "icmp6",
"state": "UNCONN",
"recv_q": 0,
"send_q": 0,
"local_address": "*",
"local_port": "ipv6-icmp",
"peer_address": "*",
"peer_port": "*",
"interface": "ens33"
},
{
"netid": "udp",
"state": "UNCONN",
"recv_q": 0,
"send_q": 0,
"local_address": "127.0.0.53",
"local_port": "domain",
"peer_address": "0.0.0.0",
"peer_port": "*",
"interface": "lo"
},
{
"netid": "tcp",
"state": "LISTEN",
"recv_q": 0,
"send_q": 128,
"local_address": "127.0.0.53",
"local_port": "domain",
"peer_address": "0.0.0.0",
"peer_port": "*",
"interface": "lo"
},
{
"netid": "tcp",
"state": "LISTEN",
"recv_q": 0,
"send_q": 128,
"local_address": "0.0.0.0",
"local_port": "ssh",
"peer_address": "0.0.0.0",
"peer_port": "*"
},
{
"netid": "tcp",
"state": "LISTEN",
"recv_q": 0,
"send_q": 128,
"local_address": "[::]",
"local_port": "ssh",
"peer_address": "[::]",
"peer_port": "*"
},
{
"netid": "v_str",
"state": "ESTAB",
"recv_q": 0,
"send_q": 0,
"local_address": "999900439",
"local_port": "1023",
"peer_address": "0",
"peer_port": "976",
"local_port_num": 1023,
"peer_port_num": 976
}
]
$ stat /bin/* | jc --stat -p -r $ sudo ss -a | jc --ss -p -r
[ [
{ {
"file": "/bin/bash", "netid": "nl",
"size": "1113504", "state": "UNCONN",
"blocks": "2176", "recv_q": "0",
"io_blocks": "4096", "send_q": "0",
"type": "regular file", "peer_address": "*",
"device": "802h/2050d", "channel": "rtnl:kernel"
"inode": "131099", },
"links": "1", {
"access": "0755", "netid": "nl",
"flags": "-rwxr-xr-x", "state": "UNCONN",
"uid": "0", "recv_q": "0",
"user": "root", "send_q": "0",
"gid": "0", "peer_address": "*",
"group": "root", "pid": "893",
"access_time": "2019-11-14 08:18:03.509681766 +0000", "channel": "rtnl:systemd-resolve"
"modify_time": "2019-06-06 22:28:15.000000000 +0000", },
"change_time": "2019-08-12 17:21:29.521945390 +0000", ...
"birth_time": "-" {
}, "netid": "p_raw",
{ "state": "UNCONN",
"file": "/bin/btrfs", "recv_q": "0",
"size": "716464", "send_q": "0",
"blocks": "1400", "peer_address": "*",
"io_blocks": "4096", "link_layer": "LLDP",
"type": "regular file", "interface": "ens33"
"device": "802h/2050d", },
"inode": "131100", {
"links": "1", "netid": "u_dgr",
"access": "0755", "state": "UNCONN",
"flags": "-rwxr-xr-x", "recv_q": "0",
"uid": "0", "send_q": "0",
"user": "root", "local_port": "93066",
"gid": "0", "peer_address": "*",
"group": "root", "peer_port": "0",
"access_time": "2019-11-14 08:18:28.990834276 +0000", "path": "/run/user/1000/systemd/notify"
"modify_time": "2018-03-12 23:04:27.000000000 +0000", },
"change_time": "2019-08-12 17:21:29.545944399 +0000", {
"birth_time": "-" "netid": "u_seq",
}, "state": "LISTEN",
.. "recv_q": "0",
] "send_q": "128",
"local_port": "20699",
"peer_address": "*",
"peer_port": "0",
"path": "/run/udev/control"
},
...
{
"netid": "icmp6",
"state": "UNCONN",
"recv_q": "0",
"send_q": "0",
"local_address": "*",
"local_port": "ipv6-icmp",
"peer_address": "*",
"peer_port": "*",
"interface": "ens33"
},
{
"netid": "udp",
"state": "UNCONN",
"recv_q": "0",
"send_q": "0",
"local_address": "127.0.0.53",
"local_port": "domain",
"peer_address": "0.0.0.0",
"peer_port": "*",
"interface": "lo"
},
{
"netid": "tcp",
"state": "LISTEN",
"recv_q": "0",
"send_q": "128",
"local_address": "127.0.0.53",
"local_port": "domain",
"peer_address": "0.0.0.0",
"peer_port": "*",
"interface": "lo"
},
{
"netid": "tcp",
"state": "LISTEN",
"recv_q": "0",
"send_q": "128",
"local_address": "0.0.0.0",
"local_port": "ssh",
"peer_address": "0.0.0.0",
"peer_port": "*"
},
{
"netid": "tcp",
"state": "LISTEN",
"recv_q": "0",
"send_q": "128",
"local_address": "[::]",
"local_port": "ssh",
"peer_address": "[::]",
"peer_port": "*"
},
{
"netid": "v_str",
"state": "ESTAB",
"recv_q": "0",
"send_q": "0",
"local_address": "999900439",
"local_port": "1023",
"peer_address": "0",
"peer_port": "976"
}
]
## process ## process
```python ```python
@ -113,28 +258,26 @@ Returns:
[ [
{ {
"file": string, "netid": string,
"link_to" string, "state": string,
"size": integer, "recv_q": integer,
"blocks": integer, "send_q": integer,
"io_blocks": integer, "local_address": string,
"type": string, "local_port": string,
"device": string, "local_port_num": integer,
"inode": integer, "peer_address": string,
"links": integer, "peer_port": string,
"access": string, "peer_port_num": integer,
"flags": string, "interface": string,
"uid": integer, "link_layer" string,
"user": string, "channel": string,
"gid": integer, "path": string,
"group": string, "pid": integer
"access_time": string,
"modify_time": string,
"change_time": string,
"birth_time": string
} }
] ]
Information from https://www.cyberciti.biz/files/ss.html used to define field names
## parse ## parse
```python ```python
parse(data, raw=False, quiet=False) parse(data, raw=False, quiet=False)

154
docs/parsers/stat.md Normal file
View File

@ -0,0 +1,154 @@
# jc.parsers.stat
jc - JSON CLI output utility stats Parser
Usage:
specify --stats as the first argument if the piped input is coming from stats
Examples:
$ stat /bin/* | jc --stat -p
[
{
"file": "/bin/bash",
"size": 1113504,
"blocks": 2176,
"io_blocks": 4096,
"type": "regular file",
"device": "802h/2050d",
"inode": 131099,
"links": 1,
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": 0,
"user": "root",
"gid": 0,
"group": "root",
"access_time": "2019-11-14 08:18:03.509681766 +0000",
"modify_time": "2019-06-06 22:28:15.000000000 +0000",
"change_time": "2019-08-12 17:21:29.521945390 +0000",
"birth_time": "-"
},
{
"file": "/bin/btrfs",
"size": 716464,
"blocks": 1400,
"io_blocks": 4096,
"type": "regular file",
"device": "802h/2050d",
"inode": 131100,
"links": 1,
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": 0,
"user": "root",
"gid": 0,
"group": "root",
"access_time": "2019-11-14 08:18:28.990834276 +0000",
"modify_time": "2018-03-12 23:04:27.000000000 +0000",
"change_time": "2019-08-12 17:21:29.545944399 +0000",
"birth_time": "-"
},
...
]
$ stat /bin/* | jc --stat -p -r
[
{
"file": "/bin/bash",
"size": "1113504",
"blocks": "2176",
"io_blocks": "4096",
"type": "regular file",
"device": "802h/2050d",
"inode": "131099",
"links": "1",
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": "0",
"user": "root",
"gid": "0",
"group": "root",
"access_time": "2019-11-14 08:18:03.509681766 +0000",
"modify_time": "2019-06-06 22:28:15.000000000 +0000",
"change_time": "2019-08-12 17:21:29.521945390 +0000",
"birth_time": "-"
},
{
"file": "/bin/btrfs",
"size": "716464",
"blocks": "1400",
"io_blocks": "4096",
"type": "regular file",
"device": "802h/2050d",
"inode": "131100",
"links": "1",
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": "0",
"user": "root",
"gid": "0",
"group": "root",
"access_time": "2019-11-14 08:18:28.990834276 +0000",
"modify_time": "2018-03-12 23:04:27.000000000 +0000",
"change_time": "2019-08-12 17:21:29.545944399 +0000",
"birth_time": "-"
},
..
]
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
Returns:
dictionary structured data with the following schema:
[
{
"file": string,
"link_to" string,
"size": integer,
"blocks": integer,
"io_blocks": integer,
"type": string,
"device": string,
"inode": integer,
"links": integer,
"access": string,
"flags": string,
"uid": integer,
"user": string,
"gid": integer,
"group": string,
"access_time": string,
"modify_time": string,
"change_time": string,
"birth_time": string
}
]
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
dictionary raw or processed structured data