From c548077282a75024542bbc5f4358591c13899168 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 14 Apr 2016 12:39:20 +0200 Subject: [PATCH] Made fillActive calls (stats_streams and current_streams) only count users that have retrieved at least 128KiB of data, in order to filter out index and meta requests. --- src/controller/controller_statistics.cpp | 31 ++++++++++++++++++++++-- src/controller/controller_statistics.h | 2 ++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/controller/controller_statistics.cpp b/src/controller/controller_statistics.cpp index 3772242d..c8034f89 100644 --- a/src/controller/controller_statistics.cpp +++ b/src/controller/controller_statistics.cpp @@ -280,6 +280,33 @@ bool Controller::statSession::hasData(){ return false; } +/// Returns true if this session should count as a viewer on the given timestamp. +bool Controller::statSession::isViewerOn(unsigned long long t){ + return getUp(t) > 128 * 1024; +} + +/// Returns true if this session should count as a viewer +bool Controller::statSession::isViewer(){ + long long upTotal = 0; + if (oldConns.size()){ + for (std::deque::iterator it = oldConns.begin(); it != oldConns.end(); ++it){ + if (it->log.size()){ + upTotal += it->log.rbegin()->second.up; + if (upTotal > 128*1024){return true;} + } + } + } + if (curConns.size()){ + for (std::map::iterator it = curConns.begin(); it != curConns.end(); ++it){ + if (it->second.log.size()){ + upTotal += it->second.log.rbegin()->second.up; + if (upTotal > 128*1024){return true;} + } + } + } + return false; +} + /// Returns the cumulative connected time for this session at timestamp t. long long Controller::statSession::getConnTime(unsigned long long t){ long long retVal = 0; @@ -642,10 +669,10 @@ void Controller::fillActive(JSON::Value & req, JSON::Value & rep, bool onlyNow){ //check all sessions if (sessions.size()){ for (std::map::iterator it = sessions.begin(); it != sessions.end(); it++){ - if (onlyNow || it->second.hasDataFor(t)){ + if (onlyNow || it->second.isViewerOn(t)){ streams.insert(it->first.streamName); } - if (it->second.hasDataFor(t)){ + if (it->second.isViewerOn(t)){ streams.insert(it->first.streamName); clients[it->first.streamName]++; } diff --git a/src/controller/controller_statistics.h b/src/controller/controller_statistics.h index 0a5d8972..5f43e6d5 100644 --- a/src/controller/controller_statistics.h +++ b/src/controller/controller_statistics.h @@ -67,6 +67,8 @@ namespace Controller { void update(unsigned long index, IPC::statExchange & data); unsigned long long getStart(); unsigned long long getEnd(); + bool isViewerOn(unsigned long long time); + bool isViewer(); bool hasDataFor(unsigned long long time); bool hasData(); long long getConnTime(unsigned long long time);