summaryrefslogtreecommitdiffhomepage
path: root/server.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-04-26 13:01:19 +0200
committerRoland Reichwein <mail@reichwein.it>2020-04-26 13:01:19 +0200
commitaebe139d00b44684158edb3616da5c37b12db6d1 (patch)
treef37eaa7a59523f2e7db42875e65f2ca2714c0e9d /server.cpp
parent91073ca08f5f9582196712ae6753714f3333979f (diff)
Added stats output
Diffstat (limited to 'server.cpp')
-rw-r--r--server.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/server.cpp b/server.cpp
index 71f39ac..5d1609d 100644
--- a/server.cpp
+++ b/server.cpp
@@ -20,6 +20,7 @@
#include <boost/config.hpp>
#include <exception>
+#include <functional>
#include <iostream>
#include <thread>
#include <vector>
@@ -39,6 +40,10 @@ using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
const std::string Server::VersionString{ "Reichwein.IT Webserver "s + std::string{VERSION} };
+namespace {
+ const int32_t stats_timer_seconds { 24 * 60 * 60 }; // save stats once a day
+} // anonymous namespace
+
Server::Server(Config& config, boost::asio::io_context& ioc, const Socket& socket, plugins_container_type& plugins, Statistics& statistics)
: m_config(config)
, m_ioc(ioc)
@@ -66,6 +71,16 @@ int run_server(Config& config, plugins_container_type& plugins)
ioc.stop();
});
+ // Save stats once a day
+ boost::asio::steady_timer stats_save_timer(ioc, boost::asio::chrono::seconds(stats_timer_seconds));
+ std::function<void(const boost::system::error_code&)> stats_callback =
+ [&](const boost::system::error_code& error){
+ stats.save();
+ stats_save_timer.expires_at(stats_save_timer.expires_at() + boost::asio::chrono::seconds(stats_timer_seconds));
+ stats_save_timer.async_wait(stats_callback);
+ };
+ stats_save_timer.async_wait(stats_callback);
+
std::vector<std::shared_ptr<Server>> servers;
const auto& sockets {config.Sockets()};