From 146685aca6a68c96957bce872f30ad4fb4ebb0d6 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 19 May 2016 01:14:07 +0200 Subject: [PATCH] Clear prometheus output of inactive streams, make stats_streams and active_streams calls just as accurate as prometheus viewer counts. --- src/controller/controller_statistics.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/controller/controller_statistics.cpp b/src/controller/controller_statistics.cpp index c8a3bd23..7db194b1 100644 --- a/src/controller/controller_statistics.cpp +++ b/src/controller/controller_statistics.cpp @@ -164,13 +164,14 @@ void Controller::SharedMemStats(void * config){ } if (activeStreams.size()){ for (std::map::iterator it = activeStreams.begin(); it != activeStreams.end(); ++it){ - if (++it->second > 1){ + if (++it->second > STATS_DELAY){ streamStopped(it->first); inactiveStreams.insert(it->first); } } while (inactiveStreams.size()){ activeStreams.erase(*inactiveStreams.begin()); + streamStats.erase(*inactiveStreams.begin()); inactiveStreams.erase(inactiveStreams.begin()); } } @@ -835,12 +836,11 @@ 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.hasDataFor(t) && it->second.isViewerOn(t))){ streams.insert(it->first.streamName); - } - if (it->second.hasDataFor(t) && it->second.isViewerOn(t)){ - streams.insert(it->first.streamName); - clients[it->first.streamName]++; + if (it->second.getSessType() == SESS_VIEWER){ + clients[it->first.streamName]++; + } } } }