hlit-mon  0.5.2
 All Classes Functions Groups Pages
Keeper Class Reference

This class accumulates data. More...

#include <Keeper.h>

Public Member Functions

void Insert_Message (pair< string, string > message)
 
void Set_Time_Calc (int time)
 
bool Time_Write ()
 
map< pair< string, string >
, map< string, double > > 
Get_Map ()
 
void Clear_Map ()
 

Detailed Description

This class accumulates data.

Author
Mayorov

Receives data from 'Subscriber' and store. After a specified period of time, obtains an average value of accumulated data and sends it on.

Definition at line 21 of file Keeper.h.

Member Function Documentation

void Keeper::Clear_Map ( )

Clears log with accumulated data.

Definition at line 95 of file Keeper.cpp.

96 {
97  map_journal.clear();
98 }
map< pair< string, string >, map< string, double > > Keeper::Get_Map ( )

Returns map with the average load of the cluster for certain period of time.

Returns
Returns a map with the data. map<pair<[type of node], [hostname]>, map<[name of parameter], [value]>>

Definition at line 63 of file Keeper.cpp.

64 {
65  for (map<pair<string, string>, map<string, double> >::iterator iter = map_journal.begin(); iter != map_journal.end(); iter++) {
66  double count = iter->second.find("iter")->second;
67  iter->second.find("cpu_user")->second /= count;
68  iter->second.find("cpu_sys")->second /= count;
69  iter->second.find("net_in")->second /= count;
70  iter->second.find("net_out")->second /= count;
71  iter->second.find("total")->second /= count;
72  iter->second.find("mem_used")->second /= count;
73  iter->second.find("buffer")->second /= count;
74  iter->second.find("cached")->second /= count;
75  }
76  return map_journal;
77 }
void Keeper::Insert_Message ( pair< string, string >  message)

Receives messages and writes to log.

Parameters
[in]messageMessage from broker. Pair<type of node, JSON>

Definition at line 16 of file Keeper.cpp.

17 {
18  reader.parse(message.second, root, true);
19  for (unsigned int i = 0; i < root.size(); i++) {
20  Json::Value cur = root[i];
21  string hostname = cur["hostname"].asString();
22  double cpu_user = cur["change"]["cpu"]["user"].asDouble();
23  double cpu_sys = cur["change"]["cpu"]["sys"].asDouble();
24  double net_in = 0.0;
25  double net_out = 0.0;
26  for (unsigned int j = 0; j < cur["change"]["net"].size(); j++) {
27  net_in += cur["change"]["net"][j]["bytes_in"].asDouble();
28  net_out += cur["change"]["net"][j]["bytes_out"].asDouble();
29  }
30  double total = cur["static"]["mem"]["total"].asDouble();
31  double mem_used = cur["static"]["mem"]["used"].asDouble();
32  double buffer = cur["static"]["mem"]["buffer"].asDouble();
33  double cached = cur["static"]["mem"]["cached"].asDouble();
34 
35  map<pair<string, string>, map<string, double> >::iterator iter = map_journal.find(pair<string, string>(message.first, hostname));
36  if (iter == map_journal.end()) {
37  map<string, double> map_param;
38  map_param.insert(pair<string, double>("iter", 0.0));
39  map_param.insert(pair<string, double>("cpu_user", cpu_user));
40  map_param.insert(pair<string, double>("cpu_sys", cpu_sys));
41  map_param.insert(pair<string, double>("net_in", net_in));
42  map_param.insert(pair<string, double>("net_out", net_out));
43  map_param.insert(pair<string, double>("total", total));
44  map_param.insert(pair<string, double>("mem_used", mem_used));
45  map_param.insert(pair<string, double>("buffer", buffer));
46  map_param.insert(pair<string, double>("cached", cached));
47  map_journal.insert(pair<pair<string, string>, map<string, double> >(pair<string, string>(message.first, hostname), map_param));
48  }
49  else {
50  iter->second.find("iter")->second += 1;
51  iter->second.find("cpu_user")->second += cpu_user;
52  iter->second.find("cpu_sys")->second += cpu_sys;
53  iter->second.find("net_in")->second += net_in;
54  iter->second.find("net_out")->second += net_out;
55  iter->second.find("total")->second += total;
56  iter->second.find("mem_used")->second += mem_used;
57  iter->second.find("buffer")->second += buffer;
58  iter->second.find("cached")->second += cached;
59  }
60  }
61 }
void Keeper::Set_Time_Calc ( int  time)

Sets length of time over which data should be communicated.

Parameters
[in]timeTime interval in milliseconds

Definition at line 90 of file Keeper.cpp.

91 {
92  time_calculate = time;
93 }
bool Keeper::Time_Write ( )

Informs whether to transmit data. Check for the expiration of the period.

Returns
Returns a Boolean variable. True or false.

Definition at line 79 of file Keeper.cpp.

80 {
81  if ((zclock_time() - time) >= time_calculate) {
82  time = zclock_time();
83  return true;
84  }
85  else {
86  return false;
87  }
88 }

The documentation for this class was generated from the following files: