mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +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();
|
||||
http_hooks_on_close();
|
||||
SrsStatistic::instance()->on_close(_srs_context->get_id());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -398,8 +399,7 @@ int SrsRtmpConn::stream_service_cycle()
|
|||
|
||||
// update the statistic when source disconveried.
|
||||
SrsStatistic* stat = SrsStatistic::instance();
|
||||
int client_id = _srs_context->get_id();
|
||||
if ((ret = stat->on_client(client_id, req)) != ERROR_SUCCESS) {
|
||||
if ((ret = stat->on_client(_srs_context->get_id(), req)) != ERROR_SUCCESS) {
|
||||
srs_error("stat client failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
@ -446,15 +446,9 @@ int SrsRtmpConn::stream_service_cycle()
|
|||
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());
|
||||
ret = playing(source);
|
||||
http_hooks_on_stop();
|
||||
stat->on_client_play_stop(client_id);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@ SrsStatisticStream::SrsStatisticStream()
|
|||
{
|
||||
id = __srs_generate_id();
|
||||
vhost = NULL;
|
||||
clients = 0;
|
||||
}
|
||||
|
||||
SrsStatisticStream::~SrsStatisticStream()
|
||||
|
@ -133,30 +132,22 @@ int SrsStatistic::on_client(int id, SrsRequest* req)
|
|||
client = clients[id];
|
||||
}
|
||||
|
||||
stream->clients[id] = client;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsStatistic::on_client_play_start(int id)
|
||||
int SrsStatistic::on_close(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;
|
||||
}
|
||||
|
||||
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--;
|
||||
SrsStatisticClient* client = it->second;
|
||||
client->stream->clients.erase(id);
|
||||
srs_freep(client);
|
||||
clients.erase(it);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -172,13 +163,10 @@ int SrsStatistic::dumps_vhosts(stringstream& ss)
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
ss << __SRS_JARRAY_START;
|
||||
bool first = true;
|
||||
std::map<std::string, SrsStatisticVhost*>::iterator it;
|
||||
for (it = vhosts.begin(); it != vhosts.end(); it++) {
|
||||
SrsStatisticVhost* vhost = it->second;
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
if (it != vhosts.begin()) {
|
||||
ss << __SRS_JFIELD_CONT;
|
||||
}
|
||||
|
||||
|
@ -197,13 +185,10 @@ int SrsStatistic::dumps_streams(stringstream& ss)
|
|||
int ret = ERROR_SUCCESS;
|
||||
|
||||
ss << __SRS_JARRAY_START;
|
||||
bool first = true;
|
||||
std::map<std::string, SrsStatisticStream*>::iterator it;
|
||||
for (it = streams.begin(); it != streams.end(); it++) {
|
||||
SrsStatisticStream* stream = it->second;
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
if (it != streams.begin()) {
|
||||
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_STR("name", stream->stream) << __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;
|
||||
}
|
||||
ss << __SRS_JARRAY_END;
|
||||
|
|
|
@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <string>
|
||||
|
||||
class SrsRequest;
|
||||
struct SrsStatisticClient;
|
||||
|
||||
struct SrsStatisticVhost
|
||||
{
|
||||
|
@ -53,7 +54,7 @@ public:
|
|||
std::string app;
|
||||
std::string stream;
|
||||
std::string url;
|
||||
int64_t clients;
|
||||
std::map<int, SrsStatisticClient*> clients;
|
||||
public:
|
||||
SrsStatisticStream();
|
||||
virtual ~SrsStatisticStream();
|
||||
|
@ -91,13 +92,9 @@ public:
|
|||
*/
|
||||
virtual int on_client(int id, SrsRequest* req);
|
||||
/**
|
||||
* client start play
|
||||
* client close
|
||||
*/
|
||||
virtual int on_client_play_start(int id);
|
||||
/**
|
||||
* client stop play
|
||||
*/
|
||||
virtual int on_client_play_stop(int id);
|
||||
virtual int on_close(int id);
|
||||
public:
|
||||
/**
|
||||
* get the server id, used to identify the server.
|
||||
|
|
Loading…
Reference in a new issue