diff --git a/docs/content/howto/monitoring-with-prometheus-and-grafana/index.md b/docs/content/howto/monitoring-with-prometheus-and-grafana/index.md index 64831eb..12e1487 100644 --- a/docs/content/howto/monitoring-with-prometheus-and-grafana/index.md +++ b/docs/content/howto/monitoring-with-prometheus-and-grafana/index.md @@ -3,9 +3,10 @@ title: "Monitoring iocaine" description: How to monitor iocaine with Prometheus and Grafana? --- -`iocaine` can be [configured](@/configuration/index.md#metrics) to expose [Prometheus](https://prometheus.io)-compatible metrics, separately from the garbage generator. When enabled, two metrics are exposed: +`iocaine` can be [configured](@/configuration/index.md#metrics) to expose [Prometheus](https://prometheus.io)-compatible metrics, separately from the garbage generator. When enabled, three metrics are exposed: - `iocaine_requests_total`, a counter of how many hits `iocaine` served, optionally with labels attached (see below). +- `iocaine_garbage_served`, the number of bytes of generated content served (not including headers, and not counting any compression by the reverse proxy). - `process_start_time_seconds`, a gauge, a timestamp of when `iocaine` started, to allow measuring uptime. # The simplest configuration @@ -23,11 +24,14 @@ This will expose the following metrics on `http://127.0.0.1:42042/metrics`: # TYPE iocaine_requests_total counter iocaine_requests_total 1 +# TYPE iocaine_garbage_served counter +iocaine_garbage_served 2122 + # TYPE process_start_time_seconds gauge process_start_time_seconds{service="iocaine"} 1738873005.2406795 ``` -The `process_start_time_seconds` metric is *always* present, and its value only changes when `iocaine` is restarted. For the sake of brevity, it is excluded from all other examples. +The `process_start_time_seconds` and `iocaine_garbage_served` metrics are *always* present. For the sake of brevity, they are excluded from all other examples. # Per-host metrics diff --git a/src/app.rs b/src/app.rs index 8bd886a..322911a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -114,7 +114,13 @@ fn poison(iocaine: &StatefulIocaine, headers: axum::http::HeaderMap, path: &str) .to_str() .unwrap(); - Html(AssembledStatisticalSequences::generate(iocaine, host, path)) + let garbage = AssembledStatisticalSequences::generate(iocaine, host, path); + + if iocaine.config.metrics.enable { + metrics::counter!("iocaine_garbage_served").increment(garbage.len() as u64); + } + + Html(garbage) } async fn poison_root(