Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add byte rate metrics #111

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AerospikeClient/Async/AsyncConnectionArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ private void SendEvent(SocketAsyncEventArgs args)
return;
}

node.IncrBytesSent(sent);

if (sent < args.Count)
{
args.SetBuffer(args.Offset + sent, args.Count - sent);
Expand Down Expand Up @@ -172,6 +174,8 @@ private void ReceiveEvent(SocketAsyncEventArgs args)
return;
}

node.IncrBytesReceived(received);

if (received < args.Count)
{
args.SetBuffer(args.Offset + received, args.Count - received);
Expand Down
14 changes: 13 additions & 1 deletion AerospikeClient/Async/AsyncNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public sealed class AsyncNode : Node
private readonly new AsyncCluster cluster;
private int asyncConnsOpened;
private int asyncConnsClosed;
private long bytesReceived;
private long bytesSent;

/// <summary>
/// Initialize server node with connection parameters.
Expand Down Expand Up @@ -196,6 +198,16 @@ internal void IncrAsyncConnClosed()
Interlocked.Increment(ref asyncConnsClosed);
}

public void IncrBytesReceived(long bytesReceived)
{
Interlocked.Add(ref this.bytesReceived, bytesReceived);
}

public void IncrBytesSent(long bytesSent)
{
Interlocked.Add(ref this.bytesSent, bytesSent);
}

public ConnectionStats GetAsyncConnectionStats()
{
int inPool = asyncConnQueue.Count;
Expand All @@ -206,7 +218,7 @@ public ConnectionStats GetAsyncConnectionStats()
{
inUse = 0;
}
return new ConnectionStats(inPool, inUse, asyncConnsOpened, asyncConnsClosed);
return new ConnectionStats(inPool, inUse, asyncConnsOpened, asyncConnsClosed, bytesReceived, bytesSent);
}
}
}
20 changes: 16 additions & 4 deletions AerospikeClient/Cluster/ClusterStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public NodeStats(Node node)
}
else
{
this.asyncStats = new ConnectionStats(0, 0, 0, 0);
this.asyncStats = new ConnectionStats(0, 0, 0, 0, 0, 0);
}
}

Expand Down Expand Up @@ -159,24 +159,36 @@ public sealed class ConnectionStats
/// Total number of node connections closed since node creation.
/// </summary>
public readonly int closed;


/// <summary>
/// Total number of bytes received from that connection.
/// </summary>
public readonly long bytesReceived;

/// <summary>
/// Total number of bytes sent to that connection.
/// </summary>
public readonly long bytesSent;

/// <summary>
/// Connection statistics constructor.
/// </summary>
public ConnectionStats(int inPool, int inUse, int opened, int closed)
public ConnectionStats(int inPool, int inUse, int opened, int closed, long bytesReceived, long bytesSent)
{
this.inPool = inPool;
this.inUse = inUse;
this.opened = opened;
this.closed = closed;
this.bytesReceived = bytesReceived;
this.bytesSent = bytesSent;
}

/// <summary>
/// Convert statistics to string.
/// </summary>
public override string ToString()
{
return "" + inUse + ',' + inPool + ',' + opened + ',' + closed;
return "" + inUse + ',' + inPool + ',' + opened + ',' + closed + ',' + bytesReceived + ',' + bytesSent;
}
}
}
2 changes: 1 addition & 1 deletion AerospikeClient/Cluster/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ public ConnectionStats GetConnectionStats()
}
inUse += tmp;
}
return new ConnectionStats(inPool, inUse, connsOpened, connsClosed);
return new ConnectionStats(inPool, inUse, connsOpened, connsClosed, -1, -1);
}

public void IncrErrorCount()
Expand Down
Loading