Skip to content

Instantly share code, notes, and snippets.

@dunkelstern
Created September 21, 2016 12:58
Show Gist options
  • Save dunkelstern/7123e48675b2fecef6407c10722aac29 to your computer and use it in GitHub Desktop.
Save dunkelstern/7123e48675b2fecef6407c10722aac29 to your computer and use it in GitHub Desktop.
nginx rtmp status style sheet
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/rtmp">
<xsl:text disable-output-escaping="yes">
<![CDATA[ <!DOCTYPE html> ]]>
</xsl:text>
<html>
<head>
<title>RTMP Statistics</title>
<style>
body {
font-family: sans-serif;
padding: 20px;
}
table.kv {
width: 400px;
border: 1px solid #c0c0c0;
border-collapse: collapse;
}
table.kv th {
text-align: left;
border-bottom: 1px solid #c0c0c0;
background-color: #f0f0f0;
padding: 5px;
}
table.kv td {
padding: 5px;
text-align: left;
}
table.kv tr:nth-child(even) {
background-color: #f8f8f8;
}
table.kv td:nth-of-type(2) {
text-align: right;
}
ul {
margin: 10px 0 10px 0;
}
</style>
</head>
<body>
<h1>RTMP Statistics</h1>
<table class="kv">
<tbody>
<tr>
<td>Uptime</td>
<td><xsl:value-of select="uptime"/></td>
<td>s</td>
</tr>
<tr>
<td>Accepted Connections</td>
<td><xsl:value-of select="naccepted"/></td>
<td></td>
</tr>
<tr>
<td>Bytes received</td>
<td><xsl:value-of select="format-number(bytes_in div 1048576, '#.#')"/></td>
<td>MiB</td>
</tr>
<tr>
<td>Bytes sent</td>
<td><xsl:value-of select="format-number(bytes_out div 1048576, '#.#')"/></td>
<td>MiB</td>
</tr>
<tr>
<td>Current bandwidth in</td>
<td><xsl:value-of select="format-number(bw_in div 1000000, '#.#')"/></td>
<td>Mb/s</td>
</tr>
<tr>
<td>Current bandwidth out</td>
<td><xsl:value-of select="format-number(bw_out div 1000000, '#.#')"/></td>
<td>Mb/s</td>
</tr>
</tbody>
</table>
<xsl:apply-templates select="server"/>
</body>
</html>
</xsl:template>
<xsl:template match="//application">
<xsl:variable name="app" select="name"/>
<h2><xsl:value-of select="$app"/></h2>
<ul>
<xsl:for-each select="live">
<xsl:apply-templates select="stream">
<xsl:with-param name="app" select="$app"/>
</xsl:apply-templates>
<xsl:if test="nclients &lt; 1">
<p>No streams</p>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="play">
<xsl:apply-templates select="stream">
<xsl:with-param name="app" select="$app"/>
</xsl:apply-templates>
<xsl:if test="nclients &lt; 1">
<p>No subscribers</p>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template match="//stream">
<xsl:param name="app">undefined</xsl:param>
<xsl:variable name="stream" select="name"/>
<li><strong><xsl:value-of select="$stream"/></strong><br/>
<xsl:if test="meta">
<ul>
<li><strong>Video</strong>: <xsl:value-of select="meta/video/width"/>x<xsl:value-of select="meta/video/height"/>@<xsl:value-of select="meta/video/frame_rate"/> (<xsl:value-of select="meta/video/codec"/>, <xsl:value-of select="meta/video/profile"/> profile, level <xsl:value-of select="meta/video/level"/>, <xsl:value-of select="format-number(bw_video div 1000, '#')"/> kbit)</li>
<li><strong>Audio</strong>: <xsl:value-of select="meta/audio/sample_rate"/> Hz, <xsl:value-of select="meta/audio/channels"/> channels (<xsl:value-of select="meta/audio/codec"/>, <xsl:value-of select="meta/audio/profile"/> profile, <xsl:value-of select="format-number(bw_audio div 1000, '#')"/> kbit)</li>
</ul>
</xsl:if>
<table class="kv">
<tbody>
<xsl:if test="time">
<tr>
<td>Time</td>
<td><xsl:value-of select="format-number(time div 1000, '#')"/></td>
<td>s</td>
</tr>
</xsl:if>
<xsl:if test="bytes_in">
<tr>
<td>Bytes received</td>
<td><xsl:value-of select="format-number(bytes_in div 1048576, '#.#')"/></td>
<td>MiB</td>
</tr>
</xsl:if>
<xsl:if test="bytes_out">
<tr>
<td>Bytes sent</td>
<td><xsl:value-of select="format-number(bytes_out div 1048576, '#.#')"/></td>
<td>MiB</td>
</tr>
</xsl:if>
<xsl:if test="bw_in">
<tr>
<td>Current bandwidth in</td>
<td><xsl:value-of select="format-number(bw_in div 1000000, '#.#')"/></td>
<td>Mb/s</td>
</tr>
</xsl:if>
<xsl:if test="bw_out">
<tr>
<td>Current bandwidth out</td>
<td><xsl:value-of select="format-number(bw_out div 1000000, '#.#')"/></td>
<td>Mb/s</td>
</tr>
</xsl:if>
</tbody>
</table>
<table class="kv">
<thead>
<tr>
<th>Client</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="client">
<tr>
<td>
<xsl:value-of select="address"/>:<xsl:value-of select="port"/>
<ul>
<li>
<xsl:choose>
<xsl:when test="publishing"><strong>Publisher</strong></xsl:when>
<xsl:otherwise><em>Subscriber</em></xsl:otherwise>
</xsl:choose>
</li>
<li>Online <xsl:value-of select="format-number(time div 1000, '#')"/> s</li>
<li><xsl:value-of select="format-number(bytes_in div 1048576, '#.#')"/> MiB in</li>
<li><xsl:value-of select="format-number(bytes_out div 1048576, '#.#')"/> MiB out</li>
</ul>
</td>
<xsl:choose>
<xsl:when test="publishing">
<td>
<a>
<xsl:attribute name="href">/control/drop/publisher?app=<xsl:value-of select="$app"/>&amp;name=<xsl:value-of select="$stream"/>&amp;clientid=<xsl:value-of select="id"/></xsl:attribute>
Drop
</a><br/>
<xsl:choose>
<xsl:when test="recording">
<a>
<xsl:attribute name="href">/control/record/stop?app=<xsl:value-of select="$app"/>&amp;name=<xsl:value-of select="$stream"/>&amp;rec=rec</xsl:attribute>
Stop Recording
</a>
</xsl:when>
<xsl:otherwise>
<a>
<xsl:attribute name="href">/control/record/start?app=<xsl:value-of select="$app"/>&amp;name=<xsl:value-of select="$stream"/>&amp;rec=rec</xsl:attribute>
Start Recording
</a>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:when>
<xsl:otherwise>
<td>
<a>
<xsl:attribute name="href">/control/drop/subscriber?app=<xsl:value-of select="$app"/>&amp;name=<xsl:value-of select="$stream"/>&amp;clientid=<xsl:value-of select="id"/></xsl:attribute>
Drop
</a>
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</tbody>
</table>
</li>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment