1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Metrics for iroh-blobs

use iroh_metrics::{
    core::{Counter, Metric},
    struct_iterable::Iterable,
};

/// Enum of metrics for the module
#[allow(missing_docs)]
#[derive(Debug, Clone, Iterable)]
pub struct Metrics {
    pub download_bytes_total: Counter,
    pub download_time_total: Counter,
    pub downloads_success: Counter,
    pub downloads_error: Counter,
    pub downloads_notfound: Counter,

    pub downloader_tick_main: Counter,
    pub downloader_tick_connection_ready: Counter,
    pub downloader_tick_message_received: Counter,
    pub downloader_tick_transfer_completed: Counter,
    pub downloader_tick_transfer_failed: Counter,
    pub downloader_tick_retry_node: Counter,
    pub downloader_tick_goodbye_node: Counter,
}

impl Default for Metrics {
    fn default() -> Self {
        Self {
            download_bytes_total: Counter::new("Total number of content bytes downloaded"),
            download_time_total: Counter::new("Total time in ms spent downloading content bytes"),
            downloads_success: Counter::new("Total number of successful downloads"),
            downloads_error: Counter::new("Total number of downloads failed with error"),
            downloads_notfound: Counter::new("Total number of downloads failed with not found"),

            downloader_tick_main: Counter::new(
                "Number of times the main downloader actor loop ticked",
            ),
            downloader_tick_connection_ready: Counter::new(
                "Number of times the downloader actor ticked for a connection ready",
            ),
            downloader_tick_message_received: Counter::new(
                "Number of times the downloader actor ticked for a message received",
            ),
            downloader_tick_transfer_completed: Counter::new(
                "Number of times the downloader actor ticked for a transfer completed",
            ),
            downloader_tick_transfer_failed: Counter::new(
                "Number of times the downloader actor ticked for a transfer failed",
            ),
            downloader_tick_retry_node: Counter::new(
                "Number of times the downloader actor ticked for a retry node",
            ),
            downloader_tick_goodbye_node: Counter::new(
                "Number of times the downloader actor ticked for a goodbye node",
            ),
        }
    }
}

impl Metric for Metrics {
    fn name() -> &'static str {
        "iroh-blobs"
    }
}