added audio and video bw to stat

This commit is contained in:
Roman Arutyunyan 2013-12-23 20:24:40 +04:00
parent da0128a2fc
commit 6bb620f2fc
5 changed files with 72 additions and 36 deletions

View file

@ -13,7 +13,7 @@
/* Bandwidth update interval in seconds */
#define NGX_RTMP_BANDWIDTH_INTERVAL 60
#define NGX_RTMP_BANDWIDTH_INTERVAL 10
typedef struct {

View file

@ -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;
}

View file

@ -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;

View file

@ -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("<in>");
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
"%uL", bw_in->bytes) - buf);
NGX_RTMP_STAT_L("</in>\r\n");
if (flags & NGX_RTMP_STAT_BW) {
NGX_RTMP_STAT_L("<bw_");
NGX_RTMP_STAT_CS(name);
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), ">%uL</bw_",
bw->bandwidth * 8)
- buf);
NGX_RTMP_STAT_CS(name);
NGX_RTMP_STAT_L(">\r\n");
}
NGX_RTMP_STAT_L("<out>");
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
"%uL", bw_out->bytes) - buf);
NGX_RTMP_STAT_L("</out>\r\n");
NGX_RTMP_STAT_L("<bwin>");
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
"%uL", bw_in->bandwidth * 8) - buf);
NGX_RTMP_STAT_L("</bwin>\r\n");
NGX_RTMP_STAT_L("<bwout>");
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
"%uL", bw_out->bandwidth * 8) - buf);
NGX_RTMP_STAT_L("</bwout>\r\n");
if (flags & NGX_RTMP_STAT_BYTES) {
NGX_RTMP_STAT_L("<bytes_");
NGX_RTMP_STAT_CS(name);
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), ">%uL</bytes_",
bw->bytes)
- 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("</time>");
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("</naccepted>\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) {

View file

@ -33,10 +33,10 @@
<th>#clients</th>
<th>In bytes</th>
<th>Out bytes</th>
<th>Input bits/s</th>
<th>Output bits/s</th>
<th colspan="3">Video</th>
<th colspan="3">Audio</th>
<th>In bits/s</th>
<th>Out bits/s</th>
<th colspan="4">Video</th>
<th colspan="4">Audio</th>
<th>State</th>
<th>Time</th>
</tr>
@ -44,32 +44,34 @@
<td colspan="2">Accepted: <xsl:value-of select="naccepted"/></td>
<td>
<xsl:call-template name="showsize">
<xsl:with-param name="size" select="in"/>
<xsl:with-param name="size" select="bytes_in"/>
</xsl:call-template>
</td>
<td>
<xsl:call-template name="showsize">
<xsl:with-param name="size" select="out"/>
<xsl:with-param name="size" select="bytes_out"/>
</xsl:call-template>
</td>
<td>
<xsl:call-template name="showsize">
<xsl:with-param name="size" select="bwin"/>
<xsl:with-param name="size" select="bw_in"/>
<xsl:with-param name="bits" select="1"/>
<xsl:with-param name="persec" select="1"/>
</xsl:call-template>
</td>
<td>
<xsl:call-template name="showsize">
<xsl:with-param name="size" select="bwout"/>
<xsl:with-param name="size" select="bw_out"/>
<xsl:with-param name="bits" select="1"/>
<xsl:with-param name="persec" select="1"/>
</xsl:call-template>
</td>
<th bgcolor="#999999">codec</th>
<th bgcolor="#999999">bits/s</th>
<th bgcolor="#999999">size</th>
<th bgcolor="#999999">fps</th>
<th bgcolor="#999999">codec</th>
<th bgcolor="#999999">bits/s</th>
<th bgcolor="#999999">freq</th>
<th bgcolor="#999999">chan</th>
<td/>
@ -145,24 +147,24 @@
<td align="middle"> <xsl:value-of select="nclients"/> </td>
<td>
<xsl:call-template name="showsize">
<xsl:with-param name="size" select="in"/>
<xsl:with-param name="size" select="bytes_in"/>
</xsl:call-template>
</td>
<td>
<xsl:call-template name="showsize">
<xsl:with-param name="size" select="out"/>
<xsl:with-param name="size" select="bytes_out"/>
</xsl:call-template>
</td>
<td>
<xsl:call-template name="showsize">
<xsl:with-param name="size" select="bwin"/>
<xsl:with-param name="size" select="bw_in"/>
<xsl:with-param name="bits" select="1"/>
<xsl:with-param name="persec" select="1"/>
</xsl:call-template>
</td>
<td>
<xsl:call-template name="showsize">
<xsl:with-param name="size" select="bwout"/>
<xsl:with-param name="size" select="bw_out"/>
<xsl:with-param name="bits" select="1"/>
<xsl:with-param name="persec" select="1"/>
</xsl:call-template>
@ -170,6 +172,13 @@
<td>
<xsl:value-of select="meta/video/codec"/>&#160;<xsl:value-of select="meta/video/profile"/>&#160;<xsl:value-of select="meta/video/level"/>
</td>
<td>
<xsl:call-template name="showsize">
<xsl:with-param name="size" select="bw_video"/>
<xsl:with-param name="bits" select="1"/>
<xsl:with-param name="persec" select="1"/>
</xsl:call-template>
</td>
<td>
<xsl:apply-templates select="meta/video/width"/>
</td>
@ -179,6 +188,13 @@
<td>
<xsl:value-of select="meta/audio/codec"/>&#160;<xsl:value-of select="meta/audio/profile"/>
</td>
<td>
<xsl:call-template name="showsize">
<xsl:with-param name="size" select="bw_audio"/>
<xsl:with-param name="bits" select="1"/>
<xsl:with-param name="persec" select="1"/>
</xsl:call-template>
</td>
<td>
<xsl:apply-templates select="meta/audio/sample_rate"/>
</td>