Skip to content
Snippets Groups Projects
Commit 71c9fe77 authored by ale's avatar ale
Browse files

add a tiny historical graph of qps

parent 89fe6829
No related branches found
No related tags found
No related merge requests found
// $Id$ // $Id$
#include <numeric>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include "status_httpd.h" #include "status_httpd.h"
using namespace std;
namespace dos { namespace dos {
static void normalize(vector<double>& values)
{
ostringstream ds;
double min = min_element(values.begin(), values.end());
double max = max_element(values.begin(), values.end());
vector<double>::iterator i;
for (i = values.begin(); i != values.end(); ++i)
*i = (*i - min) / (max - min);
}
static string to_dataset(vector<double>& values)
{
static const char vchar[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
normalize(values);
ostringstream ds;
vector<double>::const_iterator i;
for (i = values.begin(); i != values.end(); ++i)
ds << vchar[static_cast<int>(100 * (*i))];
return ds.str();
}
static string qps_graph(const vector<QpsTuple>& qps_values,
int width=500, int height=200)
{
ostringstream url;
url << "http://chart.apis.google.com/chart"
<< "?chs=" << width << "x" << height
<< "&cht=lc";
vector<double> stdup, avg, stddown;
vector<QpsTuple>::const_iterator i;
for (i = qps_values.begin(); i != qps_values.end(); ++i) {
stdup.push_back((*i).value + (*i).std_dev);
avg.push_back((*i).value);
stddown.push_back((*i).value - (*i).std_dev);
}
url << "&chd=s:"
<< to_dataset(stdup) << ","
<< to_dataset(avg) << ","
<< to_dataset(stddown);
}
void StatusHttpd::handle_status(evhttp_request *req) void StatusHttpd::handle_status(evhttp_request *req)
{ {
std::ostringstream resp; ostringstream resp;
resp << "<?xml version=\"1.0\"?>\n" resp << "<?xml version=\"1.0\"?>\n"
<< "<html lang=\"en\">\n" << "<html lang=\"en\">\n"
...@@ -19,13 +66,20 @@ void StatusHttpd::handle_status(evhttp_request *req) ...@@ -19,13 +66,20 @@ void StatusHttpd::handle_status(evhttp_request *req)
resp << "<h1>NoDDoS Master</h1>"; resp << "<h1>NoDDoS Master</h1>";
resp << "<p>Global QPS: <b>" << logic->get_qps() << "</b></p>" vector<QpsTuple> qps_values;
logic->get_store()->read_stats(qps_values, 24);
string graph_url = qps_graph(qps_values);
resp << "<table><tr><td valign=\"top\">"
<< "<p>Global QPS: <b>" << logic->get_qps() << "</b></p>"
<< "<p>Global status: <b>" << logic->get_status().str() << "<p>Global status: <b>" << logic->get_status().str()
<< "</b></p>\n"; << "</b></p>\n"
<< "</td><td>"
<< "<img src=\"" << graph_url << "\" border=\"0\"/>"
<< "</td></tr></table>\n";
resp << "<h3>Nodes</h3><ul>"; resp << "<h3>Nodes</h3><ul>";
std::vector<std::string> nodes = logic->nodes(); vector<string> nodes = logic->nodes();
std::vector<std::string>::const_iterator i; vector<string>::const_iterator i;
for (i = nodes.begin(); i != nodes.end(); i++) for (i = nodes.begin(); i != nodes.end(); i++)
resp << "<li><a href=\"http://" << (*i) resp << "<li><a href=\"http://" << (*i)
<< "/\">" << (*i) << "</a></li>"; << "/\">" << (*i) << "</a></li>";
...@@ -33,7 +87,7 @@ void StatusHttpd::handle_status(evhttp_request *req) ...@@ -33,7 +87,7 @@ void StatusHttpd::handle_status(evhttp_request *req)
resp << "<h3>Blacklisted hosts</h3><table class=\"d\">" resp << "<h3>Blacklisted hosts</h3><table class=\"d\">"
<< "<thead><tr><th>IP</th></tr></thead><tbody>"; << "<thead><tr><th>IP</th></tr></thead><tbody>";
std::vector<std::string> blacklist = logic->get_blacklist(); vector<string> blacklist = logic->get_blacklist();
for (i = blacklist.begin(); i != blacklist.end(); i++) for (i = blacklist.begin(); i != blacklist.end(); i++)
resp << "<tr><td>" << (*i) << "</td></tr>"; resp << "<tr><td>" << (*i) << "</td></tr>";
resp << "</tbody></table>\n"; resp << "</tbody></table>\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment