9 #include "flowpusher.h"
14 void from_string<long long>(const char *from, long long &to)
21 int main(int argc, char **argv)
23 int width = 1000, height = 500;
24 pqxx::connection conn05("dbname=nms05 host=localhost user=nms password=seesahS4");
25 pqxx::connection conn("dbname=nms host=localhost user=nms password=seesahS4");
27 std::vector<flow_element> flow, total_flow, total_flow05;
31 mallopt(M_TRIM_THRESHOLD, -1);
34 pqxx::work t(conn, "fetch_all");
35 pqxx::icursorstream::icursorstream cstream(t, "select port,extract(epoch from time) as time,bytes_in,bytes_out from polls natural join switches where ((switchtype='es3024' and port < 25) or (switchtype='summit400' and port > 1)) order by switch,port,time", "fetch_all", 500);
44 for (unsigned i = 0; i < res.size(); ++i) {
45 int port = res[i][0].as<int>();
46 double x = res[i][1].as<double>();
47 unsigned long long y1 = res[i][2].as<long long>(), y2 = res[i][3].as<long long>();
49 if (port != last_port) {
50 if (last_port != -1) {
51 total_flow = sum_flows(total_flow, flow);
52 fprintf(stderr, "%u (%u)\n", last_port, ++num_total);
64 total_flow = sum_flows(total_flow, flow);
66 unsigned long long min_y = 0;
67 unsigned long long max_y = 10000000;
69 for (unsigned i = 0; i < total_flow.size(); ++i) {
70 flow_element fe = total_flow[i];
72 min_y = std::min(min_y, fe.y1);
73 max_y = std::max(max_y, fe.y1);
75 min_y = std::min(min_y, fe.y2);
76 max_y = std::max(max_y, fe.y2);
82 pqxx::work t05(conn05, "fetch_all");
83 pqxx::icursorstream::icursorstream cstream05(t05, "select port,extract(epoch from (time + interval '1 year 20 days')) as time,bytes_in,bytes_out from polls natural join switches where (switchtype='es3024' and port < 25) order by switch,port,time", "fetch_all", 500);
94 for (unsigned i = 0; i < res.size(); ++i) {
95 int port = res[i][0].as<int>();
96 double x = res[i][1].as<double>();
97 unsigned long long y1 = res[i][2].as<long long>(), y2 = res[i][3].as<long long>();
99 if (port != last_port) {
100 if (last_port != -1) {
101 total_flow05 = sum_flows(total_flow05, filter_flow(flow));
102 fprintf(stderr, "TG05: %u (%u)\n", last_port, ++num_total);
114 total_flow05 = sum_flows(total_flow05, filter_flow(flow));
116 for (unsigned i = 0; i < total_flow05.size(); ++i) {
117 flow_element fe = total_flow05[i];
119 min_y = std::min(min_y, fe.y1);
120 max_y = std::max(max_y, fe.y1);
122 min_y = std::min(min_y, fe.y2);
123 max_y = std::max(max_y, fe.y2);
126 double min_x = std::min(total_flow[0].x, total_flow05[0].x);
127 double max_x = std::max(total_flow[total_flow.size() - 1].x, total_flow05[total_flow05.size() - 1].x);
129 graph *g = mygraph_new(width, height);
130 g = mygraph_make_graph(g, min_x, max_x, min_y, max_y, 5);
133 int *x = new int[total_flow.size()];
134 unsigned long long *y1 = new unsigned long long[total_flow.size()];
135 unsigned long long *y2 = new unsigned long long[total_flow.size()];
138 for (unsigned i = 0; i < total_flow.size(); ++i) {
139 x[i] = total_flow[i].x;
140 y1[i] = total_flow[i].y1;
141 y2[i] = total_flow[i].y2;
144 mygraph_plot_series(g, x, y1, total_flow.size(), 1.0f, 0.0f, 0.0f);
145 mygraph_plot_series(g, x, y2, total_flow.size(), 0.0f, 0.0f, 1.0f);
152 x = new int[total_flow05.size()];
153 y1 = new unsigned long long[total_flow05.size()];
154 y2 = new unsigned long long[total_flow05.size()];
157 for (unsigned i = 0; i < total_flow05.size(); ++i) {
158 x[i] = total_flow05[i].x;
159 y1[i] = total_flow05[i].y1;
160 y2[i] = total_flow05[i].y2;
163 mygraph_plot_series(g, x, y1, total_flow05.size(), 0.0f, 1.0f, 0.0f);
164 mygraph_plot_series(g, x, y2, total_flow05.size(), 1.0f, 0.0f, 1.0f);
170 mygraph_to_file(g, "comparative.png");