Commit 10b40d03 authored by Pavel Vainerman's avatar Pavel Vainerman

(IOC): добавил возможность выводить статистику в getInfo()

по датчику или по "заказчику"
parent 2f34b787
...@@ -340,6 +340,7 @@ namespace uniset ...@@ -340,6 +340,7 @@ namespace uniset
void showStatisticsForLostConsumers( std::ostringstream& inf ); void showStatisticsForLostConsumers( std::ostringstream& inf );
void showStatisticsForConsusmers( std::ostringstream& inf ); void showStatisticsForConsusmers( std::ostringstream& inf );
void showStatisticsForConsumersWithLostEvent( std::ostringstream& inf ); void showStatisticsForConsumersWithLostEvent( std::ostringstream& inf );
void showStatisticsForSensor( std::ostringstream& inf, const std::string& name );
private: private:
friend class NCRestorer; friend class NCRestorer;
......
...@@ -80,6 +80,12 @@ void IONotifyController::showStatisticsForConsumer( ostringstream& inf, const st ...@@ -80,6 +80,12 @@ void IONotifyController::showStatisticsForConsumer( ostringstream& inf, const st
{ {
ObjectId consumer_id = uniset_conf()->getObjectID(consumer); ObjectId consumer_id = uniset_conf()->getObjectID(consumer);
if( consumer_id == DefaultObjectId ) if( consumer_id == DefaultObjectId )
consumer_id = uniset_conf()->getControllerID(consumer);
if( consumer_id == DefaultObjectId )
consumer_id = uniset_conf()->getServiceID(consumer);
if( consumer_id == DefaultObjectId )
{ {
inf << "not found consumer '" << consumer << "'" << endl; inf << "not found consumer '" << consumer << "'" << endl;
return; return;
...@@ -196,6 +202,11 @@ void IONotifyController::showStatisticsForLostConsumers( ostringstream& inf ) ...@@ -196,6 +202,11 @@ void IONotifyController::showStatisticsForLostConsumers( ostringstream& inf )
return; return;
} }
inf << "Statisctic for consumer with lost event:"
<< endl
<< "----------------------------------------"
<< endl;
auto oind = uniset_conf()->oind; auto oind = uniset_conf()->oind;
for( const auto& l : lostConsumers ) for( const auto& l : lostConsumers )
{ {
...@@ -275,6 +286,7 @@ void IONotifyController::showStatisticsForConsumersWithLostEvent( ostringstream& ...@@ -275,6 +286,7 @@ void IONotifyController::showStatisticsForConsumersWithLostEvent( ostringstream&
empty = false; empty = false;
// выводим тех у кого lostEvent>0 // выводим тех у кого lostEvent>0
inf << "(" << setw(6) << a.first << ")[" << oind->getMapName(a.first) << "]" << endl; inf << "(" << setw(6) << a.first << ")[" << oind->getMapName(a.first) << "]" << endl;
inf << "--------------------------------------------------------------------" << endl;
for( const auto& c : i.clst ) for( const auto& c : i.clst )
{ {
...@@ -294,6 +306,54 @@ void IONotifyController::showStatisticsForConsumersWithLostEvent( ostringstream& ...@@ -294,6 +306,54 @@ void IONotifyController::showStatisticsForConsumersWithLostEvent( ostringstream&
if( empty ) if( empty )
inf << "...not found consumers with lost event..." << endl; inf << "...not found consumers with lost event..." << endl;
else
inf << "--------------------------------------------------------------------" << endl;
}
// ------------------------------------------------------------------------------------------
void IONotifyController::showStatisticsForSensor( ostringstream& inf, const string& name )
{
auto conf = uniset_conf();
auto oind = conf->oind;
ObjectId sid = conf->getSensorID(name);
if( sid == DefaultObjectId )
{
inf << "..not found ID for sensor '" << name << "'" << endl;
return;
}
ConsumerListInfo* clist = nullptr;
{
uniset_rwmutex_rlock lock(askIOMutex);
auto s = askIOList.find(sid);
if( s == askIOList.end() )
{
inf << "..not found consumers for sensor '" << name << "'" << endl;
return;
}
clist = &(s->second);
}
inf << "Statisctic for sensor "
<< "(" << setw(6) << sid << ")[" << name << "]: " << endl
<< "--------------------------------------------------------------------" << endl;
uniset_rwmutex_rlock lock2(clist->mut);
for( const auto& c: clist->clst )
{
inf << " (" << setw(6) << c.id << ")"
<< setw(35) << ORepHelpers::getShortName(oind->getMapName(c.id))
<< " ["
<< " lostEvents=" << c.lostEvents
<< " attempt=" << c.attempt
<< " smCount=" << c.smCount
<< "]"
<< endl;
}
inf << "--------------------------------------------------------------------" << endl;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
SimpleInfo* IONotifyController::getInfo( const char* userparam ) SimpleInfo* IONotifyController::getInfo( const char* userparam )
...@@ -323,7 +383,7 @@ SimpleInfo* IONotifyController::getInfo( const char* userparam ) ...@@ -323,7 +383,7 @@ SimpleInfo* IONotifyController::getInfo( const char* userparam )
showStatisticsForConsusmers(inf); showStatisticsForConsusmers(inf);
inf << "-----------------------------------------------------------------------------" << endl << endl; inf << "-----------------------------------------------------------------------------" << endl << endl;
} }
else if( param == "lost" ) else if( param == "lost" )
{ {
inf << "------------------------------- consumers list (lost event)------------------" << endl; inf << "------------------------------- consumers list (lost event)------------------" << endl;
showStatisticsForConsumersWithLostEvent(inf); showStatisticsForConsumersWithLostEvent(inf);
...@@ -331,15 +391,27 @@ SimpleInfo* IONotifyController::getInfo( const char* userparam ) ...@@ -331,15 +391,27 @@ SimpleInfo* IONotifyController::getInfo( const char* userparam )
} }
else if( !param.empty() ) else if( !param.empty() )
{ {
showStatisticsForConsumer(inf, param); auto query = uniset::explode_str(param,':');
if( query.empty() || query.size() == 1 )
showStatisticsForConsumer(inf, param);
else if( query.size() > 1 )
{
if( query[0] == "consumer" )
showStatisticsForConsumer(inf, query[1]);
else if( query[0] == "sensor" )
showStatisticsForSensor(inf, query[1]);
else
inf << "Unknown command: " << param << endl;
}
} }
else else
{ {
inf << "IONotifyController::UserParam help: " << endl inf << "IONotifyController::UserParam help: " << endl
<< " Default - Common info" << endl << " Default - Common info" << endl
<< " consumers - Consumers list " << endl << " consumers - Consumers list " << endl
<< " lost - Consumers list with lostEvent > 0" << endl << " lost - Consumers list with lostEvent > 0" << endl
<< " name - Statistic for consumer 'name'" << " consumer:name - Statistic for consumer 'name'" << endl
<< " sensor:name - Statistic for sensor 'name'"
<< endl; << endl;
} }
...@@ -1403,14 +1475,14 @@ Poco::JSON::Object::Ptr IONotifyController::httpHelp(const Poco::URI::QueryParam ...@@ -1403,14 +1475,14 @@ Poco::JSON::Object::Ptr IONotifyController::httpHelp(const Poco::URI::QueryParam
{ {
// 'consumers' // 'consumers'
uniset::json::help::item cmd("get consumers list"); uniset::json::help::item cmd("consumers", "get consumers list");
cmd.param("sensor1,sensor2,sensor3", "get consumers for sensors"); cmd.param("sensor1,sensor2,sensor3", "get consumers for sensors");
myhelp.add(cmd); myhelp.add(cmd);
} }
{ {
// 'lost' // 'lost'
uniset::json::help::item cmd("get lost consumers list"); uniset::json::help::item cmd("lost", "get lost consumers list");
myhelp.add(cmd); myhelp.add(cmd);
} }
......
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