Include accumulators on statistics engine in order to centralize and ease asXML....
authorEduardo Ramos Testillano <eduardo.ramos.testillano@ericsson.com>
Sat, 10 Oct 2015 12:28:45 +0000 (14:28 +0200)
committerEduardo Ramos Testillano <eduardo.ramos.testillano@ericsson.com>
Sat, 10 Oct 2015 12:28:45 +0000 (14:28 +0200)
example/diameter/launcher/testing/TestStep.cpp
include/anna/diameter.comm/LocalServer.hpp
include/anna/diameter.comm/Server.hpp
include/anna/statistics/Accumulator.hpp
include/anna/statistics/Engine.hpp
source/diameter.comm/Engine.cpp
source/diameter.comm/LocalServer.cpp
source/diameter.comm/Server.cpp
source/statistics/Accumulator.cpp
source/statistics/Engine.cpp
source/statistics/Meter.cpp

index 018dfcd..cb1b0f9 100644 (file)
@@ -152,7 +152,7 @@ namespace {
 
     bool result = true;
     try {
-      messageCodec.setEngine(NULL); // perhaps we will need another codec engine ...
+      messageCodec.clear();
       messageCodec.decode(message);
     }
     catch (anna::RuntimeException &ex) {
index e97fb20..d83dd31 100644 (file)
@@ -68,7 +68,7 @@ class LocalServer {
   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();
index 0484484..69f5e80 100644 (file)
@@ -74,7 +74,7 @@ class Server {
   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
index 98d4624..c13bbf1 100644 (file)
@@ -89,14 +89,31 @@ public:
 
   /**
   * 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.
@@ -189,6 +206,8 @@ public:
 
 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
index 8f59a2e..61a9fe6 100644 (file)
@@ -142,9 +142,11 @@ public:
   * 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
index 489a093..88f78e2 100644 (file)
@@ -274,7 +274,7 @@ throw(anna::RuntimeException) {
   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);
@@ -315,7 +315,7 @@ throw(anna::RuntimeException) {
   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);
index 67c35fc..b43a754 100644 (file)
@@ -43,24 +43,19 @@ LocalServer::LocalServer() :
   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() {
index 758ac2d..0b9bcd7 100644 (file)
@@ -36,23 +36,19 @@ void Server::initialize() 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() {
index 1644700..358c87c 100644 (file)
@@ -34,21 +34,13 @@ using namespace anna::time;
 
 //******************************************************************************
 //------------------------------------------------------------------------------
-//--------------------------------------------------- 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:
 
 
@@ -62,6 +54,17 @@ void Accumulator::initialize(const int & conceptId) throw() {
 }
 
 
+//------------------------------------------------------------------------------
+//---------------------------------------------------- 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()
 //------------------------------------------------------------------------------
@@ -289,6 +292,8 @@ std::string Accumulator::asString(const int & numberOfDecimals) const throw() {
   trace =  "\n=====================";
   trace +=  "\nStatistic Information";
   trace +=  "\n=====================";
+  trace += "\nAccumulator name: ";
+  trace += a_name;
   trace += "\nCurrent Time: ";
   trace += time_now.asString();
 
@@ -370,6 +375,7 @@ std::string Accumulator::asString(const int & numberOfDecimals) const throw() {
 //------------------------------------------------------------------------------
 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());
index b90b609..ebde06c 100644 (file)
@@ -158,10 +158,10 @@ bool Engine::logSample(const int & conceptId, const anna::Millisecond & unixTime
 //------------------------------------------------------------------------------
 //----------------------------------------------------------- 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;
 }
@@ -201,6 +201,14 @@ std::string Engine::asString(void) const throw() {
   }
 
   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);
 }
 
@@ -230,10 +238,10 @@ anna::xml::Node* Engine::asXML(anna::xml::Node* parent, const int & numberOfDeci
   }
 
   // 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;
 }
index feda763..9c9de5f 100644 (file)
@@ -26,7 +26,7 @@ using namespace anna::statistics;
 //------------------------------------------------------------------------------
 
 // 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);
 }