mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
add client num for stream in statistic
This commit is contained in:
parent
08e9f6ef42
commit
46d716612c
3 changed files with 16 additions and 40 deletions
|
@ -200,6 +200,7 @@ 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());
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -398,8 +399,7 @@ int SrsRtmpConn::stream_service_cycle()
|
||||||
|
|
||||||
// update the statistic when source disconveried.
|
// update the statistic when source disconveried.
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
int client_id = _srs_context->get_id();
|
if ((ret = stat->on_client(_srs_context->get_id(), req)) != ERROR_SUCCESS) {
|
||||||
if ((ret = stat->on_client(client_id, req)) != ERROR_SUCCESS) {
|
|
||||||
srs_error("stat client failed. ret=%d", ret);
|
srs_error("stat client failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -446,15 +446,9 @@ int SrsRtmpConn::stream_service_cycle()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = stat->on_client_play_start(client_id)) != ERROR_SUCCESS) {
|
|
||||||
srs_error("stat client play start failed. ret=%d", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
srs_info("start to play stream %s success", req->stream.c_str());
|
srs_info("start to play stream %s success", req->stream.c_str());
|
||||||
ret = playing(source);
|
ret = playing(source);
|
||||||
http_hooks_on_stop();
|
http_hooks_on_stop();
|
||||||
stat->on_client_play_stop(client_id);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@ SrsStatisticStream::SrsStatisticStream()
|
||||||
{
|
{
|
||||||
id = __srs_generate_id();
|
id = __srs_generate_id();
|
||||||
vhost = NULL;
|
vhost = NULL;
|
||||||
clients = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsStatisticStream::~SrsStatisticStream()
|
SrsStatisticStream::~SrsStatisticStream()
|
||||||
|
@ -133,30 +132,22 @@ 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_client_play_start(int id)
|
int SrsStatistic::on_close(int id)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
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()) {
|
||||||
it->second->stream->clients++;
|
SrsStatisticClient* client = it->second;
|
||||||
}
|
client->stream->clients.erase(id);
|
||||||
|
srs_freep(client);
|
||||||
return ret;
|
clients.erase(it);
|
||||||
}
|
|
||||||
|
|
||||||
int SrsStatistic::on_client_play_stop(int id)
|
|
||||||
{
|
|
||||||
int ret = ERROR_SUCCESS;
|
|
||||||
|
|
||||||
std::map<int, SrsStatisticClient*>::iterator it;
|
|
||||||
it = clients.find(id);
|
|
||||||
if (it != clients.end()) {
|
|
||||||
it->second->stream->clients--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -172,13 +163,10 @@ int SrsStatistic::dumps_vhosts(stringstream& ss)
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
ss << __SRS_JARRAY_START;
|
ss << __SRS_JARRAY_START;
|
||||||
bool first = true;
|
|
||||||
std::map<std::string, SrsStatisticVhost*>::iterator it;
|
std::map<std::string, SrsStatisticVhost*>::iterator it;
|
||||||
for (it = vhosts.begin(); it != vhosts.end(); it++) {
|
for (it = vhosts.begin(); it != vhosts.end(); it++) {
|
||||||
SrsStatisticVhost* vhost = it->second;
|
SrsStatisticVhost* vhost = it->second;
|
||||||
if (first) {
|
if (it != vhosts.begin()) {
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
ss << __SRS_JFIELD_CONT;
|
ss << __SRS_JFIELD_CONT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,13 +185,10 @@ int SrsStatistic::dumps_streams(stringstream& ss)
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
ss << __SRS_JARRAY_START;
|
ss << __SRS_JARRAY_START;
|
||||||
bool first = true;
|
|
||||||
std::map<std::string, SrsStatisticStream*>::iterator it;
|
std::map<std::string, SrsStatisticStream*>::iterator it;
|
||||||
for (it = streams.begin(); it != streams.end(); it++) {
|
for (it = streams.begin(); it != streams.end(); it++) {
|
||||||
SrsStatisticStream* stream = it->second;
|
SrsStatisticStream* stream = it->second;
|
||||||
if (first) {
|
if (it != streams.begin()) {
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
ss << __SRS_JFIELD_CONT;
|
ss << __SRS_JFIELD_CONT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +196,7 @@ int SrsStatistic::dumps_streams(stringstream& ss)
|
||||||
<< __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)
|
<< __SRS_JFIELD_ORG("clients", stream->clients.size())
|
||||||
<< __SRS_JOBJECT_END;
|
<< __SRS_JOBJECT_END;
|
||||||
}
|
}
|
||||||
ss << __SRS_JARRAY_END;
|
ss << __SRS_JARRAY_END;
|
||||||
|
|
|
@ -34,6 +34,7 @@ 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
|
||||||
{
|
{
|
||||||
|
@ -53,7 +54,7 @@ public:
|
||||||
std::string app;
|
std::string app;
|
||||||
std::string stream;
|
std::string stream;
|
||||||
std::string url;
|
std::string url;
|
||||||
int64_t clients;
|
std::map<int, SrsStatisticClient*> clients;
|
||||||
public:
|
public:
|
||||||
SrsStatisticStream();
|
SrsStatisticStream();
|
||||||
virtual ~SrsStatisticStream();
|
virtual ~SrsStatisticStream();
|
||||||
|
@ -91,13 +92,9 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual int on_client(int id, SrsRequest* req);
|
virtual int on_client(int id, SrsRequest* req);
|
||||||
/**
|
/**
|
||||||
* client start play
|
* client close
|
||||||
*/
|
*/
|
||||||
virtual int on_client_play_start(int id);
|
virtual int on_close(int id);
|
||||||
/**
|
|
||||||
* client stop play
|
|
||||||
*/
|
|
||||||
virtual int on_client_play_stop(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