2021-09-22 14:38:13 -07:00
|
|
|
[Home](https://kellyjonbrazil.github.io/jc/)
|
2022-01-25 17:07:47 -08:00
|
|
|
<a id="jc.parsers.vmstat_s"></a>
|
|
|
|
|
|
|
|
# jc.parsers.vmstat\_s
|
2021-09-22 14:38:13 -07:00
|
|
|
|
|
|
|
jc - JSON CLI output utility `vmstat` command output streaming parser
|
|
|
|
|
2021-09-27 10:35:08 -07:00
|
|
|
> This streaming parser outputs JSON Lines
|
|
|
|
|
2021-09-22 14:38:13 -07:00
|
|
|
Options supported: `-a`, `-w`, `-d`, `-t`
|
|
|
|
|
2022-01-19 17:30:14 -08:00
|
|
|
The `epoch` calculated timestamp field is naive. (i.e. based on the local
|
|
|
|
time of the system the parser is run on)
|
2021-09-24 10:11:15 -07:00
|
|
|
|
2022-01-19 17:30:14 -08:00
|
|
|
The `epoch_utc` calculated timestamp field is timezone-aware and is only
|
|
|
|
available if the timezone field is UTC.
|
2021-09-24 10:11:15 -07:00
|
|
|
|
2021-09-22 14:38:13 -07:00
|
|
|
Usage (cli):
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
$ vmstat | jc --vmstat-s
|
2021-09-22 14:38:13 -07:00
|
|
|
|
2022-01-19 17:30:14 -08:00
|
|
|
> Note: When piping `jc` converted `vmstat` output to other processes it may
|
|
|
|
appear the output is hanging due to the OS pipe buffers. This is because
|
|
|
|
`vmstat` output is too small to quickly fill up the buffer. Use the `-u`
|
|
|
|
option to unbuffer the `jc` output if you would like immediate output. See
|
|
|
|
the [readme](https://github.com/kellyjonbrazil/jc/tree/master#unbuffering-output)
|
|
|
|
for more information.
|
2021-09-26 16:24:18 -07:00
|
|
|
|
2021-09-22 14:38:13 -07:00
|
|
|
Usage (module):
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
import jc
|
|
|
|
# result is an iterable object (generator)
|
|
|
|
result = jc.parse('vmstat_s', vmstat_command_output.splitlines())
|
|
|
|
for item in result:
|
|
|
|
# do something
|
2022-01-18 15:38:03 -08:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
or
|
2022-01-18 15:38:03 -08:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
import jc.parsers.vmstat_s
|
|
|
|
# result is an iterable object (generator)
|
|
|
|
result = jc.parsers.vmstat_s.parse(vmstat_command_output.splitlines())
|
|
|
|
for item in result:
|
|
|
|
# do something
|
2021-09-22 14:38:13 -07:00
|
|
|
|
|
|
|
Schema:
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
{
|
|
|
|
"runnable_procs": integer,
|
|
|
|
"uninterruptible_sleeping_procs": integer,
|
|
|
|
"virtual_mem_used": integer,
|
|
|
|
"free_mem": integer,
|
|
|
|
"buffer_mem": integer,
|
|
|
|
"cache_mem": integer,
|
|
|
|
"inactive_mem": integer,
|
|
|
|
"active_mem": integer,
|
|
|
|
"swap_in": integer,
|
|
|
|
"swap_out": integer,
|
|
|
|
"blocks_in": integer,
|
|
|
|
"blocks_out": integer,
|
|
|
|
"interrupts": integer,
|
|
|
|
"context_switches": integer,
|
|
|
|
"user_time": integer,
|
|
|
|
"system_time": integer,
|
|
|
|
"idle_time": integer,
|
|
|
|
"io_wait_time": integer,
|
|
|
|
"stolen_time": integer,
|
|
|
|
"disk": string,
|
|
|
|
"total_reads": integer,
|
|
|
|
"merged_reads": integer,
|
|
|
|
"sectors_read": integer,
|
|
|
|
"reading_ms": integer,
|
|
|
|
"total_writes": integer,
|
|
|
|
"merged_writes": integer,
|
|
|
|
"sectors_written": integer,
|
|
|
|
"writing_ms": integer,
|
|
|
|
"current_io": integer,
|
|
|
|
"io_seconds": integer,
|
|
|
|
"timestamp": string,
|
|
|
|
"timezone": string,
|
|
|
|
"epoch": integer, # [0]
|
|
|
|
"epoch_utc": integer # [1]
|
|
|
|
|
|
|
|
# Below object only exists if using -qq or ignore_exceptions=True
|
|
|
|
|
|
|
|
"_jc_meta":
|
|
|
|
{
|
|
|
|
"success": boolean, # [2]
|
|
|
|
"error": string, # [3]
|
|
|
|
"line": string # [3]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[0] naive timestamp if -t flag is used
|
|
|
|
[1] aware timestamp if -t flag is used and UTC TZ
|
|
|
|
[2] false if error parsing
|
|
|
|
[3] exists if "success" is false
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$ vmstat | jc --vmstat-s
|
|
|
|
{"runnable_procs":2,"uninterruptible_sleeping_procs":0,"virtual_mem...}
|
|
|
|
...
|
|
|
|
|
|
|
|
$ vmstat | jc --vmstat-s -r
|
|
|
|
{"runnable_procs":"2","uninterruptible_sleeping_procs":"0","virtua...}
|
|
|
|
...
|
2022-01-25 17:07:47 -08:00
|
|
|
|
|
|
|
<a id="jc.parsers.vmstat_s.parse"></a>
|
|
|
|
|
|
|
|
#### parse
|
|
|
|
|
2021-09-22 14:38:13 -07:00
|
|
|
```python
|
2022-01-25 17:07:47 -08:00
|
|
|
def parse(data, raw=False, quiet=False, ignore_exceptions=False)
|
2021-09-22 14:38:13 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
Main text parsing generator function. Returns an iterator object.
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Parameters:
|
2022-01-19 17:30:14 -08:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
data: (iterable) line-based text data to parse
|
|
|
|
(e.g. sys.stdin or str.splitlines())
|
2021-09-22 14:38:13 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
raw: (boolean) unprocessed output if True
|
|
|
|
quiet: (boolean) suppress warning messages if True
|
|
|
|
ignore_exceptions: (boolean) ignore parsing exceptions if True
|
2021-09-22 14:38:13 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Yields:
|
2021-09-22 14:38:13 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Dictionary. Raw or processed structured data.
|
2021-09-22 14:38:13 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Returns:
|
|
|
|
|
|
|
|
Iterator object
|
2021-09-22 14:38:13 -07:00
|
|
|
|
|
|
|
## Parser Information
|
|
|
|
Compatibility: linux
|
|
|
|
|
2021-12-01 16:12:51 -08:00
|
|
|
Version 0.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
|