2022-05-27 13:34:07 -07:00
|
|
|
[Home](https://kellyjonbrazil.github.io/jc/)
|
|
|
|
<a id="jc.parsers.top_s"></a>
|
|
|
|
|
2024-03-14 22:46:52 -07:00
|
|
|
# jc.parsers.top_s
|
2022-05-27 13:34:07 -07:00
|
|
|
|
|
|
|
jc - JSON Convert `top -b` command output streaming parser
|
|
|
|
|
|
|
|
> This streaming parser outputs JSON Lines (cli) or returns an Iterable of
|
|
|
|
> Dictionaries (module)
|
|
|
|
|
|
|
|
Requires batch mode (`-b`).
|
|
|
|
|
|
|
|
Warning messages will be printed to `STDERR` if truncated fields are
|
|
|
|
detected. These warnings can be suppressed with the `-q` or `quiet=True`
|
|
|
|
option.
|
|
|
|
|
|
|
|
Usage (cli):
|
|
|
|
|
|
|
|
$ top -b | jc --top-s
|
|
|
|
|
|
|
|
Usage (module):
|
|
|
|
|
|
|
|
import jc
|
|
|
|
|
|
|
|
result = jc.parse('top_s', top_command_output.splitlines())
|
|
|
|
for item in result:
|
|
|
|
# do something
|
|
|
|
|
|
|
|
Schema:
|
|
|
|
|
|
|
|
{
|
|
|
|
"time": string,
|
|
|
|
"uptime": integer,
|
|
|
|
"users": integer,
|
|
|
|
"load_1m": float,
|
|
|
|
"load_5m": float,
|
|
|
|
"load_15m": float,
|
|
|
|
"tasks_total": integer,
|
|
|
|
"tasks_running": integer,
|
|
|
|
"tasks_sleeping": integer,
|
|
|
|
"tasks_stopped": integer,
|
|
|
|
"tasks_zombie": integer,
|
|
|
|
"cpu_user": float,
|
|
|
|
"cpu_sys": float,
|
|
|
|
"cpu_nice": float,
|
|
|
|
"cpu_idle": float,
|
|
|
|
"cpu_wait": float,
|
|
|
|
"cpu_hardware": float,
|
|
|
|
"cpu_software": float,
|
|
|
|
"cpu_steal": float,
|
2022-05-28 12:41:36 -07:00
|
|
|
"mem_total": float, # [0]
|
|
|
|
"mem_free": float, # [0]
|
|
|
|
"mem_used": float, # [0]
|
|
|
|
"mem_buff_cache": float, # [0]
|
|
|
|
"swap_total": float, # [0]
|
|
|
|
"swap_free": float, # [0]
|
|
|
|
"swap_used": float, # [0]
|
|
|
|
"mem_available": float, # [0]
|
2022-05-27 13:34:07 -07:00
|
|
|
"processes": [
|
|
|
|
{
|
|
|
|
"pid": integer,
|
|
|
|
"user": string,
|
|
|
|
"priority": integer,
|
|
|
|
"nice": integer,
|
2022-05-28 12:41:36 -07:00
|
|
|
"virtual_mem": float, # [1]
|
|
|
|
"resident_mem": float, # [1]
|
|
|
|
"shared_mem": float, # [1]
|
2022-05-27 13:34:07 -07:00
|
|
|
"status": string,
|
|
|
|
"percent_cpu": float,
|
|
|
|
"percent_mem": float,
|
|
|
|
"time_hundredths": string,
|
|
|
|
"command": string,
|
|
|
|
"parent_pid": integer,
|
|
|
|
"uid": integer,
|
|
|
|
"real_uid": integer,
|
|
|
|
"real_user": string,
|
|
|
|
"saved_uid": integer,
|
|
|
|
"saved_user": string,
|
|
|
|
"gid": integer,
|
|
|
|
"group": string,
|
|
|
|
"pgrp": integer,
|
|
|
|
"tty": string,
|
|
|
|
"tty_process_gid": integer,
|
|
|
|
"session_id": integer,
|
|
|
|
"thread_count": integer,
|
|
|
|
"last_used_processor": integer,
|
|
|
|
"time": string,
|
2022-05-28 12:41:36 -07:00
|
|
|
"swap": float, # [1]
|
|
|
|
"code": float, # [1]
|
|
|
|
"data": float, # [1]
|
2022-05-27 13:34:07 -07:00
|
|
|
"major_page_fault_count": integer,
|
|
|
|
"minor_page_fault_count": integer,
|
|
|
|
"dirty_pages_count": integer,
|
|
|
|
"sleeping_in_function": string,
|
|
|
|
"flags": string,
|
|
|
|
"cgroups": string,
|
|
|
|
"supplementary_gids": [
|
|
|
|
integer
|
|
|
|
],
|
|
|
|
"supplementary_groups": [
|
|
|
|
string
|
|
|
|
],
|
|
|
|
"thread_gid": integer,
|
|
|
|
"environment_variables": [
|
|
|
|
string
|
|
|
|
]
|
|
|
|
"major_page_fault_count_delta": integer,
|
|
|
|
"minor_page_fault_count_delta": integer,
|
2022-05-28 12:41:36 -07:00
|
|
|
"used": float, # [1]
|
2022-05-27 13:34:07 -07:00
|
|
|
"ipc_namespace_inode": integer,
|
|
|
|
"mount_namespace_inode": integer,
|
|
|
|
"net_namespace_inode": integer,
|
|
|
|
"pid_namespace_inode": integer,
|
|
|
|
"user_namespace_inode": integer,
|
2022-05-27 17:20:54 -07:00
|
|
|
"nts_namespace_inode": integer,
|
|
|
|
"control_group_name": string,
|
|
|
|
"lxc_container_name": string,
|
|
|
|
"numa_node": integer,
|
|
|
|
"out_of_mem_adjustment": integer,
|
|
|
|
"out_of_mem_score": integer,
|
|
|
|
"resident_anon_mem": integer,
|
|
|
|
"resident_file_backed_mem": integer,
|
|
|
|
"resident_locked_mem": integer,
|
|
|
|
"resident_shared_mem": integer
|
2022-05-27 13:34:07 -07:00
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
# below object only exists if using -qq or ignore_exceptions=True
|
|
|
|
"_jc_meta": {
|
|
|
|
"success": boolean, # false if error parsing
|
|
|
|
"error": string, # exists if "success" is false
|
|
|
|
"line": string # exists if "success" is false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[0] Values are in the units output by `top`
|
|
|
|
[1] Unit suffix stripped during float conversion
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$ top -b | jc --top-s
|
|
|
|
{"time":"11:24:50","uptime":2,"users":2,"load_1m":0.23,"load_5m":...}
|
|
|
|
...
|
|
|
|
|
|
|
|
$ top -b | jc --top-s -r
|
|
|
|
{"time":"11:24:50","uptime":"2 min","users":"2","load_1m":"0.23","lo...}
|
|
|
|
...
|
|
|
|
|
|
|
|
<a id="jc.parsers.top_s.parse"></a>
|
|
|
|
|
|
|
|
### parse
|
|
|
|
|
|
|
|
```python
|
|
|
|
def parse(data: Iterable[str],
|
|
|
|
raw: bool = False,
|
|
|
|
quiet: bool = False,
|
|
|
|
ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple]
|
|
|
|
```
|
|
|
|
|
|
|
|
Main text parsing generator function. Returns an iterable object.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
|
|
|
data: (iterable) line-based text data to parse
|
|
|
|
(e.g. sys.stdin or str.splitlines())
|
|
|
|
|
|
|
|
raw: (boolean) unprocessed output if True
|
|
|
|
quiet: (boolean) suppress warning messages if True
|
|
|
|
ignore_exceptions: (boolean) ignore parsing exceptions if True
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
Iterable of Dictionaries
|
|
|
|
|
|
|
|
### Parser Information
|
|
|
|
Compatibility: linux
|
|
|
|
|
2023-12-21 14:55:21 -08:00
|
|
|
Source: [`jc/parsers/top_s.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/top_s.py)
|
|
|
|
|
2024-04-28 13:01:07 -07:00
|
|
|
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|