This class accumulates data.
More...
#include <Keeper.h>
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.
void Keeper::Clear_Map |
( |
| ) |
|
Clears log with accumulated data.
Definition at line 95 of file Keeper.cpp.
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.
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;
void Keeper::Insert_Message |
( |
pair< string, string > |
message | ) |
|
Receives messages and writes to log.
- Parameters
-
[in] | message | Message from broker. Pair<type of node, JSON> |
Definition at line 16 of file Keeper.cpp.
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();
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();
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();
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));
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;
void Keeper::Set_Time_Calc |
( |
int |
time | ) |
|
Sets length of time over which data should be communicated.
- Parameters
-
[in] | time | Time interval in milliseconds |
Definition at line 90 of file Keeper.cpp.
92 time_calculate = time;
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.
81 if ((zclock_time() - time) >= time_calculate) {
The documentation for this class was generated from the following files: