summaryrefslogtreecommitdiffstats
path: root/ipfs-api/examples/get_stats.rs
blob: 36100a54a934bda1881dea2dc6c772cbc048e0b9 (plain)
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
// Copyright 2017 rust-ipfs-api Developers
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
//

use ipfs_api::IpfsClient;

// Creates an Ipfs client, and gets some stats about the Ipfs server.
//
#[tokio::main]
async fn main() {
    eprintln!("connecting to localhost:5001...");

    let client = IpfsClient::default();

    match client.stats_bitswap().await {
        Ok(bitswap_stats) => {
            eprintln!("bitswap stats:");
            eprintln!("  blocks recv: {}", bitswap_stats.blocks_received);
            eprintln!("  data   recv: {}", bitswap_stats.data_received);
            eprintln!("  blocks sent: {}", bitswap_stats.blocks_sent);
            eprintln!("  data   sent: {}", bitswap_stats.data_sent);
            eprintln!(
                "  peers:       {}",
                bitswap_stats.peers.join("\n               ")
            );
            eprintln!(
                "  wantlist:    {}",
                bitswap_stats.wantlist.join("\n               ")
            );
            eprintln!();
        }
        Err(e) => eprintln!("error getting bitswap stats: {}", e),
    }

    match client.stats_bw().await {
        Ok(bw_stats) => {
            eprintln!("bandwidth stats:");
            eprintln!("  total    in: {}", bw_stats.total_in);
            eprintln!("  total   out: {}", bw_stats.total_out);
            eprintln!("  rate     in: {}", bw_stats.rate_in);
            eprintln!("  rate    out: {}", bw_stats.rate_out);
            eprintln!();
        }
        Err(e) => eprintln!("error getting bandwidth stats: {}", e),
    }

    match client.stats_repo().await {
        Ok(repo_stats) => {
            eprintln!("repo stats:");
            eprintln!("  num    objs: {}", repo_stats.num_objects);
            eprintln!("  repo   size: {}", repo_stats.repo_size);
            eprintln!("  repo   path: {}", repo_stats.repo_path);
            eprintln!("  version    : {}", repo_stats.version);
        }
        Err(e) => eprintln!("error getting repo stats: {}", e),
    }
}