From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- src/pybind/mgr/iostat/__init__.py | 2 ++ src/pybind/mgr/iostat/module.py | 62 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/pybind/mgr/iostat/__init__.py create mode 100644 src/pybind/mgr/iostat/module.py (limited to 'src/pybind/mgr/iostat') diff --git a/src/pybind/mgr/iostat/__init__.py b/src/pybind/mgr/iostat/__init__.py new file mode 100644 index 000000000..ee85dc9d3 --- /dev/null +++ b/src/pybind/mgr/iostat/__init__.py @@ -0,0 +1,2 @@ +# flake8: noqa +from .module import Module diff --git a/src/pybind/mgr/iostat/module.py b/src/pybind/mgr/iostat/module.py new file mode 100644 index 000000000..b101094ab --- /dev/null +++ b/src/pybind/mgr/iostat/module.py @@ -0,0 +1,62 @@ +from typing import Any + +from mgr_module import CLIReadCommand, HandleCommandResult, MgrModule + + +class Module(MgrModule): + def __init__(self, *args: Any, **kwargs: Any) -> None: + super().__init__(*args, **kwargs) + + def self_test(self) -> None: + r = self.get('io_rate') + assert 'pg_stats_delta' in r + assert 'stamp_delta' in r['pg_stats_delta'] + assert 'stat_sum' in r['pg_stats_delta'] + assert 'num_read_kb' in r['pg_stats_delta']['stat_sum'] + assert 'num_write_kb' in r['pg_stats_delta']['stat_sum'] + assert 'num_write' in r['pg_stats_delta']['stat_sum'] + assert 'num_read' in r['pg_stats_delta']['stat_sum'] + + @CLIReadCommand('iostat', poll=True) + def iostat(self, width: int = 80, print_header: bool = False) -> HandleCommandResult: + """ + Get IO rates + """ + rd = 0 + wr = 0 + total = 0 + rd_ops = 0 + wr_ops = 0 + total_ops = 0 + ret = '' + + r = self.get('io_rate') + + stamp_delta = int(float(r['pg_stats_delta']['stamp_delta'])) + if stamp_delta > 0: + rd = r['pg_stats_delta']['stat_sum']['num_read_kb'] // stamp_delta + wr = r['pg_stats_delta']['stat_sum']['num_write_kb'] // stamp_delta + # The values are in kB, but to_pretty_iec() requires them to be in bytes + rd = rd << 10 + wr = wr << 10 + total = rd + wr + + rd_ops = r['pg_stats_delta']['stat_sum']['num_read'] // stamp_delta + wr_ops = r['pg_stats_delta']['stat_sum']['num_write'] // stamp_delta + total_ops = rd_ops + wr_ops + + if print_header: + elems = ['Read', 'Write', 'Total', 'Read IOPS', 'Write IOPS', 'Total IOPS'] + ret += self.get_pretty_header(elems, width) + + elems = [ + self.to_pretty_iec(rd) + 'B/s', + self.to_pretty_iec(wr) + 'B/s', + self.to_pretty_iec(total) + 'B/s', + str(rd_ops), + str(wr_ops), + str(total_ops) + ] + ret += self.get_pretty_row(elems, width) + + return HandleCommandResult(stdout=ret) -- cgit v1.2.3