Clear prometheus output of inactive streams, make stats_streams and active_streams calls just as accurate as prometheus viewer counts.

This commit is contained in:
Thulinma 2016-05-19 01:14:07 +02:00
parent bb1c919948
commit 146685aca6

View file

@ -164,13 +164,14 @@ void Controller::SharedMemStats(void * config){
} }
if (activeStreams.size()){ if (activeStreams.size()){
for (std::map<std::string, unsigned int>::iterator it = activeStreams.begin(); it != activeStreams.end(); ++it){ for (std::map<std::string, unsigned int>::iterator it = activeStreams.begin(); it != activeStreams.end(); ++it){
if (++it->second > 1){ if (++it->second > STATS_DELAY){
streamStopped(it->first); streamStopped(it->first);
inactiveStreams.insert(it->first); inactiveStreams.insert(it->first);
} }
} }
while (inactiveStreams.size()){ while (inactiveStreams.size()){
activeStreams.erase(*inactiveStreams.begin()); activeStreams.erase(*inactiveStreams.begin());
streamStats.erase(*inactiveStreams.begin());
inactiveStreams.erase(inactiveStreams.begin()); inactiveStreams.erase(inactiveStreams.begin());
} }
} }
@ -835,15 +836,14 @@ void Controller::fillActive(JSON::Value & req, JSON::Value & rep, bool onlyNow){
//check all sessions //check all sessions
if (sessions.size()){ if (sessions.size()){
for (std::map<sessIndex, statSession>::iterator it = sessions.begin(); it != sessions.end(); it++){ for (std::map<sessIndex, statSession>::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); streams.insert(it->first.streamName);
if (it->second.getSessType() == SESS_VIEWER){
clients[it->first.streamName]++; clients[it->first.streamName]++;
} }
} }
} }
}
//Good, now output what we found... //Good, now output what we found...
rep.null(); rep.null();
for (std::set<std::string>::iterator it = streams.begin(); it != streams.end(); it++){ for (std::set<std::string>::iterator it = streams.begin(); it != streams.end(); it++){