1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-12 11:21:52 +00:00

add connections count to api summaries. 0.9.127

This commit is contained in:
winlin 2014-06-19 18:49:05 +08:00
parent 603b3bcdcc
commit 094d82bd06
6 changed files with 97 additions and 15 deletions

View file

@ -240,6 +240,7 @@ Supported operating systems and hardware:
* 2013-10-17, Created.<br/>
## History
* v1.0, 2014-06-19, add connections count to api summaries. 0.9.127
* v1.0, 2014-06-19, add srs bytes and kbps to api summaries. 0.9.126
* v1.0, 2014-06-18, add network bytes to api summaries. 0.9.125
* v1.0, 2014-06-14, fix [#98](https://github.com/winlinvip/simple-rtmp-server/issues/98), workaround for librtmp ping(fmt=1,cid=2 fresh stream). 0.9.124

View file

@ -462,7 +462,12 @@ int SrsApiSummaries::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
<< JFIELD_ORG("srs_recv_bytes", nrs->rbytes) << JFIELD_CONT
<< JFIELD_ORG("srs_recv_kbps", nrs->rkbps) << JFIELD_CONT
<< JFIELD_ORG("srs_send_bytes", nrs->sbytes) << JFIELD_CONT
<< JFIELD_ORG("srs_send_kbps", nrs->skbps)
<< JFIELD_ORG("srs_send_kbps", nrs->skbps) << JFIELD_CONT
<< JFIELD_ORG("conn_sys", nrs->nb_conn_sys) << JFIELD_CONT
<< JFIELD_ORG("conn_sys_et", nrs->nb_conn_sys_et) << JFIELD_CONT
<< JFIELD_ORG("conn_sys_tw", nrs->nb_conn_sys_tw) << JFIELD_CONT
<< JFIELD_ORG("conn_sys_ls", nrs->nb_conn_sys_ls) << JFIELD_CONT
<< JFIELD_ORG("conn_srs", nrs->nb_conn_srs)
<< JOBJECT_END
<< JOBJECT_END
<< JOBJECT_END;

View file

@ -733,7 +733,7 @@ int SrsServer::do_cycle()
if ((i % SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES) == 0) {
srs_info("update network rtmp server info.");
resample_kbps(NULL);
srs_update_rtmp_server(kbps);
srs_update_rtmp_server((int)conns.size(), kbps);
}
#ifdef SRS_AUTO_HTTP_PARSER
if (_srs_config->get_heartbeat_enabled()) {

View file

@ -528,6 +528,8 @@ SrsNetworkRtmpServer::SrsNetworkRtmpServer()
{
ok = false;
sample_time = rbytes = sbytes = 0;
nb_conn_sys = nb_conn_srs = 0;
nb_conn_sys_et = nb_conn_sys_tw = nb_conn_sys_ls = 0;
}
static SrsNetworkRtmpServer _srs_network_rtmp_server;
@ -537,23 +539,90 @@ SrsNetworkRtmpServer* srs_get_network_rtmp_server()
return &_srs_network_rtmp_server;
}
void srs_update_rtmp_server(SrsKbps* kbps)
// @see: http://stackoverflow.com/questions/5992211/list-of-possible-internal-socket-statuses-from-proc
enum {
SYS_TCP_ESTABLISHED = 1,
SYS_TCP_SYN_SENT,
SYS_TCP_SYN_RECV,
SYS_TCP_FIN_WAIT1,
SYS_TCP_FIN_WAIT2,
SYS_TCP_TIME_WAIT,
SYS_TCP_CLOSE,
SYS_TCP_CLOSE_WAIT,
SYS_TCP_LAST_ACK,
SYS_TCP_LISTEN,
SYS_TCP_CLOSING, /* Now a valid state */
SYS_TCP_MAX_STATES /* Leave at the end! */
};
void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
{
SrsNetworkRtmpServer& r = _srs_network_rtmp_server;
r.ok = true;
if (true) {
FILE* f = fopen("/proc/net/tcp", "r");
if (f == NULL) {
srs_warn("open proc network tcp failed, ignore");
return;
}
// ignore title.
static char buf[1024];
fgets(buf, sizeof(buf), f);
r.sample_time = srs_get_system_time_ms();
int nb_conn_sys_established = 0;
int nb_conn_sys_time_wait = 0;
int nb_conn_sys_listen = 0;
int nb_conn_sys_other = 0;
for (;;) {
int st = 0;
r.rbytes = kbps->get_recv_bytes();
r.rkbps = kbps->get_recv_kbps();
r.rkbps_30s = kbps->get_recv_kbps_30s();
r.rkbps_5m = kbps->get_recv_kbps_5m();
int ret = fscanf(f, "%*s %*s %*s %2x\n", &st);
// ignore to end.
fgets(buf, sizeof(buf), f);
if (ret == 1) {
if (st == SYS_TCP_ESTABLISHED) {
nb_conn_sys_established++;
} else if (st == SYS_TCP_TIME_WAIT) {
nb_conn_sys_time_wait++;
} else if (st == SYS_TCP_LISTEN) {
nb_conn_sys_listen++;
} else {
nb_conn_sys_other++;
}
}
if (ret == EOF) {
break;
}
}
r.nb_conn_sys = nb_conn_sys_established + nb_conn_sys_time_wait + nb_conn_sys_listen + nb_conn_sys_other;
r.nb_conn_sys_et = nb_conn_sys_established;
r.nb_conn_sys_tw = nb_conn_sys_time_wait;
r.nb_conn_sys_ls = nb_conn_sys_listen;
r.sbytes = kbps->get_send_bytes();
r.skbps = kbps->get_send_kbps();
r.skbps_30s = kbps->get_send_kbps_30s();
r.skbps_5m = kbps->get_send_kbps_5m();
fclose(f);
}
if (true) {
r.ok = true;
r.nb_conn_srs = nb_conn;
r.sample_time = srs_get_system_time_ms();
r.rbytes = kbps->get_recv_bytes();
r.rkbps = kbps->get_recv_kbps();
r.rkbps_30s = kbps->get_recv_kbps_30s();
r.rkbps_5m = kbps->get_recv_kbps_5m();
r.sbytes = kbps->get_send_bytes();
r.skbps = kbps->get_send_kbps();
r.skbps_30s = kbps->get_send_kbps_30s();
r.skbps_5m = kbps->get_send_kbps_5m();
}
}
vector<string> _srs_system_ipv4_ips;

View file

@ -414,13 +414,20 @@ public:
int skbps_30s;
int skbps_5m;
// connections
int nb_conn_sys;
int nb_conn_sys_et; // established
int nb_conn_sys_tw; // time wait
int nb_conn_sys_ls; // listen
int nb_conn_srs;
SrsNetworkRtmpServer();
};
// get network devices info, use cache to avoid performance problem.
extern SrsNetworkRtmpServer* srs_get_network_rtmp_server();
// the deamon st-thread will update it.
extern void srs_update_rtmp_server(SrsKbps* kbps);
extern void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps);
// get local ip, fill to @param ips
extern void srs_retrieve_local_ipv4_ips();

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR "0"
#define VERSION_MINOR "9"
#define VERSION_REVISION "126"
#define VERSION_REVISION "127"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "SRS"