summaryrefslogtreecommitdiffhomepage
path: root/plugins
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-05-02 18:12:46 +0200
committerRoland Reichwein <mail@reichwein.it>2020-05-02 18:12:46 +0200
commit17433b0cbcacc3f41fd500551baf4d52d291e0c9 (patch)
tree16840da482129f93c1393c999e08209dd9b5a945 /plugins
parent6ab2d11a72041e22eee42b0f582377b148e4c348 (diff)
Statistics: IPv6 and HTTP fractions
Diffstat (limited to 'plugins')
-rw-r--r--plugins/statistics/statistics.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/plugins/statistics/statistics.cpp b/plugins/statistics/statistics.cpp
index 543cc4e..5eef858 100644
--- a/plugins/statistics/statistics.cpp
+++ b/plugins/statistics/statistics.cpp
@@ -1,6 +1,7 @@
#include "statistics.h"
#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/split.hpp>
#include <boost/coroutine2/coroutine.hpp>
#include <boost/process.hpp>
@@ -25,6 +26,30 @@ namespace {
return status + " " + message;
}
+ // returns sum over specified column
+ uint64_t getSum(const std::string& stats, size_t column)
+ {
+ uint64_t result{0};
+
+ std::istringstream is{stats};
+ std::string line;
+
+ while (std::getline(is, line) && !is.eof()) {
+
+ std::vector<std::string> elements;
+ boost::algorithm::split(elements, line, [](char c){ return c == ','; });
+
+ if (column >= elements.size()) {
+ std::cerr << "Error: No column " << column << " found." << std::endl;
+ return 0;
+ }
+
+ result += stoull(elements[column]);
+ }
+
+ return result;
+ }
+
} // anonymous namespace
std::string statistics_plugin::name()
@@ -80,10 +105,20 @@ std::string statistics_plugin::generate_page(
std::string result{header};
+ std::string statistics{GetServerParam("statistics")};
+ double ipv6_fraction_by_requests {double(getSum(statistics, 5)) / getSum(statistics, 1)};
+ double ipv6_fraction_by_bytes {double(getSum(statistics, 7) + getSum(statistics, 8)) / (getSum(statistics, 3) + getSum(statistics, 4))};
+ double https_fraction_by_requests {double(getSum(statistics, 9)) / getSum(statistics, 1)};
+ double https_fraction_by_bytes {double(getSum(statistics, 11) + getSum(statistics, 12)) / (getSum(statistics, 3) + getSum(statistics, 4))};
+
result += "<h1>Webserver Statistics</h1>";
result += "<p>Host uptime: "s + GetServerParam("uptime_host") + "</p>";
result += "<p>Host webserver: "s + GetServerParam("uptime_webserver") + "</p>";
- result += "<pre>"s + GetServerParam("statistics") + "</pre>"s;
+ result += "<p>IPv6 fraction by requests: "s + std::to_string(ipv6_fraction_by_requests * 100) + "</p>";
+ result += "<p>IPv6 fraction by bytes: "s + std::to_string(ipv6_fraction_by_bytes * 100) + "</p>";
+ result += "<p>HTTPS fraction by requests: "s + std::to_string(https_fraction_by_requests * 100) + "</p>";
+ result += "<p>HTTPS fraction by bytes: "s + std::to_string(https_fraction_by_bytes * 100) + "</p>";
+ result += "<pre>"s + statistics + "</pre>"s;
result += footer;