mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
add client num in statistic with traverse every client
This commit is contained in:
parent
46d716612c
commit
310e49e7f3
3 changed files with 14 additions and 13 deletions
|
@ -200,7 +200,8 @@ int SrsRtmpConn::do_cycle()
|
||||||
|
|
||||||
ret = service_cycle();
|
ret = service_cycle();
|
||||||
http_hooks_on_close();
|
http_hooks_on_close();
|
||||||
SrsStatistic::instance()->on_close(_srs_context->get_id());
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
stat->on_close(_srs_context->get_id());
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,25 +132,18 @@ int SrsStatistic::on_client(int id, SrsRequest* req)
|
||||||
client = clients[id];
|
client = clients[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
stream->clients[id] = client;
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsStatistic::on_close(int id)
|
void SrsStatistic::on_close(int id)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
|
||||||
|
|
||||||
std::map<int, SrsStatisticClient*>::iterator it;
|
std::map<int, SrsStatisticClient*>::iterator it;
|
||||||
it = clients.find(id);
|
it = clients.find(id);
|
||||||
if (it != clients.end()) {
|
if (it != clients.end()) {
|
||||||
SrsStatisticClient* client = it->second;
|
SrsStatisticClient* client = it->second;
|
||||||
client->stream->clients.erase(id);
|
|
||||||
srs_freep(client);
|
srs_freep(client);
|
||||||
clients.erase(it);
|
clients.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsStatistic::server_id()
|
int64_t SrsStatistic::server_id()
|
||||||
|
@ -192,11 +185,20 @@ int SrsStatistic::dumps_streams(stringstream& ss)
|
||||||
ss << __SRS_JFIELD_CONT;
|
ss << __SRS_JFIELD_CONT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int client_num = 0;
|
||||||
|
std::map<int, SrsStatisticClient*>::iterator it_client;
|
||||||
|
for (it_client = clients.begin(); it_client != clients.end(); it_client++) {
|
||||||
|
SrsStatisticClient* client = it_client->second;
|
||||||
|
if (client->stream == stream) {
|
||||||
|
client_num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ss << __SRS_JOBJECT_START
|
ss << __SRS_JOBJECT_START
|
||||||
<< __SRS_JFIELD_ORG("id", stream->id) << __SRS_JFIELD_CONT
|
<< __SRS_JFIELD_ORG("id", stream->id) << __SRS_JFIELD_CONT
|
||||||
<< __SRS_JFIELD_STR("name", stream->stream) << __SRS_JFIELD_CONT
|
<< __SRS_JFIELD_STR("name", stream->stream) << __SRS_JFIELD_CONT
|
||||||
<< __SRS_JFIELD_ORG("vhost", stream->vhost->id) << __SRS_JFIELD_CONT
|
<< __SRS_JFIELD_ORG("vhost", stream->vhost->id) << __SRS_JFIELD_CONT
|
||||||
<< __SRS_JFIELD_ORG("clients", stream->clients.size())
|
<< __SRS_JFIELD_ORG("clients", client_num)
|
||||||
<< __SRS_JOBJECT_END;
|
<< __SRS_JOBJECT_END;
|
||||||
}
|
}
|
||||||
ss << __SRS_JARRAY_END;
|
ss << __SRS_JARRAY_END;
|
||||||
|
|
|
@ -34,7 +34,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class SrsRequest;
|
class SrsRequest;
|
||||||
struct SrsStatisticClient;
|
|
||||||
|
|
||||||
struct SrsStatisticVhost
|
struct SrsStatisticVhost
|
||||||
{
|
{
|
||||||
|
@ -54,7 +53,6 @@ public:
|
||||||
std::string app;
|
std::string app;
|
||||||
std::string stream;
|
std::string stream;
|
||||||
std::string url;
|
std::string url;
|
||||||
std::map<int, SrsStatisticClient*> clients;
|
|
||||||
public:
|
public:
|
||||||
SrsStatisticStream();
|
SrsStatisticStream();
|
||||||
virtual ~SrsStatisticStream();
|
virtual ~SrsStatisticStream();
|
||||||
|
@ -94,7 +92,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* client close
|
* client close
|
||||||
*/
|
*/
|
||||||
virtual int on_close(int id);
|
virtual void on_close(int id);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* get the server id, used to identify the server.
|
* get the server id, used to identify the server.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue