// Statistics
int a_processing_time__StatisticConceptId; // request from local server (dpr's, etc.)
int a_received_message_size__StatisticConceptId;
- anna::statistics::Accumulator a_statisticsAccumulator;
+ anna::statistics::Accumulator *a_statisticsAccumulator;
void initializeStatisticConcepts() throw();
void resetStatistics() throw();
}
#endif
-
// Statistics
int a_processing_time__StatisticConceptId;
int a_received_message_size__StatisticConceptId;
- anna::statistics::Accumulator a_statisticsAccumulator;
+ anna::statistics::Accumulator *a_statisticsAccumulator;
void initializeStatisticConcepts() throw();
void resetStatistics() throw();
}
#endif
-
#include <anna/core/Singleton.hpp>
#include <anna/core/util/Millisecond.hpp>
+#include <anna/core/mt/Mutex.hpp>
// Standard
#include <string>
+#include <vector>
#include <map>
// Local
typedef std::map <int, _concept_identification_t>::const_iterator _concept_identification_map_iter;
typedef std::map <int, _concept_identification_t>::iterator _concept_identification_map_nc_iter;
+typedef std::vector <Accumulator*> _accumulator_vector_t;
+typedef std::vector <Accumulator*>::const_iterator _accumulator_vector_it;
/**
public:
+ /** Destructor */
+ ~Engine();
+
// Sets
/**
*/
bool enabled(void) const throw() { return (a_enabled); }
+ /**
+ * There is an advantage creating Accumulators over the engine: the #asXML method will show all the controlled information
+ * easily. Anyway, you could allocate this class objects without using this. Then, this is a helper to create accumulators
+ * and centralize their reports.
+ *
+ * @return New allocated accumulator, to be used by the client
+ */
+ Accumulator *createAccumulator() throw();
/**
* Class string representation
Engine(); // private constructor
_concept_identification_map_t a_concept_identification_map;
+ _accumulator_vector_t a_accumulators; // you could create accumulators regardless the engine, but this is easier and asXML will show all the information easily
bool a_enabled;
int a_sequence_concept_id;
+ anna::Mutex a_mutex; // for logSample
bool logSample(const int & conceptId, const anna::Millisecond & unixTimestamp, const double & value) const throw();
a_lock(false),
a_available(false),
a_lastUsedResource(NULL) {
- a_statisticsAccumulator.reset();
+ a_statisticsAccumulator = anna::statistics::Engine::instantiate().createAccumulator();
}
void LocalServer::initializeStatisticConcepts() throw() {
+ // Realm name
+ std::string realmName = a_engine ? a_engine->getRealm() : "unknown"; // it should be known (createServer)
+
// Statistics:
anna::statistics::Engine& statsEngine = anna::statistics::Engine::instantiate();
// Concepts descriptions:
std::string serverAsString = anna::functions::socketLiteralAsString(a_key.first, a_key.second);
- std::string c1desc = "Diameter processing time (for requests) at clients connected to "; c1desc += serverAsString;
- std::string c2desc = "Diameter message sizes received from clients connected to "; c2desc += serverAsString;
+ std::string c1desc = "Diameter processing time (for requests) at clients connected to "; c1desc += serverAsString; c1desc += " for realm '"; c1desc += realmName; c1desc += "'";
+ std::string c2desc = "Diameter message sizes received from clients connected to "; c2desc += serverAsString; c2desc += " for realm '"; c2desc += realmName; c2desc += "'";
// Registering
a_processing_time__StatisticConceptId = statsEngine.addConcept(c1desc.c_str(), "ms", true/* integer values */);
a_received_message_size__StatisticConceptId = statsEngine.addConcept(c2desc.c_str(), "bytes", true/* integer values */);
}
void LocalServer::resetStatistics() throw() {
- a_statisticsAccumulator.reset();
+ a_statisticsAccumulator->reset();
}
void LocalServer::updateProcessingTimeStatisticConcept(const double &value) throw() {
- a_statisticsAccumulator.process(a_processing_time__StatisticConceptId, value);
- LOGDEBUG(anna::Logger::debug(a_statisticsAccumulator.asString(), ANNA_FILE_LOCATION));
+ a_statisticsAccumulator->process(a_processing_time__StatisticConceptId, value);
+ LOGDEBUG(anna::Logger::debug(a_statisticsAccumulator->asString(), ANNA_FILE_LOCATION));
}
void LocalServer::updateReceivedMessageSizeStatisticConcept(const double &value) throw() {
- a_statisticsAccumulator.process(a_received_message_size__StatisticConceptId, value);
- //LOGDEBUG(anna::Logger::debug(a_statisticsAccumulator.asString(), ANNA_FILE_LOCATION));
+ a_statisticsAccumulator->process(a_received_message_size__StatisticConceptId, value);
+ //LOGDEBUG(anna::Logger::debug(a_statisticsAccumulator->asString(), ANNA_FILE_LOCATION));
}
result += " | Last Outgoing Activity Time: ";
result += a_lastOutgoingActivityTime.asString();
// result += "\n";
-// result += a_statisticsAccumulator.asString();
+// result += a_statisticsAccumulator->asString();
// ServerSessions only in xml
return result += " }";
}
result->createAttribute("LastOutgoingActivityTime", a_lastOutgoingActivityTime.asString());
// Statistics
anna::xml::Node* stats = result->createChild("Statistics");
- a_statisticsAccumulator.asXML(stats);
+ a_statisticsAccumulator->asXML(stats);
anna::xml::Node* serverSessions = result->createChild("ServerSessions"); // LocalServer.ServerSessions
for(const_serverSession_iterator it = serverSession_begin(); it != serverSession_end(); it++)
anna::Logger::debug(msg, ANNA_FILE_LOCATION);
);
}
-
a_maxClientSessions = 1; // mono client connection
a_lastIncomingActivityTime = (anna::Millisecond)0;
a_lastOutgoingActivityTime = (anna::Millisecond)0;
- a_statisticsAccumulator.reset();
+ a_statisticsAccumulator = anna::statistics::Engine::instantiate().createAccumulator();
a_lastUsedResource = NULL;
}
void Server::initializeStatisticConcepts() throw() {
+ // Realm name
+ std::string realmName = a_engine ? a_engine->getRealm() : "unknown"; // it should be known (createServer)
+
// Statistics:
anna::statistics::Engine& statsEngine = anna::statistics::Engine::instantiate();
// Concepts descriptions:
std::string serverAsString = anna::functions::socketLiteralAsString(a_socket.first, a_socket.second);
- std::string c1desc = "Diameter processing time (for requests) at servers on "; c1desc += serverAsString;
- std::string c2desc = "Diameter message sizes received from servers on "; c2desc += serverAsString;
+ std::string c1desc = "Diameter processing time (for requests) at servers on "; c1desc += serverAsString; c1desc += " for realm '"; c1desc += realmName; c1desc += "'";
+ std::string c2desc = "Diameter message sizes received from servers on "; c2desc += serverAsString; c2desc += " for realm '"; c2desc += realmName; c2desc += "'";
// Registering
a_processing_time__StatisticConceptId = statsEngine.addConcept(c1desc.c_str(), "ms", true/* integer values */);
a_received_message_size__StatisticConceptId = statsEngine.addConcept(c2desc.c_str(), "bytes", true/* integer values */);
}
void Server::resetStatistics() throw() {
- a_statisticsAccumulator.reset();
+ a_statisticsAccumulator->reset();
}
void Server::updateProcessingTimeStatisticConcept(const double &value) throw() {
- a_statisticsAccumulator.process(a_processing_time__StatisticConceptId, value);
- LOGDEBUG(anna::Logger::debug(a_statisticsAccumulator.asString(), ANNA_FILE_LOCATION));
+ a_statisticsAccumulator->process(a_processing_time__StatisticConceptId, value);
+ LOGDEBUG(anna::Logger::debug(a_statisticsAccumulator->asString(), ANNA_FILE_LOCATION));
}
void Server::updateReceivedMessageSizeStatisticConcept(const double &value) throw() {
- a_statisticsAccumulator.process(a_received_message_size__StatisticConceptId, value);
- //LOGDEBUG(anna::Logger::debug(a_statisticsAccumulator.asString(), ANNA_FILE_LOCATION));
+ a_statisticsAccumulator->process(a_received_message_size__StatisticConceptId, value);
+ //LOGDEBUG(anna::Logger::debug(a_statisticsAccumulator->asString(), ANNA_FILE_LOCATION));
}
result += " | Hidden: ";
result += (hidden() ? "yes" : "no");
result += "\n";
- result += a_statisticsAccumulator.asString();
+ result += a_statisticsAccumulator->asString();
for(std::vector<ClientSession*>::const_iterator it = begin(); it != end(); it++) {
result += "\n";
result->createAttribute("Hidden", hidden() ? "yes" : "no");
// Statistics
anna::xml::Node* stats = result->createChild("Statistics");
- a_statisticsAccumulator.asXML(stats);
+ a_statisticsAccumulator->asXML(stats);
anna::xml::Node* clientSessions = result->createChild("Server.ClientSessions");
for(std::vector<ClientSession*>::const_iterator it = begin(); it != end(); it++)
);
a_parent->updateOutgoingActivityTime();
}
-
anna::Logger::debug(msg, ANNA_FILE_LOCATION);
);
}
-
_concept_data_t *ptr_auxConceptData = getConcept(conceptId);
anna::Millisecond current = anna::Millisecond::getTime();
// Optional sample file dump:
- Engine::instantiate().logSample(conceptId, current, value);
+ Engine::instantiate().logSample(conceptId, current, value); // Accumulator is friend of Engine
// Statistics calculations
if(ptr_auxConceptData->Size == ULLONG_MAX) // Statistics is better during processing until reset
// Local
#include <anna/statistics/Engine.hpp>
#include <anna/statistics/internal/sccs.hpp>
-
+#include <anna/core/mt/Guard.hpp>
#include <anna/core/functions.hpp>
#include <anna/xml/xml.hpp>
//******************************************************************************
//----------------------------------------------------------------------- Engine
//******************************************************************************
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------- Engine::Engine()
+//------------------------------------------------------------------------------
Engine::Engine() {
statistics::sccs::activate();
a_enabled = false;
}
+//------------------------------------------------------------------------------
+//------------------------------------------------------------ Engine::~Engine()
+//------------------------------------------------------------------------------
+Engine::~Engine() {
+ for (_accumulator_vector_it it = a_accumulators.begin(); it != a_accumulators.end(); it++)
+ delete (*it);
+}
+
+
//------------------------------------------------------------------------------
//--------------------------------------------------------- Engine::addConcept()
//------------------------------------------------------------------------------
//--------------------------------------------------- Engine::disableSampleLog()
//------------------------------------------------------------------------------
bool Engine::logSample(const int & conceptId, const anna::Millisecond & unixTimestamp, const double & value) const throw() {
+ anna::Guard guard(a_mutex);
+
_concept_identification_map_iter it = a_concept_identification_map.find(conceptId);
if(it == a_concept_identification_map.end()) return false;
return true;
}
+
+//------------------------------------------------------------------------------
+//----------------------------------------------------------- Engine::asString()
+//------------------------------------------------------------------------------
+Accumulator *Engine::createAccumulator() throw() {
+ Accumulator *result;
+
+ result = new Accumulator();
+ a_accumulators.push_back(result);
+ return result;
+}
+
+
//------------------------------------------------------------------------------
//----------------------------------------------------------- Engine::asString()
//------------------------------------------------------------------------------
concept->createAttribute("IntegerNatureSample", (*iter).second.IntegerNatureSample ? "yes" : "no");
}
+ // Accumulators:
+ for (_accumulator_vector_it it = a_accumulators.begin(); it != a_accumulators.end(); it++) {
+ anna::xml::Node* accumulators = result->createChild("anna.statistics.Accumulators");
+ (*it)->asXML(accumulators);
+ }
+
return result;
}
-