metrics: Provide an iocaine_garbage_served metric, too
Some checks failed
documentation / documentation (push) Waiting to run
documentation / notification (push) Blocked by required conditions
lint / linting (push) Waiting to run
build / binary (push) Has been cancelled
build / binary-static (x86_64-linux) (push) Has been cancelled
build / container (push) Has been cancelled
build / clippy (push) Has been cancelled

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2025-02-15 14:14:55 +01:00
parent 87c1dfa04b
commit efa3a203ba
No known key found for this signature in database
2 changed files with 13 additions and 3 deletions

View file

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

View file

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