From 668a61c3892014038a8f610b0affa8ecf33387f0 Mon Sep 17 00:00:00 2001 From: David Hill Date: Fri, 16 Nov 2018 11:04:08 -0600 Subject: [PATCH] MCOL-1875 - fixed issue with calulating module cpu usage --- oamapps/serverMonitor/cpuMonitor.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/oamapps/serverMonitor/cpuMonitor.cpp b/oamapps/serverMonitor/cpuMonitor.cpp index 49d01ec3f..c9d458a4f 100644 --- a/oamapps/serverMonitor/cpuMonitor.cpp +++ b/oamapps/serverMonitor/cpuMonitor.cpp @@ -556,7 +556,7 @@ void ServerMonitor::getCPUdata() string tmpsystemCpu = tmpDir + "/processCpu"; - cmd = "top -b -n 6 -d 1 | awk '{print $5}' | grep %id > " + tmpsystemCpu; + cmd = "top -b -n 6 -d 1 | grep '%Cpu' | awk '{print $8}' > " + tmpsystemCpu; system(cmd.c_str()); ifstream oldFile (tmpsystemCpu.c_str()); @@ -569,13 +569,17 @@ void ServerMonitor::getCPUdata() while (oldFile.getline(line, 400)) { string buf = line; - string::size_type pos = buf.find ('%', 0); - - if (pos != string::npos) + string::size_type pos = buf.find ('id,', 0); + if (pos == string::npos) { systemIdle = systemIdle + atol(buf.substr(0, pos - 1).c_str()); count++; } + else + { + systemIdle = systemIdle + 100; + count++; + } } oldFile.close();