use std::sync::Arc;
use iroh::Endpoint;
use iroh_metrics::{Counter, MetricsGroup};
/// Metrics for our docs protocol.
#[derive(Debug, Default, MetricsGroup)]
#[metrics(name = "docs")]
struct DocsMetrics {
/// Documents written successfully
documents_written: Counter,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let preset = iroh_services::preset()
.api_secret_from_str("YOUR_API_KEY")?
.build()?;
let endpoint = Endpoint::bind(preset.clone()).await?;
endpoint.online().await;
// Register the group with the client. It ships alongside the built-in
// endpoint metrics on the client's reporting interval.
let metrics = Arc::new(DocsMetrics::default());
let client = preset
.client_builder(&endpoint)
.register_metrics_group(metrics.clone())
.build()
.await?;
// Each time a document is written, bump the counter
metrics.documents_written.inc();
Ok(())
}