|
|
@@ -346,8 +346,12 @@ ErrorCodeEnum ResourceWatcherFSM::OnInit()
|
|
|
}
|
|
|
spRunConfig->ReadConfigValueInt("WarnRecord", "disk", m_diskLastWarnHour);
|
|
|
|
|
|
- UploadSysProcInfoTask* uploadProcInfo = new UploadSysProcInfoTask(this);
|
|
|
- GetEntityBase()->GetFunction()->PostThreadPoolTask(uploadProcInfo);
|
|
|
+ int CloseUploadSysProcFlag = 0; //关闭进程信息上送标志
|
|
|
+ spCtSettingConfig->ReadConfigValueInt(m_pEntity->GetEntityName(), "CloseUploadSysProcFlag", CloseUploadSysProcFlag);
|
|
|
+ if (!CloseUploadSysProcFlag) {
|
|
|
+ UploadSysProcInfoTask* uploadProcInfo = new UploadSysProcInfoTask(this);
|
|
|
+ GetEntityBase()->GetFunction()->PostThreadPoolTask(uploadProcInfo);
|
|
|
+ }
|
|
|
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
@@ -3422,6 +3426,17 @@ 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);
|
|
|
@@ -3446,17 +3461,6 @@ 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)
|
|
|
@@ -5157,29 +5161,39 @@ void ResourceWatcherFSM::GetSystemProccess()
|
|
|
}
|
|
|
|
|
|
int len = 0;
|
|
|
- CSimpleStringA startStr = "{";
|
|
|
CSimpleStringA curProcStr = "";
|
|
|
CSimpleStringA endStr = ",";
|
|
|
- CSimpleStringA totalProcStr = "";
|
|
|
+ CSimpleStringA totalProcStr = "{";
|
|
|
+
|
|
|
+ int uploadTime = 0;
|
|
|
+ auto last_it = std::prev(processName.end());
|
|
|
unordered_map<int, CSimpleStringA>::iterator it;
|
|
|
for (it = processName.begin(); it != processName.end(); ++it)
|
|
|
{
|
|
|
//"pid1":"name1"
|
|
|
curProcStr = CSimpleStringA("\"") + to_string(it->first).c_str() + "\":\"" + it->second + "\"";
|
|
|
-
|
|
|
- //{"pid1":"name1", "pid2":"name2", …… 往后一个一个拼接,如果达到长度上限 则把“,” 替换为“ } ”
|
|
|
len = totalProcStr.GetLength() + curProcStr.GetLength();
|
|
|
- if (len >= 1500)
|
|
|
+ if (len > 1000 || it == last_it)
|
|
|
{
|
|
|
endStr = "}";
|
|
|
- totalProcStr = startStr + totalProcStr + endStr;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetSystemProccess")(totalProcStr.GetData());
|
|
|
- //清空进程信息,重新收集
|
|
|
- totalProcStr.Clear();
|
|
|
+ uploadTime++;
|
|
|
+ if (it == last_it)
|
|
|
+ {
|
|
|
+ totalProcStr = totalProcStr + curProcStr + endStr;
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetSystemProccess")(totalProcStr.GetData());
|
|
|
+ totalProcStr = "{";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ totalProcStr[totalProcStr.GetLength() - 1] = '}';
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetSystemProccess")(totalProcStr.GetData());
|
|
|
+ totalProcStr = CSimpleStringA("{") + curProcStr + ","; //超过长度则从当前进程开始重新搭建日志
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- totalProcStr = startStr + totalProcStr + endStr;
|
|
|
+ endStr = ",";
|
|
|
+ totalProcStr = totalProcStr + curProcStr + endStr;
|
|
|
}
|
|
|
|
|
|
}
|