network interface monitor completed.

This commit is contained in:
Zhen Tang 2013-07-08 00:16:20 +08:00
parent 0ff245fc2c
commit 3e21bca0da
6 changed files with 315 additions and 4 deletions

View File

@ -98,6 +98,28 @@ class MONITOR_API NetworkInterface
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
static double GetBytesTotalPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentPerSecond(const wchar_t * instanceName, int idleTime);
static double GetCurrentBandwidth(const wchar_t * instanceName);
static double GetBytesReceivedPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedNonUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedDiscarded(const wchar_t * instanceName);
static double GetPacketsReceivedErrors(const wchar_t * instanceName);
static double GetPacketsReceivedUnknown(const wchar_t * instanceName);
static double GetBytesSentPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentNonUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsOutboundDiscarded(const wchar_t * instanceName);
static double GetPacketsOutboundErrors(const wchar_t * instanceName);
static double GetOutputQueueLength(const wchar_t * instanceName);
static double GetOffloadedConnections(const wchar_t * instanceName);
static double GetTcpActiveRscConnections(const wchar_t * instanceName);
static double GetTcpRscCoalescedPacketsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetTcpRscExceptionsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetTcpRscAveragePacketSize(const wchar_t * instanceName);
};
class MONITOR_API PhysicalDisk

View File

@ -13,22 +13,244 @@ list<wstring> NetworkInterface::GetCounterList()
return Common::GetCounterList(L"Network Interface");
}
// Bytes Total/sec
double NetworkInterface::GetBytesTotalPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Bytes Total/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// Packets/sec
double NetworkInterface::GetPacketsPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// Packets Received/sec
double NetworkInterface::GetPacketsReceivedPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets Received/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// Packets Sent/sec
double NetworkInterface::GetPacketsSentPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets Sent/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// Current Bandwidth
double NetworkInterface::GetCurrentBandwidth(const wchar_t * instanceName)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Current Bandwidth";
double ret=Common::GetCounterValue(fullCounterPath.c_str());
return ret;
}
// Bytes Received/sec
double NetworkInterface::GetBytesReceivedPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Bytes Received/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// Packets Received Unicast/sec
double NetworkInterface::GetPacketsReceivedUnicastPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets Received Unicast/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// Packets Received Non-Unicast/sec
double NetworkInterface::GetPacketsReceivedNonUnicastPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets Received Non-Unicast/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// Packets Received Discarded
double NetworkInterface::GetPacketsReceivedDiscarded(const wchar_t * instanceName)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets Received Discarded";
double ret=Common::GetCounterValue(fullCounterPath.c_str());
return ret;
}
// Packets Received Errors
double NetworkInterface::GetPacketsReceivedErrors(const wchar_t * instanceName)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets Received Errors";
double ret=Common::GetCounterValue(fullCounterPath.c_str());
return ret;
}
// Packets Received Unknown
double NetworkInterface::GetPacketsReceivedUnknown(const wchar_t * instanceName)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets Received Unknown";
double ret=Common::GetCounterValue(fullCounterPath.c_str());
return ret;
}
// Bytes Sent/sec
double NetworkInterface::GetBytesSentPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Bytes Sent/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// Packets Sent Unicast/sec
double NetworkInterface::GetPacketsSentUnicastPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets Sent Unicast/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// Packets Sent Non-Unicast/sec
double NetworkInterface::GetPacketsSentNonUnicastPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets Sent Non-Unicast/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// Packets Outbound Discarded
double NetworkInterface::GetPacketsOutboundDiscarded(const wchar_t * instanceName)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets Outbound Discarded";
double ret=Common::GetCounterValue(fullCounterPath.c_str());
return ret;
}
// Packets Outbound Errors
double NetworkInterface::GetPacketsOutboundErrors(const wchar_t * instanceName)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Packets Outbound Errors";
double ret=Common::GetCounterValue(fullCounterPath.c_str());
return ret;
}
// Output Queue Length
double NetworkInterface::GetOutputQueueLength(const wchar_t * instanceName)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Output Queue Length";
double ret=Common::GetCounterValue(fullCounterPath.c_str());
return ret;
}
// Offloaded Connections
double NetworkInterface::GetOffloadedConnections(const wchar_t * instanceName)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\Offloaded Connections";
double ret=Common::GetCounterValue(fullCounterPath.c_str());
return ret;
}
// TCP Active RSC Connections
double NetworkInterface::GetTcpActiveRscConnections(const wchar_t * instanceName)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\TCP Active RSC Connections";
double ret=Common::GetCounterValue(fullCounterPath.c_str());
return ret;
}
// TCP RSC Coalesced Packets/sec
double NetworkInterface::GetTcpRscCoalescedPacketsPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\TCP RSC Coalesced Packets/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// TCP RSC Exceptions/sec
// TCP RSC Average Packet Size
double NetworkInterface::GetTcpRscExceptionsPerSecond(const wchar_t * instanceName, int idleTime)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\TCP RSC Exceptions/sec";
double ret=Common::GetCounterValueWithIdle(fullCounterPath.c_str(),idleTime);
return ret;
}
// TCP RSC Average Packet Size
double NetworkInterface::GetTcpRscAveragePacketSize(const wchar_t * instanceName)
{
wstring fullCounterPath(L"");
fullCounterPath+=L"\\Network Interface(";
fullCounterPath+=instanceName;
fullCounterPath+=L")\\TCP RSC Average Packet Size";
double ret=Common::GetCounterValue(fullCounterPath.c_str());
return ret;
}

View File

@ -9,4 +9,26 @@ class MONITOR_API NetworkInterface
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
static double GetBytesTotalPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentPerSecond(const wchar_t * instanceName, int idleTime);
static double GetCurrentBandwidth(const wchar_t * instanceName);
static double GetBytesReceivedPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedNonUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedDiscarded(const wchar_t * instanceName);
static double GetPacketsReceivedErrors(const wchar_t * instanceName);
static double GetPacketsReceivedUnknown(const wchar_t * instanceName);
static double GetBytesSentPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentNonUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsOutboundDiscarded(const wchar_t * instanceName);
static double GetPacketsOutboundErrors(const wchar_t * instanceName);
static double GetOutputQueueLength(const wchar_t * instanceName);
static double GetOffloadedConnections(const wchar_t * instanceName);
static double GetTcpActiveRscConnections(const wchar_t * instanceName);
static double GetTcpRscCoalescedPacketsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetTcpRscExceptionsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetTcpRscAveragePacketSize(const wchar_t * instanceName);
};

View File

@ -98,6 +98,28 @@ class MONITOR_API NetworkInterface
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
static double GetBytesTotalPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentPerSecond(const wchar_t * instanceName, int idleTime);
static double GetCurrentBandwidth(const wchar_t * instanceName);
static double GetBytesReceivedPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedNonUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedDiscarded(const wchar_t * instanceName);
static double GetPacketsReceivedErrors(const wchar_t * instanceName);
static double GetPacketsReceivedUnknown(const wchar_t * instanceName);
static double GetBytesSentPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentNonUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsOutboundDiscarded(const wchar_t * instanceName);
static double GetPacketsOutboundErrors(const wchar_t * instanceName);
static double GetOutputQueueLength(const wchar_t * instanceName);
static double GetOffloadedConnections(const wchar_t * instanceName);
static double GetTcpActiveRscConnections(const wchar_t * instanceName);
static double GetTcpRscCoalescedPacketsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetTcpRscExceptionsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetTcpRscAveragePacketSize(const wchar_t * instanceName);
};
class MONITOR_API PhysicalDisk

View File

@ -98,6 +98,28 @@ class MONITOR_API NetworkInterface
public:
static list<wstring> GetInstances();
static list<wstring> GetCounterList();
static double GetBytesTotalPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentPerSecond(const wchar_t * instanceName, int idleTime);
static double GetCurrentBandwidth(const wchar_t * instanceName);
static double GetBytesReceivedPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedNonUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsReceivedDiscarded(const wchar_t * instanceName);
static double GetPacketsReceivedErrors(const wchar_t * instanceName);
static double GetPacketsReceivedUnknown(const wchar_t * instanceName);
static double GetBytesSentPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsSentNonUnicastPerSecond(const wchar_t * instanceName, int idleTime);
static double GetPacketsOutboundDiscarded(const wchar_t * instanceName);
static double GetPacketsOutboundErrors(const wchar_t * instanceName);
static double GetOutputQueueLength(const wchar_t * instanceName);
static double GetOffloadedConnections(const wchar_t * instanceName);
static double GetTcpActiveRscConnections(const wchar_t * instanceName);
static double GetTcpRscCoalescedPacketsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetTcpRscExceptionsPerSecond(const wchar_t * instanceName, int idleTime);
static double GetTcpRscAveragePacketSize(const wchar_t * instanceName);
};
class MONITOR_API PhysicalDisk

View File

@ -2,8 +2,8 @@
int _tmain(int argc, _TCHAR* argv[])
{
//list<wstring> counterList=PhysicalDisk::GetCounterList();
//list<wstring> instances=Process::GetInstances();
//list<wstring> counterList=NetworkInterface::GetCounterList();
//list<wstring> instances=NetworkInterface::GetInstances();
//list<wstring>::iterator iter;
//std::wcout.imbue(std::locale("chs"));
//for(iter=counterList.begin();iter!=counterList.end();iter++)
@ -14,9 +14,10 @@ int _tmain(int argc, _TCHAR* argv[])
//{
// wcout<<(*iter).c_str()<<endl;
//}
wstring name=L"Broadcom 802.11n 网络适配器";
while(1)
{
printf("%lf\n",Memory::GetLongTermAverageStandbyCacheLifetimes());
printf("%lf\n",NetworkInterface::GetTcpRscAveragePacketSize(name.c_str()));
Sleep(500);
}
return 0;