-
Notifications
You must be signed in to change notification settings - Fork 10
/
http_file_graph_data_logger.cpp
114 lines (97 loc) · 2.88 KB
/
http_file_graph_data_logger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <map>
#include <string>
#include <time.h>
#include <vector>
#include <gd.h>
#include "log.h"
#include "utils.h"
#include "hasher.h"
#include "math.h"
#include "stirrer.h"
#include "random_source.h"
#include "fips140.h"
#include "scc.h"
#include "hasher_type.h"
#include "stirrer_type.h"
#include "pool_crypto.h"
#include "pool.h"
#include "pools.h"
#include "config.h"
#include "encrypt_stream.h"
#include "statistics.h"
#include "statistics_global.h"
#include "statistics_user.h"
#include "users.h"
#include "handle_client.h"
#include "data_store_int.h"
#include "data_logger.h"
#include "graph.h"
#include "http_bundle.h"
#include "http_request_t.h"
#include "http_file.h"
#include "http_file_graph_data_logger.h"
http_file_graph_data_logger::http_file_graph_data_logger(data_logger *dl_in, std::string font) : dl(dl_in)
{
g = new graph(font);
}
http_file_graph_data_logger::~http_file_graph_data_logger()
{
delete g;
}
std::string http_file_graph_data_logger::get_url()
{
return "/graph.png";
}
std::string http_file_graph_data_logger::get_meta_type()
{
return "image/png";
}
http_bundle * http_file_graph_data_logger::do_request(http_request_t request_type, std::string request_url, http_bundle *request_details)
{
std::map<std::string, std::string> request_parameters = split_parameters(request_url);
std::map<std::string, std::string>::iterator it = request_parameters.find("type");
std::string type = "mem_pool_counts";
if (it != request_parameters.end())
type = it -> second.c_str();
int width = 640, height = 240;
it = request_parameters.find("width");
if (it != request_parameters.end())
width = std::max(240, atoi(it -> second.c_str()));
it = request_parameters.find("height");
if (it != request_parameters.end())
height = std::max(200, atoi(it -> second.c_str()));
std::string title = type;
std::vector<std::string> reply_headers;
long int *t = NULL;
double *v = NULL;
int n = 0;
if (type == "mem_pool_counts")
dl -> get_mem_pool_counts(&t, &v, &n);
else if (type == "dsk_pool_counts")
dl -> get_dsk_pool_counts(&t, &v, &n);
else if (type == "connection_counts")
dl -> get_connection_counts(&t, &v, &n);
else if (type == "mem_pools_bitcount")
dl -> get_pools_bitcounts(&t, &v, &n);
else if (type == "dsk_pools_bitcount")
dl -> get_disk_pools_bitcounts(&t, &v, &n);
else if (type == "recv_bit_count")
dl -> get_recv_bit_count(&t, &v, &n);
else if (type == "recv_bit_count_in")
dl -> get_recv_bit_count_in(&t, &v, &n);
else if (type == "sent_bit_count")
dl -> get_sent_bit_count(&t, &v, &n);
else
{
dolog(LOG_INFO, "%s is an unknown graph-type", type.c_str());
return NULL;
}
char *img_data = NULL;
size_t img_data_len = 0;
g -> do_draw(width, height, title, t, v, n, &img_data, &img_data_len);
free(t);
free(v);
http_bundle *result = new http_bundle(reply_headers, (unsigned char *)img_data, (int)img_data_len);
free(img_data);
return result;
}