diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-04-26 13:01:19 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-04-26 13:01:19 +0200 |
commit | aebe139d00b44684158edb3616da5c37b12db6d1 (patch) | |
tree | f37eaa7a59523f2e7db42875e65f2ca2714c0e9d /server.cpp | |
parent | 91073ca08f5f9582196712ae6753714f3333979f (diff) |
Added stats output
Diffstat (limited to 'server.cpp')
-rw-r--r-- | server.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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()}; |