Skip to content

Commit

Permalink
Merge branch 'master' into release/2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanshudong committed Mar 4, 2021
2 parents 480a26f + 2ff3fbd commit 6315a44
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
39 changes: 35 additions & 4 deletions NodeServer/NodeImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,14 @@ int NodeImp::getLogData(const string& application, const string& serverName, con

NODE_LOG(serverId)->debug() << "[NodeImp::getLogData] newcmd:" << newCmd << endl;

fileData = TC_Port::exec(newCmd.c_str());
string errstr;
fileData = TC_Port::exec(newCmd.c_str(), errstr);
if (fileData.empty()) {
if (!errstr.empty()) {
fileData = errstr;
NODE_LOG(serverId)->error() << errstr << endl;
}
}

// #if TARGET_PLATFORM_WINDOWS

Expand Down Expand Up @@ -939,7 +946,15 @@ int NodeImp::getNodeLoad(const string& application, const string& serverName, in
#else
string cmd = "top -c -bw 160 -n 1 -o '%CPU' -o '%MEM'";

fileData = TC_Port::exec(cmd.c_str());
string errstr;
fileData = TC_Port::exec(cmd.c_str(), errstr);
if (fileData.empty()) {
if (!errstr.empty()) {
fileData = errstr;
NODE_LOG(serverId)->error() << errstr << endl;
}
}

// FILE* fpTop = popen(cmd.c_str(), "r");
// char buf[1 * 1024 * 1024] = { 0 };
// fread(buf, sizeof(char), sizeof(buf)-1, fpTop);
Expand All @@ -957,7 +972,15 @@ int NodeImp::getNodeLoad(const string& application, const string& serverName, in
fileData += "\n\n";
fileData += "#this-top-begin#" + string(100, '-');
fileData += "\n";
fileData += TC_Port::exec(cmd.c_str());

errstr.clear();
fileData += TC_Port::exec(cmd.c_str(), errstr);
if (fileData.empty()) {
if (!errstr.empty()) {
fileData += errstr;
NODE_LOG(serverId)->error() << errstr << endl;
}
}
// fileData += string(buf);
fileData += "#this-top-end#";
}
Expand All @@ -970,7 +993,15 @@ int NodeImp::getNodeLoad(const string& application, const string& serverName, in
fileData += "\n\n";
fileData += "#core-file-begin#" + string(100, '-');
fileData += "\n";
fileData = TC_Port::exec(cmd.c_str());

errstr.clear();
fileData = TC_Port::exec(cmd.c_str(), errstr);
if (fileData.empty()) {
if (!errstr.empty()) {
fileData = errstr;
NODE_LOG(serverId)->error() << errstr << endl;
}
}
// fileData += string(buf);

NODE_LOG(serverId)->debug() << fileData << endl;
Expand Down
10 changes: 9 additions & 1 deletion NodeServer/PlatformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ LoadInfo PlatformInfo::getLoadInfo()
// info.avg15 = static_cast<float>( loadAvg[2] );
}
#else
string data = TC_Port::exec("wmic cpu get loadpercentage");
string errstr;
string data = TC_Port::exec("wmic cpu get loadpercentage", errstr);
if (data.empty()) {
if (!errstr.empty()) {
TLOGERROR(errstr << endl);
return info;
}
}

vector<string> v = TC_Common::sepstr<string>(data, "\n");
for(auto s : v)
{
Expand Down

0 comments on commit 6315a44

Please sign in to comment.