bool result = true;
try {
- messageCodec.setEngine(NULL); // perhaps we will need another codec engine ...
+ messageCodec.clear();
messageCodec.decode(message);
}
catch (anna::RuntimeException &ex) {
int a_processing_time__StatisticConceptId; // request from local server (dpr's, etc.)
int a_received_message_size__StatisticConceptId;
anna::statistics::Accumulator *a_statisticsAccumulator;
- void initializeStatisticConcepts() throw();
+ void initializeStatisticResources() throw();
void resetStatistics() throw();
// void eraseServerSession(const anna::comm::ClientSocket& clientSocket) throw();
int a_processing_time__StatisticConceptId;
int a_received_message_size__StatisticConceptId;
anna::statistics::Accumulator *a_statisticsAccumulator;
- void initializeStatisticConcepts() throw();
+ void initializeStatisticResources() throw();
void resetStatistics() throw();
// Availability
/**
* Constructor.
+ *
+ * @param name Accumulator name
*/
- Accumulator();
+ Accumulator(const std::string &name) : a_name(name) {};
/**
* Destructor.
*/
~Accumulator();
+ /**
+ * Adds a new statistic concept through the accumulator, to ease the concept name creation,
+ * which will be a string defined by: concept name + ': ' + accumulator name.
+ *
+ * @param description Concept description; e.g.: processing time, messages size, etc.
+ * @param unit Concept unit description
+ * @param integerNatureSample Most of cases we will measure 'time' with the unit which force integer values
+ * (is more intuitive 850 msecs than 0,850 secs). Then, it is @em true by default.
+ * This is useful to advice better representation for some indicators like minimum/maximum
+ * within integer samples.
+ *
+ * @return Assigned concept identification number (sequence)
+ */
+ int addConcept(const std::string & description, const std::string & unit, const bool & integerNatureSample = true) throw();
+
/**
* Process new value for the sample.
private:
+ std::string a_name;
+
void initialize(const int & conceptId) throw();
_concept_data_t * getConcept(const int & conceptId) const throw(anna::RuntimeException);
// Return NULL if no data is found for the concept Id
* easily. Anyway, you could allocate this class objects without using this. Then, this is a helper to create accumulators
* and centralize their reports.
*
+ * @param name Accumulator name
+ *
* @return New allocated accumulator, to be used by the client
*/
- Accumulator *createAccumulator() throw();
+ Accumulator *createAccumulator(const std::string &name) throw();
/**
* Class string representation
result->setCategory(category);
result->setDescription(description);
result->setAllowedInactivityTime(allowedInactivityTime);
- result->initializeStatisticConcepts();
+ result->initializeStatisticResources();
// Los saco con metodos virtuales readXXX del motor:
// if ((a_cea.isEmpty()) || (a_dwa.isEmpty()))
// throw anna::RuntimeException("Must define valid CEA and DWA messages by mean setCEAandDWA()", ANNA_FILE_LOCATION);
result->a_socket = socket;
result->setMaxClientSessions(a_numberOfClientSessionsPerServer /* engine */);
result->a_engine = this;
- result->initializeStatisticConcepts();
+ result->initializeStatisticResources();
for(int k = 0; k < a_numberOfClientSessionsPerServer; k++)
result->addClientSession(k);
a_category(0),
a_lock(false),
a_available(false),
- a_lastUsedResource(NULL) {
- 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; 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 */);
+ a_lastUsedResource(NULL),
+ a_statisticsAccumulator(NULL) {}
+
+
+void LocalServer::initializeStatisticResources() throw() {
+ std::string accName = "local server '";
+ accName += anna::functions::socketLiteralAsString(a_key.first, a_key.second);
+ accName += "' on realm '";
+ accName += a_engine ? a_engine->getRealm() : "unknown"; // it should be known (createServer)
+ accName += "'";
+ a_statisticsAccumulator = anna::statistics::Engine::instantiate().createAccumulator(accName);
+ a_processing_time__StatisticConceptId = a_statisticsAccumulator->addConcept("Diameter requests processing time at clients connected to", "ms", true/* integer values */);
+ a_received_message_size__StatisticConceptId = a_statisticsAccumulator->addConcept("Diameter message sizes received from clients connected to", "bytes", true/* integer values */);
}
void LocalServer::resetStatistics() throw() {
a_maxClientSessions = 1; // mono client connection
a_lastIncomingActivityTime = (anna::Millisecond)0;
a_lastOutgoingActivityTime = (anna::Millisecond)0;
- a_statisticsAccumulator = anna::statistics::Engine::instantiate().createAccumulator();
+ a_statisticsAccumulator = NULL;
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; 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::initializeStatisticResources() throw() {
+ std::string accName = "remote server '";
+ accName += anna::functions::socketLiteralAsString(a_socket.first, a_socket.second);
+ accName += "' from realm '";
+ accName += a_engine ? a_engine->getRealm() : "unknown"; // it should be known (createServer)
+ accName += "'";
+ a_statisticsAccumulator = anna::statistics::Engine::instantiate().createAccumulator(accName);
+ a_processing_time__StatisticConceptId = a_statisticsAccumulator->addConcept("Diameter requests processing time at", "ms", true/* integer values */);
+ a_received_message_size__StatisticConceptId = a_statisticsAccumulator->addConcept("Diameter message sizes received from", "bytes", true/* integer values */);
}
void Server::resetStatistics() throw() {
//******************************************************************************
//------------------------------------------------------------------------------
-//--------------------------------------------------- Accumulator::Accumulator()
+//-------------------------------------------------- Accumulator::~Accumulator()
//------------------------------------------------------------------------------
-
-// Default Constructor
-Accumulator::Accumulator() {
- //reset (); no sense
-}
-
-
Accumulator::~Accumulator() {
// LOGMETHOD (TraceMethod tttm ("anna::statistics::Accumulator", "Destructor", ANNA_FILE_LOCATION));
+ // TODO: anna::statistics::Engine::instantiate().releaseAccumulator(a_name);
}
-
-
// Private functions:
}
+//------------------------------------------------------------------------------
+//---------------------------------------------------- Accumulator::addConcept()
+//------------------------------------------------------------------------------
+int Accumulator::addConcept(const std::string & description, const std::string & unit, const bool & integerNatureSample) throw() {
+ std::string conceptName = description;
+ conceptName += ": ";
+ conceptName += a_name;
+ return anna::statistics::Engine::instantiate().addConcept(conceptName, unit, integerNatureSample);
+}
+
+
//------------------------------------------------------------------------------
//---------------------------------------------------- Accumulator::getConcept()
//------------------------------------------------------------------------------
trace = "\n=====================";
trace += "\nStatistic Information";
trace += "\n=====================";
+ trace += "\nAccumulator name: ";
+ trace += a_name;
trace += "\nCurrent Time: ";
trace += time_now.asString();
//------------------------------------------------------------------------------
anna::xml::Node* Accumulator::asXML(anna::xml::Node* parent, const int & numberOfDecimals) const throw() {
anna::xml::Node* result = parent->createChild("anna.statistics.Accumulator");
+ result->createAttribute("Name", a_name);
_concept_data_map_iter iter;
_concept_data_map_iter iter_min(a_concept_data_map.begin());
_concept_data_map_iter iter_max(a_concept_data_map.end());
//------------------------------------------------------------------------------
//----------------------------------------------------------- Engine::asString()
//------------------------------------------------------------------------------
-Accumulator *Engine::createAccumulator() throw() {
+Accumulator *Engine::createAccumulator(const std::string &name) throw() {
Accumulator *result;
- result = new Accumulator();
+ result = new Accumulator(name);
a_accumulators.push_back(result);
return result;
}
}
trace += "\n";
+
+ // Accumulators:
+ trace += "\nNumber of accumulators= "; trace += anna::functions::asString(a_accumulators.size());
+ for (_accumulator_vector_it it = a_accumulators.begin(); it != a_accumulators.end(); it++) {
+ trace += "\n";
+ trace += (*it)->asString();
+ }
+
return (trace);
}
}
// Accumulators:
- for (_accumulator_vector_it it = a_accumulators.begin(); it != a_accumulators.end(); it++) {
- anna::xml::Node* accumulators = result->createChild("anna.statistics.Accumulators");
+ anna::xml::Node* accumulators = result->createChild("anna.statistics.Accumulators");
+ accumulators->createAttribute("RegisteredAccumulators", a_accumulators.size());
+ for (_accumulator_vector_it it = a_accumulators.begin(); it != a_accumulators.end(); it++)
(*it)->asXML(accumulators);
- }
return result;
}
//------------------------------------------------------------------------------
// Default Constructor
-Meter::Meter(const std::string & description) {
+Meter::Meter(const std::string & description) : a_accumulator(description) {
Engine& statsEngine = Engine::instantiate();
a_single_accumulator_concept_id = statsEngine.addConcept(description, "ms", true);
}