|
2 | 2 | title: "Metrics" |
3 | 3 | --- |
4 | 4 |
|
5 | | -Placeholder: Suggested metrics, instrumentation, and dashboards for iroh services. |
| 5 | +iroh provides support for collecting metrics about your application's |
| 6 | +performance and behavior using the `iroh-metrics` crate. This crate offers a |
| 7 | +simple and flexible way to define, collect, and report various metrics. |
| 8 | + |
| 9 | +## Example |
| 10 | + |
| 11 | +```rust |
| 12 | +use iroh_metrics::{Counter, MetricsGroup}; |
| 13 | + |
| 14 | +/// Define your metrics: |
| 15 | +#[derive(Debug, Default, MetricsGroup)] |
| 16 | +#[metrics(name = "ping")] |
| 17 | +pub struct Metrics { |
| 18 | + /// count of valid ping messages sent |
| 19 | + pub pings_sent: Counter, |
| 20 | + /// count of valid ping messages received |
| 21 | + pub pings_recv: Counter, |
| 22 | +} |
| 23 | + |
| 24 | +// elsewhere... |
| 25 | +let metrics = Metrics::default(); |
| 26 | + |
| 27 | +// increment count of pings we've received |
| 28 | +metrics.pings_recv.inc(); |
| 29 | +``` |
| 30 | + |
| 31 | +## Exporting metrics |
| 32 | + |
| 33 | +The `iroh-metrics` crate supports exporting metrics in various formats, such |
| 34 | +as Prometheus, which can be scraped by monitoring systems. |
| 35 | + |
| 36 | +As a convenience, the iroh team runs a service that collects Prometheus metrics from |
| 37 | +applications using iroh. To export your metrics to this service, you can use the |
| 38 | +`iroh-n0des` crate. |
| 39 | + |
| 40 | +First, sign up for an account on [n0des.iroh.computer](https://n0des.iroh.computer/signup) and create a project. |
| 41 | + |
| 42 | +Then, follow the instructions in the [iroh-n0des |
| 43 | +documentation](https://n0des.iroh.computer/docs/metrics/custom) to set up the exporter in your |
| 44 | +application. |
| 45 | + |
0 commit comments