avg_block_io send alarm to xalarmd

This commit is contained in:
zhuofeng 2024-10-09 15:17:12 +08:00
parent 3830f57e56
commit 066cfe307e
3 changed files with 116 additions and 1 deletions

View File

@ -0,0 +1,73 @@
From 7d5ad8f2dd87432b8f46ea5002400ee46cb6756a Mon Sep 17 00:00:00 2001
From: gaoruoshu <gaoruoshu@huawei.com>
Date: Wed, 9 Oct 2024 14:22:38 +0800
Subject: [PATCH] avg_block_io send alarm to xalarmd
---
config/tasks/avg_block_io.mod | 2 ++
.../sentryPlugins/avg_block_io/module_conn.py | 23 +++++++++++++++----
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/config/tasks/avg_block_io.mod b/config/tasks/avg_block_io.mod
index b9b6f34..bcd063b 100644
--- a/config/tasks/avg_block_io.mod
+++ b/config/tasks/avg_block_io.mod
@@ -3,3 +3,5 @@ enabled=yes
task_start=/usr/bin/python3 /usr/bin/avg_block_io
task_stop=pkill -f /usr/bin/avg_block_io
type=oneshot
+alarm_id=1002
+alarm_clear_time=5
diff --git a/src/python/sentryPlugins/avg_block_io/module_conn.py b/src/python/sentryPlugins/avg_block_io/module_conn.py
index 0da4208..2fc5a83 100644
--- a/src/python/sentryPlugins/avg_block_io/module_conn.py
+++ b/src/python/sentryPlugins/avg_block_io/module_conn.py
@@ -16,6 +16,7 @@ import time
from .utils import is_abnormal
from sentryCollector.collect_plugin import is_iocollect_valid, get_io_data, Result_Messages
from syssentry.result import ResultLevel, report_result
+from xalarm.sentry_notify import xalarm_report, MINOR_ALM, ALARM_TYPE_OCCUR
TASK_NAME = "avg_block_io"
@@ -68,19 +69,33 @@ def process_report_data(disk_name, rw, io_data):
if not is_abnormal((disk_name, 'bio', rw), io_data):
return
+ msg = {"alarm_source": TASK_NAME, "driver_name": disk_name, "io_type": rw}
+
ctrl_stage = ['throtl', 'wbt', 'iocost', 'bfq']
for stage_name in ctrl_stage:
if is_abnormal((disk_name, stage_name, rw), io_data):
- logging.warning("{} - {} - {} report IO press".format(time.ctime(), disk_name, rw))
+ msg["reason"] = "IO press slow"
+ msg["block_stack"] = f"bio,{stage_name}"
+ logging.warning("{} - {} report IO press slow".format(disk_name, rw))
+ xalarm_report(1002, MINOR_ALM, ALARM_TYPE_OCCUR, json.dumps(msg))
return
if is_abnormal((disk_name, 'rq_driver', rw), io_data):
- logging.warning("{} - {} - {} report driver".format(time.ctime(), disk_name, rw))
+ msg["reason"] = "driver slow"
+ msg["block_stack"] = "bio,rq_driver"
+ logging.warning("{} - {} report driver slow".format(disk_name, rw))
+ xalarm_report(1002, MINOR_ALM, ALARM_TYPE_OCCUR, json.dumps(msg))
return
kernel_stage = ['gettag', 'plug', 'deadline', 'hctx', 'requeue']
for stage_name in kernel_stage:
if is_abnormal((disk_name, stage_name, rw), io_data):
- logging.warning("{} - {} - {} report kernel".format(time.ctime(), disk_name, rw))
+ msg["reason"] = "kernel slow"
+ msg["block_stack"] = f"bio,{stage_name}"
+ logging.warning("{} - {} report kernel slow".format(disk_name, rw))
+ xalarm_report(1002, MINOR_ALM, ALARM_TYPE_OCCUR, json.dumps(msg))
return
- logging.warning("{} - {} - {} report IO press".format(time.ctime(), disk_name, rw))
+ msg["reason"] = "unknown"
+ msg["block_stack"] = "bio"
+ logging.warning("{} - {} report UNKNOWN slow".format(disk_name, rw))
+ xalarm_report(1002, MINOR_ALM, ALARM_TYPE_OCCUR, json.dumps(msg))
--
2.33.0

34
bugfix-typo.patch Normal file
View File

@ -0,0 +1,34 @@
From 7d5ad8f2dd87432b8f46ea5002400ee46cb6756a Mon Sep 17 00:00:00 2001
From: gaoruoshu <gaoruoshu@huawei.com>
Date: Wed, 9 Oct 2024 14:22:38 +0800
Subject: [PATCH] bugfix typo
---
src/python/sentryPlugins/avg_block_io/avg_block_io.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/python/sentryPlugins/avg_block_io/avg_block_io.py b/src/python/sentryPlugins/avg_block_io/avg_block_io.py
index b6b3b28..26a60c5 100644
--- a/src/python/sentryPlugins/avg_block_io/avg_block_io.py
+++ b/src/python/sentryPlugins/avg_block_io/avg_block_io.py
@@ -114,7 +114,7 @@ def read_config_lat_iodump(io_dic, config):
common_param = {}
lat_sec = None
if not config.has_section("latency"):
- logging.warning("Cannot find algorithm section in config file")
+ logging.warning("Cannot find latency section in config file")
else:
lat_sec = config["latency"]
@@ -122,7 +122,7 @@ def read_config_lat_iodump(io_dic, config):
if not config.has_section("iodump"):
logging.warning("Cannot find iodump section in config file")
else:
- lat_sec = config["iodump"]
+ iodump_sec = config["iodump"]
if not lat_sec and not iodump_sec:
return common_param
--
2.27.0

View File

@ -4,7 +4,7 @@
Summary: System Inspection Framework Summary: System Inspection Framework
Name: sysSentry Name: sysSentry
Version: 1.0.2 Version: 1.0.2
Release: 22 Release: 23
License: Mulan PSL v2 License: Mulan PSL v2
Group: System Environment/Daemons Group: System Environment/Daemons
Source0: https://gitee.com/openeuler/sysSentry/releases/download/v%{version}/%{name}-%{version}.tar.gz Source0: https://gitee.com/openeuler/sysSentry/releases/download/v%{version}/%{name}-%{version}.tar.gz
@ -34,6 +34,8 @@ Patch21: fix-ai_block_io-some-issues.patch
Patch22: add-pyxalarm-and-pySentryNotify-add-multi-users-supp.patch Patch22: add-pyxalarm-and-pySentryNotify-add-multi-users-supp.patch
Patch23: add-sentryctl-get_alarm-module_name-s-time_range-d.patch Patch23: add-sentryctl-get_alarm-module_name-s-time_range-d.patch
Patch24: fix-python-3.7-not-support-list-bool-type.patch Patch24: fix-python-3.7-not-support-list-bool-type.patch
Patch25: avg_block_io-send-alarm-to-xalarmd.patch
Patch26: bugfix-typo.patch
BuildRequires: cmake gcc-c++ BuildRequires: cmake gcc-c++
BuildRequires: python3 python3-setuptools BuildRequires: python3 python3-setuptools
@ -276,6 +278,12 @@ rm -rf %{buildroot}
%attr(0550,root,root) %{python3_sitelib}/sentryPlugins/ai_block_io %attr(0550,root,root) %{python3_sitelib}/sentryPlugins/ai_block_io
%changelog %changelog
* Wed Oct 9 2024 zhuofeng <zhuofeng2@huawei.com> - 1.0.2-23
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:avg_block_io send alarm to xalarmd
* Wed Oct 9 2024 caixiaomeng <caixiaomeng2@huawei.com> - 1.0.2-22 * Wed Oct 9 2024 caixiaomeng <caixiaomeng2@huawei.com> - 1.0.2-22
- Type:bugfix - Type:bugfix
- CVE:NA - CVE:NA