Stats API

May 16, 2022 ยท View on GitHub

ipfs.stats.bitswap([options]

Show diagnostic information on the bitswap agent.

Note: stats.bitswap and bitswap.stat can be used interchangeably. See bitswap.stat for more details.

ipfs.stats.repo([options])

Get stats for the currently used repo.

Note: stats.repo and repo.stat can be used interchangeably. See repo.stat for more details.

ipfs.stats.bw([options])

Get IPFS bandwidth information.

Parameters

None

Options

An optional object which may have the following keys:

NameTypeDefaultDescription
peerPeerIdundefinedSpecifies a peer to print bandwidth for
protoStringundefinedSpecifies a protocol to print bandwidth for
pollbooleanundefinedIs used to yield bandwidth info at an interval
intervalNumberundefinedThe time interval to wait between updating output, if poll is true
timeoutNumberundefinedA timeout in ms
signalAbortSignalundefinedCan be used to cancel any long running requests started as a result of this call

Returns

TypeDescription
AsyncIterable<Object>An async iterable that yields IPFS bandwidth information

Each yielded object contains the following keys:

  • totalIn - is a BigInt, in bytes.
  • totalOut - is a BigInt, in bytes.
  • rateIn - is a float, in bytes.
  • rateOut - is a float, in bytes.

Example

for await (const stats of ipfs.stats.bw()) {
  console.log(stats)
}
// { totalIn: BigInt {...},
//   totalOut: BigInt {...},
//   rateIn: number {...},
//   rateOut: number {...} }

A great source of examples can be found in the tests for this API.