From 6bb620f2fcc58b85beeaf2db66e923d80ee8e430 Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Mon, 23 Dec 2013 20:24:40 +0400 Subject: [PATCH] added audio and video bw to stat --- ngx_rtmp_bandwidth.h | 2 +- ngx_rtmp_live_module.c | 5 ++++ ngx_rtmp_live_module.h | 2 ++ ngx_rtmp_stat_module.c | 59 ++++++++++++++++++++++++++---------------- stat.xsl | 40 +++++++++++++++++++--------- 5 files changed, 72 insertions(+), 36 deletions(-) diff --git a/ngx_rtmp_bandwidth.h b/ngx_rtmp_bandwidth.h index 0d9d323..b498482 100644 --- a/ngx_rtmp_bandwidth.h +++ b/ngx_rtmp_bandwidth.h @@ -13,7 +13,7 @@ /* Bandwidth update interval in seconds */ -#define NGX_RTMP_BANDWIDTH_INTERVAL 60 +#define NGX_RTMP_BANDWIDTH_INTERVAL 10 typedef struct { diff --git a/ngx_rtmp_live_module.c b/ngx_rtmp_live_module.c index eeff441..5bebb9e 100644 --- a/ngx_rtmp_live_module.c +++ b/ngx_rtmp_live_module.c @@ -1028,6 +1028,11 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, ngx_rtmp_update_bandwidth(&ctx->stream->bw_in, h->mlen); ngx_rtmp_update_bandwidth(&ctx->stream->bw_out, h->mlen * peers); + ngx_rtmp_update_bandwidth(h->type == NGX_RTMP_MSG_AUDIO ? + &ctx->stream->bw_in_audio : + &ctx->stream->bw_in_video, + h->mlen); + return NGX_OK; } diff --git a/ngx_rtmp_live_module.h b/ngx_rtmp_live_module.h index 5d9612c..71eca36 100644 --- a/ngx_rtmp_live_module.h +++ b/ngx_rtmp_live_module.h @@ -48,6 +48,8 @@ struct ngx_rtmp_live_stream_s { ngx_rtmp_live_stream_t *next; ngx_rtmp_live_ctx_t *ctx; ngx_rtmp_bandwidth_t bw_in; + ngx_rtmp_bandwidth_t bw_in_audio; + ngx_rtmp_bandwidth_t bw_in_video; ngx_rtmp_bandwidth_t bw_out; ngx_msec_t epoch; unsigned active:1; diff --git a/ngx_rtmp_stat_module.c b/ngx_rtmp_stat_module.c index 975ca93..5e67770 100644 --- a/ngx_rtmp_stat_module.c +++ b/ngx_rtmp_stat_module.c @@ -245,34 +245,39 @@ ngx_rtmp_stat_output(ngx_http_request_t *r, ngx_chain_t ***lll, #define NGX_RTMP_STAT_ECS(s) NGX_RTMP_STAT_E((s), ngx_strlen(s)) +#define NGX_RTMP_STAT_BW 0x01 +#define NGX_RTMP_STAT_BYTES 0x02 +#define NGX_RTMP_STAT_BW_BYTES 0x03 + + static void ngx_rtmp_stat_bw(ngx_http_request_t *r, ngx_chain_t ***lll, - ngx_rtmp_bandwidth_t *bw_in, ngx_rtmp_bandwidth_t *bw_out) + ngx_rtmp_bandwidth_t *bw, char *name, + ngx_uint_t flags) { u_char buf[NGX_INT64_LEN + 1]; - ngx_rtmp_update_bandwidth(bw_in, 0); - ngx_rtmp_update_bandwidth(bw_out, 0); + ngx_rtmp_update_bandwidth(bw, 0); - NGX_RTMP_STAT_L(""); - NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), - "%uL", bw_in->bytes) - buf); - NGX_RTMP_STAT_L("\r\n"); + if (flags & NGX_RTMP_STAT_BW) { + NGX_RTMP_STAT_L("%uLbandwidth * 8) + - buf); + NGX_RTMP_STAT_CS(name); + NGX_RTMP_STAT_L(">\r\n"); + } - NGX_RTMP_STAT_L(""); - NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), - "%uL", bw_out->bytes) - buf); - NGX_RTMP_STAT_L("\r\n"); - - NGX_RTMP_STAT_L(""); - NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), - "%uL", bw_in->bandwidth * 8) - buf); - NGX_RTMP_STAT_L("\r\n"); - - NGX_RTMP_STAT_L(""); - NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), - "%uL", bw_out->bandwidth * 8) - buf); - NGX_RTMP_STAT_L("\r\n"); + if (flags & NGX_RTMP_STAT_BYTES) { + NGX_RTMP_STAT_L("%uLbytes) + - buf); + NGX_RTMP_STAT_CS(name); + NGX_RTMP_STAT_L(">\r\n"); + } } @@ -440,7 +445,14 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll, - buf); NGX_RTMP_STAT_L(""); - ngx_rtmp_stat_bw(r, lll, &stream->bw_in, &stream->bw_out); + ngx_rtmp_stat_bw(r, lll, &stream->bw_in, "in", + NGX_RTMP_STAT_BW_BYTES); + ngx_rtmp_stat_bw(r, lll, &stream->bw_out, "out", + NGX_RTMP_STAT_BW_BYTES); + ngx_rtmp_stat_bw(r, lll, &stream->bw_in_audio, "audio", + NGX_RTMP_STAT_BW); + ngx_rtmp_stat_bw(r, lll, &stream->bw_in_video, "video", + NGX_RTMP_STAT_BW); nclients = 0; codec = NULL; @@ -773,7 +785,8 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r) "%ui", ngx_rtmp_naccepted) - nbuf); NGX_RTMP_STAT_L("\r\n"); - ngx_rtmp_stat_bw(r, lll, &ngx_rtmp_bw_in, &ngx_rtmp_bw_out); + ngx_rtmp_stat_bw(r, lll, &ngx_rtmp_bw_in, "in", NGX_RTMP_STAT_BW_BYTES); + ngx_rtmp_stat_bw(r, lll, &ngx_rtmp_bw_out, "out", NGX_RTMP_STAT_BW_BYTES); cscf = cmcf->servers.elts; for (n = 0; n < cmcf->servers.nelts; ++n, ++cscf) { diff --git a/stat.xsl b/stat.xsl index d4700ef..6d05308 100644 --- a/stat.xsl +++ b/stat.xsl @@ -33,10 +33,10 @@ #clients In bytes Out bytes - Input bits/s - Output bits/s - Video - Audio + In bits/s + Out bits/s + Video + Audio State Time @@ -44,32 +44,34 @@ Accepted: - + - + - + - + codec + bits/s size fps codec + bits/s freq chan @@ -145,24 +147,24 @@ - + - + - + - + @@ -170,6 +172,13 @@    + + + + + + + @@ -179,6 +188,13 @@   + + + + + + +