diff --git a/api/api_common.go b/api/api_common.go index 33658eb2f..973eed31b 100644 --- a/api/api_common.go +++ b/api/api_common.go @@ -30,8 +30,17 @@ type Common interface { NetFindPeer(context.Context, peer.ID) (peer.AddrInfo, error) NetPubsubScores(context.Context) ([]PubsubScore, error) NetAutoNatStatus(context.Context) (NatInfo, error) + + // NetBandwidthStats returns statistics about the nodes total bandwidth + // usage and current rate across all peers and protocols. NetBandwidthStats(ctx context.Context) (metrics.Stats, error) + + // NetBandwidthStatsByPeer returns statistics about the nodes bandwidth + // usage and current rate per peer NetBandwidthStatsByPeer(ctx context.Context) (map[string]metrics.Stats, error) + + // NetBandwidthStatsByProtocol returns statistics about the nodes bandwidth + // usage and current rate per protocol NetBandwidthStatsByProtocol(ctx context.Context) (map[protocol.ID]metrics.Stats, error) // MethodGroup: Common diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index 5c74ef23b..4810fa39a 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -14,8 +14,10 @@ import ( "github.com/ipfs/go-cid" "github.com/ipfs/go-filestore" + metrics "github.com/libp2p/go-libp2p-core/metrics" "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" + protocol "github.com/libp2p/go-libp2p-protocol" pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/multiformats/go-multiaddr" @@ -133,6 +135,22 @@ func init() { InvalidMessageDeliveries: 3, }, }) + addExample(map[string]metrics.Stats{ + "12D3KooWSXmXLJmBR1M7i9RW9GQPNUhZSzXKzxDHWtAgNuJAbyEJ": metrics.Stats{ + RateIn: 100, + RateOut: 50, + TotalIn: 174000, + TotalOut: 12500, + }, + }) + addExample(map[protocol.ID]metrics.Stats{ + "/fil/hello/1.0.0": metrics.Stats{ + RateIn: 100, + RateOut: 50, + TotalIn: 174000, + TotalOut: 12500, + }, + }) maddr, err := multiaddr.NewMultiaddr("/ip4/52.36.61.156/tcp/1347/p2p/12D3KooWFETiESTf1v4PGUvtnxMAcEFMzLZbJGg4tjWfGEimYior") if err != nil { diff --git a/go.mod b/go.mod index bfe54e0ed..5051dc058 100644 --- a/go.mod +++ b/go.mod @@ -88,7 +88,6 @@ require ( github.com/libp2p/go-libp2p-core v0.6.1 github.com/libp2p/go-libp2p-discovery v0.5.0 github.com/libp2p/go-libp2p-kad-dht v0.8.3 - github.com/libp2p/go-libp2p-metrics v0.0.1 github.com/libp2p/go-libp2p-mplex v0.2.4 github.com/libp2p/go-libp2p-noise v0.1.1 github.com/libp2p/go-libp2p-peerstore v0.2.6