瀏覽代碼

Z991239-6348 #comment feat: 根据不同终态上送信息

陈纪林80310970 3 月之前
父節點
當前提交
b4306db7a1

+ 56 - 53
Module/mod_ResourceWatcher/ResourceWatcherFSM.cpp

@@ -7,7 +7,6 @@
 #include <algorithm>
 #include "fileutil.h"
 #include <ctime>
-#include "CommEntityUtil.hpp"
 #include "SpUtility.h"
 #include "RestfulFunc.h"
 #include <stdio.h>
@@ -95,6 +94,10 @@ bool cmp(const pair<int, double>& a, const pair<int, double>& b) {
     return a.second > b.second;
 }
 
+bool cmpPid(const pair<int, CSimpleStringA>& a, const pair<int, CSimpleStringA>& b) {
+    return a.first < b.first;
+}
+
 #if defined(RVC_OS_WIN)
 //https://blog.csdn.net/aflyeaglenku/article/details/51742820
 typedef struct _dmi_header
@@ -260,9 +263,9 @@ bool ResourceWatcherFSM::GetSysActiveStatus(CSimpleStringA& outInfo)
 //首页状态变化时触发的功能
 void ResourceWatcherFSM::TriggerAtStatusChanged(bool bMStatus)
 {
-    if (firstMpage)//首次进入首页
+    if (neverMainPage)//首次进入首页
     {
-        firstMpage = false;
+        neverMainPage = false;
 
         CSmartPointer<IConfigInfo> spRunConfig;
         CSmartPointer<IConfigInfo> spCtSettingConfig;
@@ -315,9 +318,21 @@ void ResourceWatcherFSM::TriggerAtStatusChanged(bool bMStatus)
     }
 }
 
+void ResourceWatcherFSM::TriggerProccessUpload()
+{
+    CSmartPointer<IConfigInfo> spCtSettingConfig;
+    GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
+    int CloseUploadSysProcFlag = 0; //关闭进程信息上送标志
+    spCtSettingConfig->ReadConfigValueInt(m_pEntity->GetEntityName(), "CloseUploadSysProcFlag", CloseUploadSysProcFlag);
+    if (CloseUploadSysProcFlag != 1) {
+        UploadSysProcInfoTask* uploadProcInfo = new UploadSysProcInfoTask(this);
+        GetEntityBase()->GetFunction()->PostThreadPoolTask(uploadProcInfo);
+    }
+}
+
 ErrorCodeEnum ResourceWatcherFSM::OnInit()
 {
-    firstMpage = true;		//是否首次进入首页
+    neverMainPage = true;		//是否未进入过首页
 
     ErrorCodeEnum erroCode = Error_Succeed;
     DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Complied at: %s %s", __DATE__, __TIME__);
@@ -346,13 +361,6 @@ ErrorCodeEnum ResourceWatcherFSM::OnInit()
     }
     spRunConfig->ReadConfigValueInt("WarnRecord", "disk", m_diskLastWarnHour);
 
-    int CloseUploadSysProcFlag = 0; //关闭进程信息上送标志
-    spCtSettingConfig->ReadConfigValueInt(m_pEntity->GetEntityName(), "CloseUploadSysProcFlag", CloseUploadSysProcFlag);
-    if (!CloseUploadSysProcFlag) {
-        UploadSysProcInfoTask* uploadProcInfo = new UploadSysProcInfoTask(this);
-        GetEntityBase()->GetFunction()->PostThreadPoolTask(uploadProcInfo);
-    }
-
     return Error_Succeed;
 }
 
@@ -3426,17 +3434,6 @@ void ResourceWatcherFSM::GetSystemCPUStatus()
     }
     CloseHandle(hProcessSnapNew);
 
-    //终端进程名称转换
-    CSystemRunInfo runInfo = { 0 };
-    GetEntityBase()->GetFunction()->GetSystemRunInfo(runInfo);
-    for (int i = 0; i < runInfo.strRunningEntityNames.GetCount(); i++) //实体进程的名称默认全为sphost,需转换为对应实体名
-    {
-        runInfo.strRunningEntityNames[i];
-        CEntityRunInfo entityInfo = { 0 };
-        GetEntityBase()->GetFunction()->GetEntityRunInfo(runInfo.strRunningEntityNames[i].GetData(), entityInfo);
-        processName[entityInfo.dwProcessID] = runInfo.strRunningEntityNames[i];
-    }
-
     long long idle = CompareFileTime2(preIdleTime, idleTime);
     long long kernel = CompareFileTime2(preKernelTime, kernelTime);
     long long user = CompareFileTime2(preUserTime, userTime);
@@ -3461,6 +3458,17 @@ void ResourceWatcherFSM::GetSystemCPUStatus()
         cpuWarnTime = cpuWarnTime % cpuWarnThreshold;
         if (cpuWarnTime == 0) //CPU使用率过高达到一定次数告警一次
         {
+            //终端进程名称转换
+            CSystemRunInfo runInfo = { 0 };
+            GetEntityBase()->GetFunction()->GetSystemRunInfo(runInfo);
+            for (int i = 0; i < runInfo.strRunningEntityNames.GetCount(); i++) //实体进程的名称默认全为sphost,需转换为对应实体名
+            {
+                runInfo.strRunningEntityNames[i];
+                CEntityRunInfo entityInfo = { 0 };
+                GetEntityBase()->GetFunction()->GetEntityRunInfo(runInfo.strRunningEntityNames[i].GetData(), entityInfo);
+                processName[entityInfo.dwProcessID] = runInfo.strRunningEntityNames[i];
+            }
+
             //进程占用率计算
             unordered_map<int, long long>::iterator it;
             for (it = newProcessTime.begin(); it != newProcessTime.end(); ++it)
@@ -4872,32 +4880,6 @@ void ResourceWatcherFSM::GetSystemCPUStatus()
         processCpu[tPid] = tRatio;
     }
 
-    CSystemRunInfo runInfo = { 0 };
-    GetEntityBase()->GetFunction()->GetSystemRunInfo(runInfo);
-
-    for (int i = 0; i < runInfo.strRunningEntityNames.GetCount(); i++) //实体进程的名称默认全为sphost,需转换为对应实体名
-    {
-        CSimpleStringA entityName = runInfo.strRunningEntityNames[i].GetData();
-        CEntityRunInfo entityInfo = { 0 };
-        GetEntityBase()->GetFunction()->GetEntityRunInfo(entityName.GetData(), entityInfo);
-        processName[entityInfo.dwProcessID] = entityName;
-    }
-
-    vector<pair<int, double>> vec(processCpu.begin(), processCpu.end());
-    sort(vec.begin(), vec.end(), cmp); //根据CPU使用率从大到小进行排序
-
-    int cpuTop = 10;
-    int len = MIN(cpuTop, vec.size()); //确认要展示的进程数量
-    CSimpleStringA procWarn = "";
-    for (int i = 0; i < len; ++i) //构建进程的CPU使用告警信息
-    {
-        char* tUsage = new char[20];
-        sprintf(tUsage, "%.2lf", vec[i].second);
-        procWarn = procWarn + ",\"" + processName[vec[i].first] + "\":\"" + tUsage + "%\"";
-
-        delete tUsage;
-    }
-
     unsigned long oldInfo, newInfo;
     double cUsedRate = 0;
 
@@ -4924,6 +4906,32 @@ void ResourceWatcherFSM::GetSystemCPUStatus()
         cpuWarnTime = cpuWarnTime % cpuWarnThreshold;
         if (cpuWarnTime == 0) //每达到一次阈值告警一次
         {
+            CSystemRunInfo runInfo = { 0 };
+            GetEntityBase()->GetFunction()->GetSystemRunInfo(runInfo);
+
+            for (int i = 0; i < runInfo.strRunningEntityNames.GetCount(); i++) //实体进程的名称默认全为sphost,需转换为对应实体名
+            {
+                CSimpleStringA entityName = runInfo.strRunningEntityNames[i].GetData();
+                CEntityRunInfo entityInfo = { 0 };
+                GetEntityBase()->GetFunction()->GetEntityRunInfo(entityName.GetData(), entityInfo);
+                processName[entityInfo.dwProcessID] = entityName;
+            }
+
+            vector<pair<int, double>> vec(processCpu.begin(), processCpu.end());
+            sort(vec.begin(), vec.end(), cmp); //根据CPU使用率从大到小进行排序
+
+            int cpuTop = 10;
+            int len = MIN(cpuTop, vec.size()); //确认要展示的进程数量
+            CSimpleStringA procWarn = "";
+            for (int i = 0; i < len; ++i) //构建进程的CPU使用告警信息
+            {
+                char* tUsage = new char[20];
+                sprintf(tUsage, "%.2lf", vec[i].second);
+                procWarn = procWarn + ",\"" + processName[vec[i].first] + "\":\"" + tUsage + "%\"";
+
+                delete tUsage;
+            }
+
             stringstream tss;
             tss << std::setiosflags(std::ios::fixed) << std::setprecision(2) << cUsedRate * 100;
 
@@ -5152,11 +5160,6 @@ void ResourceWatcherFSM::ConfirmWindowEffectHasBeenOpen()
 }
 #endif // RVC_OS_LINUX
 
-
-bool cmpPid(const pair<int, CSimpleStringA>& a, const pair<int, CSimpleStringA>& b) {
-    return a.first < b.first;
-}
-
 void ResourceWatcherFSM::GetSystemProccess()
 {
     if(processName.empty())

+ 27 - 4
Module/mod_ResourceWatcher/ResourceWatcherFSM.h

@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "SpFSM.h"
+#include "CommEntityUtil.hpp"
 
 #define JUS_A_TEST 0
 #include "FileInfo.h"
@@ -236,6 +237,7 @@ public:
 
 	//进入首页时触发的功能在此
 	void TriggerAtStatusChanged(bool bMStatus);
+	void TriggerProccessUpload();
 
 	void AfterInit();
 
@@ -289,7 +291,7 @@ private:
 	int m_cpuHighPercent, m_memHighPercent, m_diskHighPercent;
 
     BOOL checkActiveBefore;
-	BOOL firstMpage;
+	BOOL neverMainPage;
 	BOOL forceFileOpt;
 
 	std::vector<std::string> keyUserlist;
@@ -316,6 +318,7 @@ public:
 		SpReqAnsContext<ResourceWatcherService_GetBizLinks_Req,
 		ResourceWatcherService_GetBizLinks_Ans>::Pointer ctx);
 
+	bool GetNeverMainPageFlag() { return neverMainPage; } //是否未进过首页
 	void GetSystemProccess();
 	void GetSystemCPUStatus();
 	void GetSystemMemoryStatus();
@@ -534,14 +537,34 @@ struct CheckDiskFileSpaceTask : public ITaskSp
 	}
 };
 
-//获取系统进程并上送
+//获取系统进程并上送, TerminalStage的值为 A, C, M, S触发
 struct UploadSysProcInfoTask : public ITaskSp
 {
 	ResourceWatcherFSM* m_pFSM;
 	UploadSysProcInfoTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
 	void Process()
 	{
-		m_pFSM->GetSystemCPUStatus();
-		m_pFSM->GetSystemProccess();
+		CSimpleStringA t_terminalState;
+		m_pFSM->GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", t_terminalState);
+		if (t_terminalState == "A") // A 准入成功后判断是否进首页
+		{
+			DWORD elapsed = 0;
+			DWORD dwStart = SP::Module::Comm::RVCGetTickCount();
+			DWORD dwEnd = SP::Module::Comm::RVCGetTickCount();
+			DWORD checkTimeOut = 5 * 60000; //五分钟超时
+			while (elapsed < checkTimeOut && m_pFSM->GetNeverMainPageFlag()) //准入成功,5分钟未进首页 or 成功进入首页跳出循环
+			{
+				Sleep(1000);
+				dwEnd = SP::Module::Comm::RVCGetTickCount();
+				elapsed = dwEnd - dwStart;
+			}
+			m_pFSM->GetSystemCPUStatus();
+			m_pFSM->GetSystemProccess();
+		}
+		else // C, M, S  准入失败时触发
+		{
+			m_pFSM->GetSystemCPUStatus();
+			m_pFSM->GetSystemProccess();
+		}
 	}
 };

+ 11 - 0
Module/mod_ResourceWatcher/mod_ResourceWatcher.h

@@ -86,6 +86,7 @@ public:
 			m_fsm.TriggerAtStatusChanged(true);
 		}
 		spEntityFunction->RegistSysVarEvent("UIState", this);
+		spEntityFunction->RegistSysVarEvent("terminalStage", this);
 
 		CSmartPointer<IConfigInfo> spCtSettingConfig;
 		GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
@@ -219,6 +220,16 @@ public:
 		if ((_strnicmp(pszKey, "UIState", strlen("UIState")) == 0)) {
 			m_fsm.TriggerAtStatusChanged(_strnicmp(pszValue, "M", strlen("M")) == 0);
 		}
+		else if ((_strnicmp(pszKey, "terminalStage", strlen("terminalStage")) == 0)) {
+			if (0 == CSimpleStringA("C").Compare(pszValue, true)
+				|| 0 == CSimpleStringA("S").Compare(pszValue, true)
+				|| 0 == CSimpleStringA("M").Compare(pszValue, true)
+				|| 0 == CSimpleStringA("A").Compare(pszValue, true)
+				)
+			{
+				m_fsm.TriggerProccessUpload();
+			}
+		}
 	}
 private: