7 map<string, map<string, double> > map_journal;
8 time_calculate = 30000;
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;
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;
81 if ((zclock_time() - time) >= time_calculate) {
92 time_calculate = time;
void Set_Time_Calc(int time)
void Insert_Message(pair< string, string > message)
map< pair< string, string >, map< string, double > > Get_Map()