Skip to content

Commit

Permalink
feat(IStatsApi): define the statistics/diagnostics interface
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Dec 10, 2018
1 parent d077c9b commit 5cc6292
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/CoreApi/BandwidthData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Ipfs.CoreApi
{
/// <summary>
/// The statistics for <see cref="IStatsApi.BandwidthAsync"/>.
/// </summary>
public class BandwidthData
{
/// <summary>
/// The number of bytes received.
/// </summary>
public ulong TotalIn;

/// <summary>
/// The number of bytes sent.
/// </summary>
public ulong TotalOut;

/// <summary>
/// TODO
/// </summary>
public double RateIn;

/// <summary>
/// TODO
/// </summary>
public double RateOut;

}
}
65 changes: 65 additions & 0 deletions src/CoreApi/BitswapData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Ipfs.CoreApi
{
/// <summary>
/// The statistics for <see cref="IStatsApi.BitswapAsync"/>.
/// </summary>
public class BitswapData
{
/// <summary>
/// TODO: Unknown.
/// </summary>
public int ProviderBufLen;

/// <summary>
/// The content that is wanted.
/// </summary>
public IEnumerable<Cid> WantList;

/// <summary>
/// The known peers.
/// </summary>
public IEnumerable<MultiHash> Peers;

/// <summary>
/// The number of blocks sent by other peers.
/// </summary>
public ulong BlocksReceived;

/// <summary>
/// The number of bytes sent by other peers.
/// </summary>
public ulong DataReceived;

/// <summary>
/// The number of blocks sent to other peers.
/// </summary>
public ulong BlocksSent;

/// <summary>
/// The number of bytes sent to other peers.
/// </summary>
public ulong DataSent;

/// <summary>
/// The number of duplicate blocks sent by other peers.
/// </summary>
/// <remarks>
/// A duplicate block is a block that is already stored in the
/// local repository.
/// </remarks>
public ulong DupBlksReceived;

/// <summary>
/// The number of duplicate bytes sent by other peers.
/// </summary>
/// <remarks>
/// A duplicate block is a block that is already stored in the
/// local repository.
/// </remarks>
public ulong DupDataReceived;
}
}
8 changes: 8 additions & 0 deletions src/CoreApi/ICoreApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ public interface ICoreApi
/// </value>
IPubSubApi PubSub { get; }

/// <summary>
/// Provides access to the Stats (statistics) API.
/// </summary>
/// <value>
/// An object that implements <see cref="IStatsApi"/>.
/// </value>
IStatsApi Stats { get; }

/// <summary>
/// Provides access to the Swarm API.
/// </summary>
Expand Down
52 changes: 52 additions & 0 deletions src/CoreApi/IStatsApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Ipfs.CoreApi
{
/// <summary>
/// Get statistics/diagnostics for the various core components.
/// </summary>
public interface IStatsApi
{
/// <summary>
/// Get statistics on network bandwidth.
/// </summary>
/// <param name="cancel">
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
/// </param>
/// <returns>
/// A task that represents the asynchronous operation. The task's result is
/// the current <see cref="BandwidthData"/>.
/// </returns>
/// <seealso cref="ISwarmApi"/>
Task<BandwidthData> BandwidthAsync(CancellationToken cancel = default(CancellationToken));

/// <summary>
/// Get statistics on the blocks exchanged with other peers.
/// </summary>
/// <param name="cancel">
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
/// </param>
/// <returns>
/// A task that represents the asynchronous operation. The task's result is
/// the current <see cref="BitswapData"/>.
/// </returns>
/// <seealso cref="IBitswapApi"/>
Task<BitswapData> BitswapAsync(CancellationToken cancel = default(CancellationToken));

/// <summary>
/// Get statistics on repository.
/// </summary>
/// <param name="cancel">
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
/// </param>
/// <returns>
/// A task that represents the asynchronous operation. The task's result is
/// the current <see cref="BandwidthData"/>.
/// </returns>
Task<RepositoryData> RepositoryAsync(CancellationToken cancel = default(CancellationToken));
}
}
38 changes: 38 additions & 0 deletions src/CoreApi/RepositoryData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Ipfs.CoreApi
{
/// <summary>
/// The statistics for <see cref="IStatsApi.RepositoryAsync"/>.
/// </summary>
public class RepositoryData
{
/// <summary>
/// The number of blocks in the repository.
/// </summary>
public ulong NumObjects;

/// <summary>
/// The total number bytes in the repository.
/// </summary>
public ulong RepoSize;

/// <summary>
/// The fully qualified path to the repository.
/// </summary>
public string RepoPath;

/// <summary>
/// The version number of the repository.
/// </summary>
public string Version;

/// <summary>
/// The maximum number of bytes of the repository.
/// </summary>
public ulong StorageMax;

}
}

0 comments on commit 5cc6292

Please sign in to comment.