<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>docs/content/features/metrics.md - fork/static-web-server @ allow-symlink</title>
<meta name="description" content="docs/content/features/metrics.md in fork/static-web-server at allow-symlink.">
<meta property="og:title" content="docs/content/features/metrics.md - fork/static-web-server @ allow-symlink">
<meta property="og:description" content="docs/content/features/metrics.md in fork/static-web-server at allow-symlink.">
<meta property="og:type" content="website">
<meta property="og:site_name" content="git.julia.blue">
<link rel="stylesheet" href="/css/style.css?v=62">
<script type="module" src="/js/main.js?v=62"></script>
</head>
<body>
<main data-ref="allow-symlink" data-tip="4414610fe1b0370ff0ac415e9367548840584710">
<noscript>
  <div class="callout">
    <p>
      hey! this is a static git repo viewer. commit diffs, file history,
      older commits and other revisions won't load without javascript.
    </p>
    <p>
      you are still able to view source files on branch/tag tips,
      but the experience is degraded.
    </p>
  </div>
</noscript>
<header class="repo"><div>
<h1>fork/static-web-server</h1>
</div>
<pre class="clone">git clone https://git.julia.blue/fork/static-web-server</pre>
</header>
<p class="snapshot-commit"><span class="commit-author">Chris Snell</span><span class="commit-message" data-commit="0a8c8cac01228b0ac5a7f0ce59d51eef8800e12b">docs: metrics feature documenation page (#633)</span><span class="snapshot-sha sha" data-commit="0a8c8cac01228b0ac5a7f0ce59d51eef8800e12b">0a8c8ca</span><time datetime="2026-02-27T13:49:40-07:00" title="2026-02-27 13:49:40 -0700">2026-02-27</time></p>
<header class="topbar"><details class="switcher"><summary>allow-symlink</summary><div class="menu"><strong>branches</strong><a class="current" href="/fork/static-web-server/ref/allow-symlink/">allow-symlink</a><a class="all" href="/fork/static-web-server/refs">all refs →</a></div></details><nav class="crumbs"><a href="/fork/static-web-server/">static-web-server</a> / <a href="/fork/static-web-server/ref/allow-symlink/tree/docs/">docs</a> / <a href="/fork/static-web-server/ref/allow-symlink/tree/docs/content/">content</a> / <a href="/fork/static-web-server/ref/allow-symlink/tree/docs/content/features/">features</a> / <span class="cur">metrics.md</span></nav>
<span class="view-stats"><span>2.3 KiB</span><span>51 lines</span></span><span class="actions"><a class="raw" href="/fork/static-web-server/raw/41a8faa98f6e53dd23256b796fa64322df037b48/docs/content/features/metrics.md">raw</a></span></header>
<div class="markdown-view"><input type="radio" name="markdown-view" id="markdown-rendered" checked><label for="markdown-rendered">rendered</label><input type="radio" name="markdown-view" id="markdown-code"><label for="markdown-code">code</label><section class="readme rendered"><h1>Metrics</h1>
<p>SWS provides an optional <code>/metrics</code> endpoint that exposes Prometheus-compatible metrics about HTTP traffic. Useful for monitoring request rates, latency, error rates, and connection counts.</p>
<p>This feature is disabled by default and can be controlled by the boolean <code>--metrics</code> option or the equivalent <a href="/fork/static-web-server/ref/allow-symlink/blob/docs/content/configuration/environment-variables.md#server_metrics">SERVER_METRICS</a> env.</p>
<h2>Exposed metrics</h2>
<table><thead><tr><th>Metric</th><th>Type</th><th>Labels</th><th>Description</th></tr></thead><tbody>
<tr><td><code>sws_http_requests_total</code></td><td>Counter</td><td>method, status, host</td><td>Total requests by method, status class (2xx, 4xx, etc.), and Host header</td></tr>
<tr><td><code>sws_http_request_duration_seconds</code></td><td>Histogram</td><td>method, status, host</td><td>Request latency with buckets from 50µs to 10s</td></tr>
<tr><td><code>sws_http_response_bytes_total</code></td><td>Counter</td><td>method, status, host</td><td>Total response bytes (from Content-Length)</td></tr>
<tr><td><code>sws_http_requests_inflight</code></td><td>Gauge</td><td>—</td><td>Requests currently being processed</td></tr>
<tr><td><code>sws_http_connections_active</code></td><td>Gauge</td><td>—</td><td>Active HTTP connections</td></tr>
</tbody></table>
<p>When built with the <code>experimental</code> feature and <code>RUSTFLAGS="--cfg tokio_unstable"</code>, Tokio runtime metrics (worker threads, task scheduling, etc.) are also included in the output.</p>
<h2>Example</h2>
<pre class="language-bash"><a-f>static-web-server</a-f> <a-co>--root</a-co> /var/www <a-co>--metrics</a-co></pre>
<pre class="language-bash"><a-f>curl</a-f> http://localhost/metrics</pre>
<pre># HELP sws_http_requests_total Total HTTP requests by method, status class, and host.
# TYPE sws_http_requests_total counter
sws_http_requests_total{host=&quot;localhost&quot;,method=&quot;GET&quot;,status=&quot;2xx&quot;} 42
# HELP sws_http_request_duration_seconds HTTP request duration in seconds by method, status class, and host.
# TYPE sws_http_request_duration_seconds histogram
sws_http_request_duration_seconds_bucket{host=&quot;localhost&quot;,method=&quot;GET&quot;,status=&quot;2xx&quot;,le=&quot;0.001&quot;} 38
...
# HELP sws_http_connections_active Number of currently active HTTP connections.
# TYPE sws_http_connections_active gauge
sws_http_connections_active 2
</pre>
<h2>Grafana dashboard</h2>
<p>An example Grafana dashboard is included in <a href="https://github.com/static-web-server/static-web-server/blob/master/contrib/grafana/dashboard.json"><code>contrib/grafana/dashboard.json</code></a>. Import it into Grafana to get panels for request rates, latency histograms, error rates, and active connections out of the box.</p>
<h2>TOML configuration</h2>
<pre class="language-toml"><a-p>[</a-p><a-pr>general</a-pr><a-p>]</a-p>
<a-pr>metrics</a-pr> <a-o>=</a-o> <a-co>true</a-co></pre>
</section><div class="code-panel"><pre class="code src language-markdown"><span class="code-line"><a class="ln" id="L1" href="#L1">1</a><span class="code-text"><a-p>#</a-p> <a-tt>Metrics</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L2" href="#L2">2</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L3" href="#L3">3</a><span class="code-text">SWS provides an optional `/metrics` endpoint that exposes Prometheus-compatible metrics about HTTP traffic. Useful for monitoring request rates, latency, error rates, and connection counts.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L4" href="#L4">4</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L5" href="#L5">5</a><span class="code-text">This feature is disabled by default and can be controlled by the boolean `--metrics` option or the equivalent [SERVER_METRICS](../configuration/environment-variables.md#server_metrics) env.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L6" href="#L6">6</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L7" href="#L7">7</a><span class="code-text"><a-p>##</a-p> <a-tt>Exposed metrics</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L8" href="#L8">8</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L9" href="#L9">9</a><span class="code-text">| Metric | Type | Labels | Description |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L10" href="#L10">10</a><span class="code-text">| -- | -- | -- | -- |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L11" href="#L11">11</a><span class="code-text">| `sws_http_requests_total` | Counter | method, status, host | Total requests by method, status class (2xx, 4xx, etc.), and Host header |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L12" href="#L12">12</a><span class="code-text">| `sws_http_request_duration_seconds` | Histogram | method, status, host | Request latency with buckets from 50µs to 10s |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L13" href="#L13">13</a><span class="code-text">| `sws_http_response_bytes_total` | Counter | method, status, host | Total response bytes (from Content-Length) |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L14" href="#L14">14</a><span class="code-text">| `sws_http_requests_inflight` | Gauge | — | Requests currently being processed |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L15" href="#L15">15</a><span class="code-text">| `sws_http_connections_active` | Gauge | — | Active HTTP connections |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L16" href="#L16">16</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L17" href="#L17">17</a><span class="code-text">When built with the `experimental` feature and `RUSTFLAGS=&quot;--cfg tokio_unstable&quot;`, Tokio runtime metrics (worker threads, task scheduling, etc.) are also included in the output.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L18" href="#L18">18</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L19" href="#L19">19</a><span class="code-text"><a-p>##</a-p> <a-tt>Example</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L20" href="#L20">20</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L21" href="#L21">21</a><span class="code-text"><a-p>```</a-p><a-tl>sh</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L22" href="#L22">22</a><span class="code-text"><a-p>static-web-server --root /var/www --metrics</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L23" href="#L23">23</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L24" href="#L24">24</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L25" href="#L25">25</a><span class="code-text"><a-p>```</a-p><a-tl>sh</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L26" href="#L26">26</a><span class="code-text"><a-p>curl http://localhost/metrics</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L27" href="#L27">27</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L28" href="#L28">28</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L29" href="#L29">29</a><span class="code-text"><a-p>```</a-p><a-tl>text</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L30" href="#L30">30</a><span class="code-text"><a-p># HELP sws_http_requests_total Total HTTP requests by method, status class, and host.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L31" href="#L31">31</a><span class="code-text"><a-p># TYPE sws_http_requests_total counter</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L32" href="#L32">32</a><span class="code-text"><a-p>sws_http_requests_total{host=&quot;localhost&quot;,method=&quot;GET&quot;,status=&quot;2xx&quot;} 42</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L33" href="#L33">33</a><span class="code-text"><a-p># HELP sws_http_request_duration_seconds HTTP request duration in seconds by method, status class, and host.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L34" href="#L34">34</a><span class="code-text"><a-p># TYPE sws_http_request_duration_seconds histogram</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L35" href="#L35">35</a><span class="code-text"><a-p>sws_http_request_duration_seconds_bucket{host=&quot;localhost&quot;,method=&quot;GET&quot;,status=&quot;2xx&quot;,le=&quot;0.001&quot;} 38</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L36" href="#L36">36</a><span class="code-text"><a-p>...</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L37" href="#L37">37</a><span class="code-text"><a-p># HELP sws_http_connections_active Number of currently active HTTP connections.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L38" href="#L38">38</a><span class="code-text"><a-p># TYPE sws_http_connections_active gauge</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L39" href="#L39">39</a><span class="code-text"><a-p>sws_http_connections_active 2</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L40" href="#L40">40</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L41" href="#L41">41</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L42" href="#L42">42</a><span class="code-text"><a-p>## </a-p><a-tt>Grafana dashboard</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L43" href="#L43">43</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L44" href="#L44">44</a><span class="code-text"><a-p>An example Grafana dashboard is included in [`contrib/grafana/dashboard.json`](https://github.com/static-web-server/static-web-server/blob/master/contrib/grafana/dashboard.json). Import it into Grafana to get panels for request rates, latency histograms, error rates, and active connections out of the box.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L45" href="#L45">45</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L46" href="#L46">46</a><span class="code-text"><a-p>## </a-p><a-tt>TOML configuration</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L47" href="#L47">47</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L48" href="#L48">48</a><span class="code-text"><a-p>```</a-p><a-tl>toml</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L49" href="#L49">49</a><span class="code-text"><a-p>[</a-p><a-pr>general</a-pr><a-p>]</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L50" href="#L50">50</a><span class="code-text"><a-p>metrics </a-p><a-o>=</a-o><a-p> </a-p><a-co>true</a-co></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L51" href="#L51">51</a><span class="code-text"><a-p>```</a-p></span></span></pre></div></div>
</main>
</body>
</html>
