Commit 010be9bd authored by Pavel Vainerman's avatar Pavel Vainerman

(LogServer): добавил получение информации о текущем состоянии

в формате json (для http api)
parent 61c03c90
......@@ -574,9 +574,9 @@ nlohmann::json <xsl:value-of select="$CLASSNAME"/>_SK::httpGet( const Poco::URI:
jdata["LogServer"] = {
{"host",logserv_host},
{"port",logserv_port},
{"state",( logserv->isRunning() ? "RUNNIG" : "STOPPED" )}
{"state",( logserv->isRunning() ? "RUNNIG" : "STOPPED" )},
{"info", logserv->httpGetShortInfo() }
};
// logserv->getShortInfo()
}
else
jdata["LogServer"] = {};
......
......@@ -3,7 +3,7 @@
ulimit -Sc 1000000
uniset2-start.sh -f ./test --name TestProc --confile test.xml --ulog-add-levels system,warn,crit \
--test-sm-ready-timeout 15000 --test-run-logserver --test-logserver-host 192.192.192.192 $*
--test-sm-ready-timeout 15000 --test-run-logserver $*
#--test-log-add-levels any $*
#info,warn,crit,system,level9 > 1.log
......
......@@ -29,6 +29,7 @@
#include "UTCPSocket.h"
#include "CommonEventLoop.h"
#include "LogServerTypes.h"
#include "json.hpp"
// -------------------------------------------------------------------------
class LogSession;
class LogAgregator;
......@@ -120,6 +121,7 @@ class LogServer:
static std::string help_print( const std::string& prefix );
std::string getShortInfo();
nlohmann::json httpGetShortInfo();
protected:
LogServer();
......
......@@ -27,6 +27,7 @@
#include "UTCPCore.h"
#include "UTCPStream.h"
#include "LogAgregator.h"
#include "json.hpp"
// -------------------------------------------------------------------------
/*! Реализация "сессии" для клиентов LogServer. */
class LogSession
......@@ -76,6 +77,7 @@ class LogSession
bool isAcive() const noexcept;
std::string getShortInfo() noexcept;
nlohmann::json httpGetShortInfo();
std::string name() const noexcept;
......
......@@ -343,6 +343,25 @@ string LogServer::getShortInfo()
return std::move(inf.str());
}
// -----------------------------------------------------------------------------
nlohmann::json LogServer::httpGetShortInfo()
{
nlohmann::json jdata;
jdata["name"] = myname;
jdata["host"] = addr;
jdata["port"] = port;
jdata["sessMaxCount"] = sessMaxCount;
{
uniset_rwmutex_rlock l(mutSList);
auto& jsess = jdata["sessions"];
for( const auto& s : slist )
jsess.push_back(s->httpGetShortInfo());
}
return std::move(jdata);
}
// -----------------------------------------------------------------------------
void LogServer::saveDefaultLogLevels( const std::string& logname )
{
if( mylog.is_info() )
......
......@@ -674,6 +674,29 @@ string LogSession::getShortInfo() noexcept
return std::move(inf.str());
}
// ---------------------------------------------------------------------
nlohmann::json LogSession::httpGetShortInfo()
{
nlohmann::json jret;
size_t sz = 0;
{
std::unique_lock<std::mutex> lk(logbuf_mutex);
sz = logbuf.size();
}
auto& jdata = jret[caddr];
jdata["client"] = caddr;
jdata["maxbufsize"] = maxRecordsNum;
jdata["bufsize"] = sz;
jdata["maxCount"] = maxCount;
jdata["minSizeMsg"] = minSizeMsg;
jdata["maxSizeMsg"] = maxSizeMsg;
jdata["numLostMsg"] = numLostMsg;
return std::move(jret);
}
// ---------------------------------------------------------------------
string LogSession::name() const noexcept
{
return caddr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment