From e10a22503d052a05a1c0395752a3ed865a295b54 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 11 Oct 2016 15:19:14 +0200 Subject: [PATCH] Added per-output statistics --- src/controller/controller_statistics.cpp | 25 ++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/controller/controller_statistics.cpp b/src/controller/controller_statistics.cpp index cdb815e5..d486f64d 100644 --- a/src/controller/controller_statistics.cpp +++ b/src/controller/controller_statistics.cpp @@ -1290,6 +1290,7 @@ void Controller::handlePrometheus(HTTP::Parser & H, Socket::Connection & conn, i tthread::lock_guard guard(statsMutex); //collect the data first std::map streams; + std::map outputs; unsigned long totViewers = 0, totInputs = 0, totOutputs = 0; unsigned int t = Util::epoch() - STATS_DELAY; //check all sessions @@ -1300,6 +1301,7 @@ void Controller::handlePrometheus(HTTP::Parser & H, Socket::Connection & conn, i case SESS_UNSET: case SESS_VIEWER: streams[it->first.streamName].viewers++; + outputs[it->first.connector]++; totViewers++; break; case SESS_INPUT: @@ -1323,6 +1325,13 @@ void Controller::handlePrometheus(HTTP::Parser & H, Socket::Connection & conn, i response << "mist_sessions_total{sessType=\"outgoing\"} " << totOutputs << "\n"; response << "mist_sessions_total{sessType=\"cached\"} " << sessions.size() << "\n\n"; + response << "# HELP mist_outputs Number of viewers active right now, server-wide, by output type.\n"; + response << "# TYPE mist_outputs gauge\n"; + for (std::map::iterator it = outputs.begin(); it != outputs.end(); ++it){ + response << "mist_outputs{output=\"" << it->first << "\"} " << it->second << "\n"; + } + response << "\n"; + response << "# HELP mist_sessions_count Counts of unique sessions by type since server start.\n"; response << "# TYPE mist_sessions_count counter\n"; response << "mist_sessions_count{sessType=\"viewers\"} " << servViewers << "\n"; @@ -1368,6 +1377,7 @@ void Controller::handlePrometheus(HTTP::Parser & H, Socket::Connection & conn, i tthread::lock_guard guard(statsMutex); //collect the data first std::map streams; + std::map outputs; unsigned long totViewers = 0, totInputs = 0, totOutputs = 0; unsigned int t = Util::epoch() - STATS_DELAY; //check all sessions @@ -1378,6 +1388,7 @@ void Controller::handlePrometheus(HTTP::Parser & H, Socket::Connection & conn, i case SESS_UNSET: case SESS_VIEWER: streams[it->first.streamName].viewers++; + outputs[it->first.connector]++; totViewers++; break; case SESS_INPUT: @@ -1406,11 +1417,6 @@ void Controller::handlePrometheus(HTTP::Parser & H, Socket::Connection & conn, i resp["st"].append((long long)servUpBytes); resp["st"].append((long long)servDownBytes); - for (std::map::iterator it = streams.begin(); it != streams.end(); ++it){ - resp["streams"][it->first]["curr"].append((long long)it->second.viewers); - resp["streams"][it->first]["curr"].append((long long)it->second.inputs); - resp["streams"][it->first]["curr"].append((long long)it->second.outputs); - } for (std::map::iterator it = streamStats.begin(); it != streamStats.end(); ++it){ resp["streams"][it->first]["tot"].append((long long)it->second.viewers); @@ -1419,10 +1425,17 @@ void Controller::handlePrometheus(HTTP::Parser & H, Socket::Connection & conn, i resp["streams"][it->first]["bw"].append((long long)it->second.upBytes); resp["streams"][it->first]["bw"].append((long long)it->second.downBytes); } + for (std::map::iterator it = streams.begin(); it != streams.end(); ++it){ + resp["streams"][it->first]["curr"].append((long long)it->second.viewers); + resp["streams"][it->first]["curr"].append((long long)it->second.inputs); + resp["streams"][it->first]["curr"].append((long long)it->second.outputs); + } + for (std::map::iterator it = outputs.begin(); it != outputs.end(); ++it){ + resp["outputs"][it->first] = (long long)it->second; + } } - H.Chunkify(resp.toString(), conn); }