From 9e8b07cbfc50b6096e7d618cfc494dc8053a72e2 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 27 Apr 2016 12:49:25 +0200 Subject: [PATCH] Added STATS_DELAY compile flag for overriding the statistics delay for better or worse accuracy than the default. --- CMakeLists.txt | 7 +++++++ lib/config.cpp | 8 ++++++++ src/controller/controller_statistics.cpp | 11 ++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f1a5517..478f1bfb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,13 @@ if (DEFINED NOCRASHCHECK ) add_definitions(-DNOCRASHCHECK=1) endif() +######################################## +# Build Variables - Stats delay overrid# +######################################## +if (DEFINED STATS_DELAY ) + add_definitions(-DSTATS_DELAY=${STATS_DELAY}) +endif() + ######################################## # Build Variables - Prepare for Build # ######################################## diff --git a/lib/config.cpp b/lib/config.cpp index d6aae576..eeafd84c 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -264,6 +264,14 @@ bool Util::Config::parseArgs(int & argc, char ** & argv) { #ifdef KILLONEXIT std::cout << "- Flag: Kill on exit. All binaries will forcibly shut down all their children on exit. This disabled rolling restart support." << std::endl; #endif + #ifdef STATS_DELAY + std::cout << "- Setting: Stats delay " << STATS_DELAY << ". Statistics of viewer counts are delayed by " << STATS_DELAY << " seconds as opposed to the default of 15 seconds. "; + if (STATS_DELAY > 15){ + std::cout << "This makes them more accurate." << std::endl; + }else{ + std::cout << "This makes them less accurate." << std::endl; + } + #endif /*LTS-END*/ std::cout << "Built on " __DATE__ ", " __TIME__ << std::endl; exit(1); diff --git a/src/controller/controller_statistics.cpp b/src/controller/controller_statistics.cpp index fbd0c5f0..5523446b 100644 --- a/src/controller/controller_statistics.cpp +++ b/src/controller/controller_statistics.cpp @@ -31,6 +31,11 @@ #define COUNTABLE_BYTES 128*1024 +#ifndef STATS_DELAY +#define STATS_DELAY 15 +#endif + + std::map Controller::sessions; ///< list of sessions that have statistics data available std::map Controller::connToSession; ///< Map of socket IDs to session info. bool Controller::killOnExit = KILL_ON_EXIT; @@ -750,7 +755,7 @@ void Controller::fillActive(JSON::Value & req, JSON::Value & rep, bool onlyNow){ //collect the data first std::set streams; std::map clients; - unsigned int t = Util::epoch() - 15; + unsigned int t = Util::epoch() - STATS_DELAY; //check all sessions if (sessions.size()){ for (std::map::iterator it = sessions.begin(); it != sessions.end(); it++){ @@ -1059,7 +1064,7 @@ void Controller::handlePrometheus(HTTP::Parser & H, Socket::Connection & conn, i //collect the data first std::map clients; unsigned long totClients = 0; - unsigned int t = Util::epoch() - 15; + unsigned int t = Util::epoch() - STATS_DELAY; //check all sessions if (sessions.size()){ for (std::map::iterator it = sessions.begin(); it != sessions.end(); it++){ @@ -1117,7 +1122,7 @@ void Controller::handlePrometheus(HTTP::Parser & H, Socket::Connection & conn, i //collect the data first std::map clients; unsigned long totClients = 0; - unsigned int t = Util::epoch() - 15; + unsigned int t = Util::epoch() - STATS_DELAY; //check all sessions if (sessions.size()){ for (std::map::iterator it = sessions.begin(); it != sessions.end(); it++){