test
[anna.git] / source / diameter.comm / MessageStatistics.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8 // Standard
9 #include <string>
10
11 // Project
12 #include <anna/diameter.comm/MessageStatistics.hpp>
13 #include <anna/statistics/Engine.hpp>
14 #include <anna/diameter/functions.hpp>
15 #include <anna/diameter/helpers/defines.hpp>
16 #include <anna/diameter/codec/Message.hpp>
17 #include <anna/diameter/codec/Engine.hpp>
18 #include <anna/diameter/codec/EngineManager.hpp>
19
20
21 void anna::diameter::comm::MessageStatistics::initialize(const std::string &name) throw(anna::RuntimeException) {
22   a_accumulator = anna::statistics::Engine::instantiate().createAccumulator(name);
23 }
24
25
26 void anna::diameter::comm::MessageStatistics::process(const ConceptType::_v &conceptType, const anna::diameter::CommandId &cid, const double & value) throw(anna::RuntimeException) {
27
28   // Development issue:
29 //  if (!a_accumulator) {
30 //    LOGWARNING(anna::Logger::warning("Cannot process uninitialized 'MessageStatistics' instance", ANNA_FILE_LOCATION));
31 //    return;
32 //  }
33
34   // retrieve the concept id for the pair:
35   ConceptId conceptId(cid, conceptType);
36   int engine_concept_id = 0;
37   concepts_map_it it = a_concepts.find(conceptId);
38   if (it != a_concepts.end()) { // found
39     engine_concept_id = it->second;
40   }
41   else { // register a new concept id
42     std::string description;
43     if(conceptType == ConceptType::SentRequestProcessingTime) {
44       description = anna::functions::asString("Processing time for outgoing requests (code = %d)", cid.first);
45     }
46     else if (conceptType == ConceptType::ReceivedMessageSize) {
47       description = "Message size for received messages ";
48       description += anna::diameter::functions::commandIdAsPairString(cid);
49     }
50
51     engine_concept_id = a_accumulator->addConcept(description, "ms", true/* integer values */);
52     a_concepts[conceptId] = engine_concept_id;
53   }
54
55   a_accumulator->process(engine_concept_id, value);
56 }
57