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