|
@@ -50,29 +50,32 @@ void CGUIConsoleEntity::OnLog(const CAutoArray<CUUID>& SubIDs, const CUUID nLogI
|
|
|
void CGUIConsoleEntity::OnEntityStateHook(const char* pszEntityName, const char* pszTriggerEntity, EntityStateEnum eState, EntityStateEnum eLastState)
|
|
|
{
|
|
|
//did not open log sender
|
|
|
- if (!m_isOpenLogSender)
|
|
|
- return;
|
|
|
-
|
|
|
- LogInfo msg;
|
|
|
- if (eLastState == EntityState_Idle && eState != EntityState_Idle)
|
|
|
- {
|
|
|
- msg.sysError = ErrorCodeEnum::Error_Closed;
|
|
|
- msg.userCode = ErrorCodeEnum::Error_Closed;
|
|
|
- msg.message = CSimpleString::Format("%s实体异常,重新启动...", pszEntityName);
|
|
|
- }
|
|
|
- else
|
|
|
+ if (m_isOpenLogSender)
|
|
|
{
|
|
|
- msg.sysError = ErrorCodeEnum::Error_Succeed;
|
|
|
- msg.userCode = ErrorCodeEnum::Error_Succeed;
|
|
|
- if (eState == EntityState_Starting)
|
|
|
- msg.message = CSimpleString::Format("正在启动实体%s...", pszEntityName);
|
|
|
- else if(eState == EntityState_Idle)
|
|
|
- msg.message = CSimpleString::Format("%s 实体启动成功", pszEntityName);
|
|
|
- }
|
|
|
+ LogInfo msg;
|
|
|
+ if (eLastState == EntityState_Idle && eState != EntityState_Idle)
|
|
|
+ {
|
|
|
+ msg.sysError = ErrorCodeEnum::Error_Closed;
|
|
|
+ msg.userCode = ErrorCodeEnum::Error_Closed;
|
|
|
+ msg.message = CSimpleString::Format("%s实体异常,重新启动...", pszEntityName);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ msg.sysError = ErrorCodeEnum::Error_Succeed;
|
|
|
+ msg.userCode = ErrorCodeEnum::Error_Succeed;
|
|
|
+ if (eState == EntityState_Starting)
|
|
|
+ msg.message = CSimpleString::Format("正在启动实体%s...", pszEntityName);
|
|
|
+ else if (eState == EntityState_Idle)
|
|
|
+ msg.message = CSimpleString::Format("%s 实体启动成功", pszEntityName);
|
|
|
+ }
|
|
|
+
|
|
|
+ msg.timeStr = GenerateTimeStr().c_str();
|
|
|
+ msg.entityName = pszEntityName;
|
|
|
+ SpSendBroadcast(GetFunction(), eMsg_LogInfo, eMsgSig_LogInfo, msg);
|
|
|
+ }
|
|
|
|
|
|
- msg.timeStr = GenerateTimeStr().c_str();
|
|
|
- msg.entityName = pszEntityName;
|
|
|
- SpSendBroadcast(GetFunction(), eMsg_LogInfo, eMsgSig_LogInfo, msg);
|
|
|
+ if (m_isOpenEntityMonitor)
|
|
|
+ PostEntityVary(pszEntityName);//if registered, while entity status changed, send to web
|
|
|
}
|
|
|
|
|
|
|
|
@@ -101,6 +104,9 @@ std::pair<DWORD, std::string> CGUIConsoleEntity::openLogSender(SpReqAnsContext<G
|
|
|
else
|
|
|
m_sendLogType = logType;
|
|
|
auto rc = GetFunction()->SubscribeLog(m_logSubID, this, (LogTypeEnum)m_sendLogType, Severity_None, Error_IgnoreAll, -1, NULL, false);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("openLogSender SubscribeLog %s %s", ctx->Req.LogType.GetData(),
|
|
|
+ (rc == ErrorCodeEnum::Error_Succeed ? "success" : "failed"));
|
|
|
+
|
|
|
m_isOpenLogSender = (rc == ErrorCodeEnum::Error_Succeed);
|
|
|
return std::pair<DWORD, std::string>(rc, "");
|
|
|
}
|
|
@@ -121,98 +127,99 @@ std::pair<DWORD, std::string> CGUIConsoleEntity::closeLogSender()
|
|
|
auto rc = GetFunction()->UnsubscribeLog(m_logSubID);
|
|
|
if(rc == ErrorCodeEnum::Error_Succeed)
|
|
|
m_logSubID = 0;
|
|
|
+
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("closeLogSender UnsubscribeLog %s", (rc == ErrorCodeEnum::Error_Succeed ? "success" : "failed"));
|
|
|
+
|
|
|
m_isOpenLogSender = !(rc == ErrorCodeEnum::Error_Succeed);
|
|
|
return std::pair<DWORD, std::string>(rc, "");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-std::pair<DWORD, std::string> CGUIConsoleEntity::openEntityMonitor()
|
|
|
+std::pair<DWORD, std::string> CGUIConsoleEntity::openEntityMonitor(SpReqAnsContext<GUIConsoleService_OpenEntityMonitor_Req, GUIConsoleService_OpenEntityMonitor_Ans>::Pointer ctx)
|
|
|
{
|
|
|
m_isOpenEntityMonitor = true;
|
|
|
- /*
|
|
|
- timer->stop();
|
|
|
-
|
|
|
- ui->performTableWidget->clearContents();
|
|
|
-
|
|
|
- process->start("/bin/bash");
|
|
|
- if(process->waitForStarted(3000)) {
|
|
|
- process->write(cmd.toLatin1());
|
|
|
- process->closeWriteChannel();
|
|
|
- process->waitForFinished(3000);
|
|
|
- QString result = process->readAllStandardOutput();
|
|
|
- QRegularExpression reg;
|
|
|
- reg.setPattern(" +");
|
|
|
- result = result.replace(reg," ");
|
|
|
- QStringList elemList = result.split("\n");
|
|
|
- elemList.removeFirst();
|
|
|
- elemList.removeLast();
|
|
|
- ui->performTableWidget->setRowCount(elemList.length());
|
|
|
- for(int i=0;i< elemList.length();i++) {
|
|
|
- QString line = elemList.at(i);
|
|
|
- QStringList elems = line.split(" ");
|
|
|
- QString strPID = elems.at(RAW_PID_INDEX);
|
|
|
- bool root = false, related = false;
|
|
|
- for(int j=0; j<ui->performTableWidget->columnCount(); j++) {
|
|
|
- QTableWidgetItem* item = new QTableWidgetItem;
|
|
|
- item->setBackground((i % 2 != 0) ? QColor("#f5f5f5") : QColor("#ffffff"));
|
|
|
- if(j== COLUMN_NAME_INDEX) {
|
|
|
- item->setWhatsThis(strPID);
|
|
|
- line = elems.at(RAW_COMMAND_INDEX);
|
|
|
- if (line.compare("spshell", Qt::CaseInsensitive) == 0
|
|
|
- || line.compare("sphost", Qt::CaseInsensitive) == 0
|
|
|
- || line.compare("cefclient", Qt::CaseInsensitive) == 0
|
|
|
- || line.compare("guardian", Qt::CaseInsensitive) == 0) {
|
|
|
- related = true;
|
|
|
- item->setForeground(QBrush(Qt::red));
|
|
|
-
|
|
|
- if (line.compare("sphost", Qt::CaseInsensitive) == 0 && elems.count() > 7 && elems.at(7).startsWith("mod_")) {
|
|
|
- line = elems.at(7);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- item->setToolTip(line);
|
|
|
- item->setText(line);
|
|
|
- }
|
|
|
- else if (j == COLUMN_PID_INDEX) {
|
|
|
- item->setTextAlignment(Qt::AlignHCenter);
|
|
|
- item->setText(elems.at(RAW_PID_INDEX));
|
|
|
- }
|
|
|
- else if (j == COLUMN_CPU_INDEX) {
|
|
|
- item->setTextAlignment(Qt::AlignHCenter);
|
|
|
- item->setText(elems.at(RAW_CPU_INDEX));
|
|
|
- }
|
|
|
- else if (j == COLUMN_MEM_INDEX) {
|
|
|
- item->setTextAlignment(Qt::AlignHCenter);
|
|
|
- item->setText(elems.at(RAW_MEM_INDEX));
|
|
|
- }
|
|
|
- else if(j== COLUMN_COMMAND_INDEX)
|
|
|
- {
|
|
|
- line = elems.mid(5).join(" ");
|
|
|
- item->setText(line);
|
|
|
- item->setToolTip(line);
|
|
|
- } else if(j == COLUMN_FDS_INDEX) {
|
|
|
- if (related) {
|
|
|
- int fds = GetProcessFdsImpl(pro, strPID.toInt());
|
|
|
- item->setText(QString::number(fds));
|
|
|
- } else {
|
|
|
- item->setText("NA");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- ui->performTableWidget->setItem(i, j, item);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- timer->start();
|
|
|
+ if (ctx->Req.longestFrequence <= 1)
|
|
|
+ m_longestEntityMonitor = 1;
|
|
|
+ else
|
|
|
+ m_longestEntityMonitor = ctx->Req.longestFrequence;
|
|
|
+ if (ctx->Req.leastFrequence <= 1)
|
|
|
+ m_leastEntityMonitor = 1;
|
|
|
+ else
|
|
|
+ m_leastEntityMonitor = ctx->Req.leastFrequence;
|
|
|
+
|
|
|
+ m_entityMonitor_shouldwork = true;
|
|
|
+
|
|
|
+ auto entityMonitorSender = [this] {
|
|
|
+ while (m_isOpenEntityMonitor)
|
|
|
+ {
|
|
|
+ std::unique_lock<std::mutex> guard(m_entityMonitro_lock);
|
|
|
+ m_entityMonitor_cv.wait(guard, [this] {
|
|
|
+ return m_entityMonitor_shouldwork || (std::chrono::steady_clock::now() - m_entityMonitorlast_notify_time >= std::chrono::seconds(m_longestEntityMonitor));
|
|
|
+ });
|
|
|
+
|
|
|
+ m_entityMonitorlast_notify_time = std::chrono::steady_clock::now();
|
|
|
+ m_entityMonitor_shouldwork = false;
|
|
|
+ EntityStatus cur;
|
|
|
+ CAutoArray<EntityEntry> Entities;
|
|
|
+ auto ret = GetAllEntity(Entities);
|
|
|
+ if (ret.first != ErrorCodeEnum::Error_Succeed)
|
|
|
+ {
|
|
|
+ LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_AlreadyExist, WARN_GUICONSOLE_ENTITYMONITOR_GETINFO_FAILED,
|
|
|
+ CSimpleStringA::Format("openEntityMonitor - GetAllEntity failed, %d", ret.first));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ cur.entityName.Init(Entities.GetCount());
|
|
|
+ cur.status.Init(Entities.GetCount());
|
|
|
+ cur.processId.Init(Entities.GetCount());
|
|
|
+ cur.versionNo.Init(Entities.GetCount());
|
|
|
+ cur.lastStartTime.Init(Entities.GetCount());
|
|
|
+
|
|
|
+ for (int i = 0; i < Entities.GetCount(); ++i) {
|
|
|
+ cur.entityName[i] = Entities[i].Name;
|
|
|
+ cur.status[i] = EntityEntry::GetStateName(Entities[i].State);
|
|
|
+ cur.processId[i] = std::to_string(Entities[i].Pid).c_str();
|
|
|
+ cur.versionNo[i] = getRunVersion();
|
|
|
+ cur.lastStartTime[i] = Entities[i].lastStartTime.ToTimeString();
|
|
|
+ }
|
|
|
+
|
|
|
+ SpSendBroadcast(GetFunction(), eMsg_EntityStatus, eMsgSig_EntityStatus, cur);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ std::this_thread::yield();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ if (thread_entityMonitor != NULL)
|
|
|
+ {
|
|
|
+ LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_AlreadyExist, WARN_GUICONSOLE_ENTITYMONITOR_EXISTED,
|
|
|
+ "openEntityMonitor, thread_entityMonitor already existed");
|
|
|
+ return std::pair<DWORD, std::string>(WARN_GUICONSOLE_ENTITYMONITOR_EXISTED, "");
|
|
|
+ }
|
|
|
|
|
|
- */
|
|
|
+ thread_entityMonitor = new std::thread(entityMonitorSender);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("openEntityMonitor create entityMonitor sender thread %s, leastFrequence:%d, m_longestEntityMonitor:%d",
|
|
|
+ (thread_entityMonitor != NULL ? "success" : "failed"), m_leastEntityMonitor, m_longestEntityMonitor);
|
|
|
+
|
|
|
return std::pair<DWORD, std::string>(Error_Succeed, "");
|
|
|
}
|
|
|
|
|
|
std::pair<DWORD, std::string> CGUIConsoleEntity::closeEntityMonitor()
|
|
|
{
|
|
|
m_isOpenEntityMonitor = false;
|
|
|
+
|
|
|
+ if (thread_entityMonitor == NULL)
|
|
|
+ {
|
|
|
+ LogWarn(SeverityLevelEnum::Severity_Middle, ErrorCodeEnum::Error_NotExist, WARN_GUICONSOLE_ENTITYMONITOR_NOTEXISTED,
|
|
|
+ "closeEntityMonitor, thread_entityMonitor not exist");
|
|
|
+ return std::pair<DWORD, std::string>(WARN_GUICONSOLE_ENTITYMONITOR_NOTEXISTED, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ thread_entityMonitor->join();
|
|
|
+ delete thread_entityMonitor;
|
|
|
+ thread_entityMonitor = NULL;
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("closeEntityMonitor close entityMonitor sender thread success");
|
|
|
+
|
|
|
return std::pair<DWORD, std::string>(Error_Succeed, "");
|
|
|
}
|
|
|
|
|
@@ -260,6 +267,9 @@ std::pair<DWORD, std::string> CGUIConsoleEntity::openPerformanceSender(SpReqAnsC
|
|
|
|
|
|
thread_performanceSend = new std::thread(performanceSender);
|
|
|
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("openPerformanceSender create performance sender thread %s, sendFrequence:%d",
|
|
|
+ (thread_performanceSend != NULL ? "success" : "failed"), m_performanceSenderFrequence);
|
|
|
+
|
|
|
return std::pair<DWORD, std::string>(Error_Succeed, "");
|
|
|
}
|
|
|
|
|
@@ -277,6 +287,8 @@ std::pair<DWORD, std::string> CGUIConsoleEntity::closePerformanceSender()
|
|
|
delete thread_performanceSend;
|
|
|
thread_performanceSend = NULL;
|
|
|
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("closePerformanceSender close performance sender thread success");
|
|
|
+
|
|
|
return std::pair<DWORD, std::string>(Error_Succeed, "");
|
|
|
}
|
|
|
|
|
@@ -339,7 +351,8 @@ std::pair<DWORD, std::string> CGUIConsoleEntity::VTM_controlEntity(SpReqAnsConte
|
|
|
|
|
|
CGUIConsoleEntity::CGUIConsoleEntity()
|
|
|
:m_isOpenLogSender(false), m_isOpenEntityMonitor(false), m_isOpenPerformanceSender(false),
|
|
|
- m_sendLogType(LogTypeEnum::Log_Warning), thread_performanceSend(NULL)
|
|
|
+ m_sendLogType(LogTypeEnum::Log_Warning), thread_performanceSend(NULL), thread_entityMonitor(NULL),
|
|
|
+ m_longestEntityMonitor(60), m_leastEntityMonitor(2)
|
|
|
{
|
|
|
}
|
|
|
|
|
@@ -355,59 +368,74 @@ CGUIConsoleEntity::~CGUIConsoleEntity()
|
|
|
thread_performanceSend = NULL;
|
|
|
}
|
|
|
|
|
|
+ if (thread_entityMonitor)
|
|
|
+ {
|
|
|
+ thread_entityMonitor->detach();
|
|
|
+ delete thread_entityMonitor;
|
|
|
+ thread_entityMonitor = NULL;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
void CGUIConsoleSession::Handle_OpenLogSender(SpReqAnsContext<GUIConsoleService_OpenLogSender_Req, GUIConsoleService_OpenLogSender_Ans>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
auto ret = m_pEntity->openLogSender(ctx);
|
|
|
ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
|
|
|
}
|
|
|
|
|
|
void CGUIConsoleSession::Handle_CloseLogSender(SpReqAnsContext<GUIConsoleService_CloseLogSender_Req, GUIConsoleService_CloseLogSender_Ans>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
auto ret = m_pEntity->closeLogSender();
|
|
|
ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
|
|
|
}
|
|
|
|
|
|
void CGUIConsoleSession::Handle_OpenEntityMonitor(SpReqAnsContext<GUIConsoleService_OpenEntityMonitor_Req, GUIConsoleService_OpenEntityMonitor_Ans>::Pointer ctx)
|
|
|
{
|
|
|
- auto ret = m_pEntity->openEntityMonitor();
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
+ auto ret = m_pEntity->openEntityMonitor(ctx);
|
|
|
ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
|
|
|
}
|
|
|
|
|
|
void CGUIConsoleSession::Handle_CloseEntityMonitor(SpReqAnsContext<GUIConsoleService_CloseEntityMonitor_Req, GUIConsoleService_CloseEntityMonitor_Ans>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
auto ret = m_pEntity->closeEntityMonitor();
|
|
|
ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
|
|
|
}
|
|
|
|
|
|
void CGUIConsoleSession::Handle_OpenPerformanceSender(SpReqAnsContext<GUIConsoleService_OpenPerformanceSender_Req, GUIConsoleService_OpenPerformanceSender_Ans>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
auto ret = m_pEntity->openPerformanceSender(ctx);
|
|
|
ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
|
|
|
}
|
|
|
|
|
|
void CGUIConsoleSession::Handle_ClosePerformanceSender(SpReqAnsContext<GUIConsoleService_ClosePerformanceSender_Req, GUIConsoleService_ClosePerformanceSender_Ans>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
auto ret = m_pEntity->closePerformanceSender();
|
|
|
ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
|
|
|
}
|
|
|
|
|
|
void CGUIConsoleSession::Handle_VTMSystemControl(SpReqAnsContext<GUIConsoleService_VTMSystemControl_Req, GUIConsoleService_VTMSystemControl_Ans>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
auto ret = m_pEntity->VTMSystemControl(ctx);
|
|
|
ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
|
|
|
}
|
|
|
|
|
|
void CGUIConsoleSession::Handle_VTM_controlEntity(SpReqAnsContext<GUIConsoleService_VTM_controlEntity_Req, GUIConsoleService_VTM_controlEntity_Ans>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
auto ret = m_pEntity->VTM_controlEntity(ctx);
|
|
|
ctx->Answer((ErrorCodeEnum)ret.first, (ErrorCodeEnum)ret.first);
|
|
|
}
|
|
|
|
|
|
void CGUIConsoleSession::Handle_GetAllEntityList(SpReqAnsContext<GUIConsoleService_GetAllEntityList_Req, GUIConsoleService_GetAllEntityList_Ans>::Pointer ctx)
|
|
|
{
|
|
|
+ DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
CAutoArray<EntityEntry> Entities;
|
|
|
auto ret = m_pEntity->GetAllEntity(Entities);
|
|
|
if (ret.first != ErrorCodeEnum::Error_Succeed)
|
|
@@ -572,6 +600,7 @@ ErrorCodeEnum CGUIConsoleEntity::GetEntity(const char* entity_name, EntityEntry&
|
|
|
|
|
|
void CGUIConsoleEntity::PostEntityVary(const char* entity_name)
|
|
|
{
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("PostEntityVary %s ", entity_name);
|
|
|
EntityEntry ret;
|
|
|
DWORD rc;
|
|
|
if (ErrorCodeEnum::Error_Succeed != (rc = GetEntity(entity_name, ret)))
|
|
@@ -581,6 +610,21 @@ void CGUIConsoleEntity::PostEntityVary(const char* entity_name)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ auto now = std::chrono::steady_clock::now();
|
|
|
+ if (now - m_entityMonitorlast_notify_time < std::chrono::seconds(m_leastEntityMonitor)) {
|
|
|
+ return; // m_leastEntityMonitor seconds not passed, ignore this notification
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ std::lock_guard<std::mutex> guard(m_entityMonitro_lock);
|
|
|
+ m_entityMonitor_shouldwork = true;
|
|
|
+ }//release lock this time
|
|
|
+
|
|
|
+
|
|
|
+ m_entityMonitor_cv.notify_one();
|
|
|
+
|
|
|
+ /*
|
|
|
EntityStatus cur;
|
|
|
cur.entityName = entity_name;
|
|
|
cur.status = EntityEntry::GetStateName(ret.State);
|
|
@@ -588,6 +632,7 @@ void CGUIConsoleEntity::PostEntityVary(const char* entity_name)
|
|
|
cur.versionNo = getRunVersion();
|
|
|
cur.lastStartTime = ret.lastStartTime.ToTimeString();
|
|
|
SpSendBroadcast(GetFunction(), eMsg_EntityStatus, eMsgSig_EntityStatus, cur);
|
|
|
+ */
|
|
|
}
|
|
|
|
|
|
|