2009-10-18 00:08:20 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenMetaverse.TestClient
|
|
|
|
|
|
{
|
|
|
|
|
|
public class NetstatsCommand : Command
|
|
|
|
|
|
{
|
|
|
|
|
|
public NetstatsCommand(TestClient testClient)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "netstats";
|
|
|
|
|
|
Description = "Provide packet and capabilities utilization statistics";
|
|
|
|
|
|
Category = CommandCategory.Simulator;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Client.Settings.TRACK_UTILIZATION)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "TRACK_UTILIZATION is not enabled in Settings, statistics not available";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder packetOutput = new StringBuilder();
|
|
|
|
|
|
StringBuilder capsOutput = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
packetOutput.AppendFormat("{0,-30}|{1,4}|{2,4}|{3,-10}|{4,-10}|" + System.Environment.NewLine, "Packet Name", "Sent", "Recv",
|
|
|
|
|
|
" TX Bytes ", " RX Bytes ");
|
|
|
|
|
|
|
|
|
|
|
|
capsOutput.AppendFormat("{0,-30}|{1,4}|{2,4}|{3,-10}|{4,-10}|" + System.Environment.NewLine, "Message Name", "Sent", "Recv",
|
|
|
|
|
|
" TX Bytes ", " RX Bytes ");
|
|
|
|
|
|
// " RX "
|
|
|
|
|
|
|
|
|
|
|
|
long packetsSentCount = 0;
|
|
|
|
|
|
long packetsRecvCount = 0;
|
|
|
|
|
|
long packetBytesSent = 0;
|
|
|
|
|
|
long packetBytesRecv = 0;
|
|
|
|
|
|
|
|
|
|
|
|
long capsSentCount = 0;
|
|
|
|
|
|
long capsRecvCount = 0;
|
|
|
|
|
|
long capsBytesSent = 0;
|
|
|
|
|
|
long capsBytesRecv = 0;
|
|
|
|
|
|
|
2019-12-16 19:50:19 -06:00
|
|
|
|
foreach (KeyValuePair<string, Stats.UtilizationStatistics.Stat> kvp in Client.Stats.GetStatistics())
|
2009-10-18 00:08:20 +00:00
|
|
|
|
{
|
2019-12-16 19:50:19 -06:00
|
|
|
|
if (kvp.Value.Type == Stats.Type.Message)
|
2009-10-18 00:08:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
capsOutput.AppendFormat("{0,-30}|{1,4}|{2,4}|{3,-10}|{4,-10}|" + System.Environment.NewLine, kvp.Key, kvp.Value.TxCount, kvp.Value.RxCount,
|
|
|
|
|
|
FormatBytes(kvp.Value.TxBytes), FormatBytes(kvp.Value.RxBytes));
|
|
|
|
|
|
|
|
|
|
|
|
capsSentCount += kvp.Value.TxCount;
|
|
|
|
|
|
capsRecvCount += kvp.Value.RxCount;
|
|
|
|
|
|
capsBytesSent += kvp.Value.TxBytes;
|
|
|
|
|
|
capsBytesRecv += kvp.Value.RxBytes;
|
|
|
|
|
|
}
|
2019-12-16 19:50:19 -06:00
|
|
|
|
else if (kvp.Value.Type == Stats.Type.Packet)
|
2009-10-18 00:08:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
packetOutput.AppendFormat("{0,-30}|{1,4}|{2,4}|{3,-10}|{4,-10}|" + System.Environment.NewLine, kvp.Key, kvp.Value.TxCount, kvp.Value.RxCount,
|
|
|
|
|
|
FormatBytes(kvp.Value.TxBytes), FormatBytes(kvp.Value.RxBytes));
|
|
|
|
|
|
|
|
|
|
|
|
packetsSentCount += kvp.Value.TxCount;
|
|
|
|
|
|
packetsRecvCount += kvp.Value.RxCount;
|
|
|
|
|
|
packetBytesSent += kvp.Value.TxBytes;
|
|
|
|
|
|
packetBytesRecv += kvp.Value.RxBytes;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
capsOutput.AppendFormat("{0,30}|{1,4}|{2,4}|{3,-10}|{4,-10}|" + System.Environment.NewLine, "Capabilities Totals", capsSentCount, capsRecvCount,
|
|
|
|
|
|
FormatBytes(capsBytesSent), FormatBytes(capsBytesRecv));
|
|
|
|
|
|
|
|
|
|
|
|
packetOutput.AppendFormat("{0,30}|{1,4}|{2,4}|{3,-10}|{4,-10}|" + System.Environment.NewLine, "Packet Totals", packetsSentCount, packetsRecvCount,
|
|
|
|
|
|
FormatBytes(packetBytesSent), FormatBytes(packetBytesRecv));
|
|
|
|
|
|
|
2022-02-25 19:38:11 -06:00
|
|
|
|
return System.Environment.NewLine + capsOutput + System.Environment.NewLine + System.Environment.NewLine + packetOutput;
|
2009-10-18 00:08:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string FormatBytes(long bytes)
|
|
|
|
|
|
{
|
|
|
|
|
|
const int scale = 1024;
|
2022-02-25 19:38:11 -06:00
|
|
|
|
string[] orders = new[] { "GB", "MB", "KB", "Bytes" };
|
2009-10-18 00:08:20 +00:00
|
|
|
|
long max = (long)Math.Pow(scale, orders.Length - 1);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (string order in orders)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( bytes > max )
|
2022-02-25 19:38:11 -06:00
|
|
|
|
return $"{decimal.Divide(bytes, max):##.##} {order}";
|
2009-10-18 00:08:20 +00:00
|
|
|
|
|
|
|
|
|
|
max /= scale;
|
|
|
|
|
|
}
|
|
|
|
|
|
return "0";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|