fix bug: procSched.report: list index out of range

Signed-off-by: weiyaping <weiyaping@xfusion.com>
(cherry picked from commit ed026d30b2ef1a9d841c6648131f915f9d581a08)
This commit is contained in:
weiyaping 2023-12-15 04:36:45 -05:00 committed by openeuler-sync-bot
parent 12c820734a
commit b9aaf76c07
3 changed files with 108 additions and 2 deletions

View File

@ -2,7 +2,7 @@
Name: atune-collector
Version: 1.1.0
Release: 6
Release: 7
Summary: A-Tune-Collector is used to collect various system resources.
License: Mulan PSL v2
URL: https://gitee.com/openeuler/A-Tune-Collector
@ -23,9 +23,11 @@ Patch12: atune-collector-add-backup-for-apps.patch
Patch13: feature-add-network-CPI.patch
Patch14: feature-add-multi-for-rps-xps.patch
Patch15: feature-add-rfs-to-network.patch
Patch16: fix-bug-procsched-report-list-index-out-of-range.patch
Patch17: fix-bug-procsched-data-collection-issue.patch
BuildRequires: python3-setuptools
Requires: python3-dict2xml
Requires: python3-dict2xml python3-werkzeug
%description
The A-Tune-Collector is used to collect various system resources and can also be used as the collector of the A-Tune project.
@ -47,6 +49,9 @@ The A-Tune-Collector is used to collect various system resources and can also be
%attr(0600,root,root) %{_sysconfdir}/atune_collector/*
%changelog
* Fri Dec 15 2023 weiyaping <weiyaping@xfusion.com> - 1.1.0-7
- fix bug: ProcSched.report: list index out of range
* Wed Nov 29 2023 gaoruoshu <gaoruoshu@huawei.com> - 1.1.0-6
- feature: add rfs and rps/xps=multi to [network]

View File

@ -0,0 +1,56 @@
From 43c7e8eb00268570abbaeacbb2689079dddec63d Mon Sep 17 00:00:00 2001
From: weiyaping <weiyaping@xfusion.com>
Date: Fri, 15 Dec 2023 03:50:06 -0500
Subject: [PATCH] fix-bug-procsched-data-collection-issue
---
atune_collector/plugin/monitor/process/sched.py | 27 ++++++++++++++++---------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/atune_collector/plugin/monitor/process/sched.py b/atune_collector/plugin/monitor/process/sched.py
index f184957..0fadeba 100644
--- a/atune_collector/plugin/monitor/process/sched.py
+++ b/atune_collector/plugin/monitor/process/sched.py
@@ -107,7 +107,7 @@ class ProcSched(Monitor):
continue
pattern = re.compile(
- r"(\w+)\ {1,}\:\ {1,}(\d+.\d+)",
+ r"(\w+)\ {1,}\:\ {1,}(\d+\.?\d*)",
re.I | re.UNICODE | re.MULTILINE)
search_obj = pattern.findall(info)
search_list = []
@@ -118,13 +118,20 @@ class ProcSched(Monitor):
search_list.append(obj[0])
search_list.append(obj[1])
if len(search_obj) == 0:
- err = LookupError("Fail to find data")
- LOGGER.error("%s.%s: %s", self.__class__.__name__,
- inspect.stack()[0][3], str(err))
- raise err
+ return " " + " ".join(['0'] * len(keys))
+ proc_data = []
+ proc_keys = 0
+ proc_step = len(set(keys))
- while start <= len(self.__applications) * len(keys):
- for key in keys:
- ret = ret + " " + search_list[search_list.index(key, start)+1]
- start = search_list.index(key, start) + 1
- return ret
\ No newline at end of file
+ for key in keys:
+ if len(proc_data) >= self.__proc_flag.count(True) * proc_step:
+ break
+ proc_data.append(search_list[search_list.index(key, start) + 1])
+ start = search_list.index(key, start) + 1
+ for pid_flag in self.__proc_flag:
+ if not pid_flag:
+ ret = ret + " " + " ".join(['0'] * proc_step)
+ else:
+ ret = ret + " " + " ".join(proc_data[proc_keys:(proc_keys + proc_step)])
+ proc_keys += proc_step
+ return ret
--
1.8.3.1

View File

@ -0,0 +1,45 @@
From 009428bbf8f38bf9754999ec77403c4b181cf8ed Mon Sep 17 00:00:00 2001
From: weiyaping <weiyaping@xfusion.com>
Date: Fri, 15 Dec 2023 03:37:02 -0500
Subject: [PATCH] fix bug:ProcSched.report: list index out of range
---
atune_collector/plugin/monitor/process/sched.py | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/atune_collector/plugin/monitor/process/sched.py b/atune_collector/plugin/monitor/process/sched.py
index 5289d84..f184957 100644
--- a/atune_collector/plugin/monitor/process/sched.py
+++ b/atune_collector/plugin/monitor/process/sched.py
@@ -36,10 +36,12 @@ class ProcSched(Monitor):
self.__interval = 1
self.__applications = []
self.__pids = []
+ self.__proc_flag = []
def _get(self, para=None):
output = ""
pids = []
+ proc_flag = []
if para is not None:
opts, _ = getopt.getopt(para.split(), None, ['interval=', 'app='])
for opt, val in opts:
@@ -67,9 +69,13 @@ class ProcSched(Monitor):
for app in self.__applications:
pid = subprocess.getoutput(
- "ps -A | grep {} | awk '{{print $1}}'".format(app)).split()[0]
- pids.append(pid)
+ "ps -A | grep {} | awk '{{print $1}}'".format(app)).split()
+ app_pid_flag = True if pid else False
+ proc_flag.append(app_pid_flag)
+ if pid:
+ pids.append(pid[0])
self.__pids = pids
+ self.__proc_flag = proc_flag
for pid in self.__pids:
out = subprocess.check_output(
--
1.8.3.1