P
Okay, mit Win32_PerfRawData_Tcpip_NetworkInterface gehts, dort werden die values nicht gelöscht!
Man muss nur noch eine Diferenz errechnen, und die zeit dazwischen dann hat man die up und down raten!
vector<__int64> NEOsLcdClass::GetNetUsages(vector <CString> &Interfaces)
{
vector<__int64> Usages;
/* BEGIN */
HRESULT result;
IEnumWbemClassObject* pEnumerator = NULL;
IWbemClassObject *pclsObj;
DWORD uReturn;
Interfaces.clear();
if(InitializedWbem)
{
/* Use the IWbemServices pointer to make requests of WMI */
result = pSvc->ExecQuery(
_T("WQL"),
_T("SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface"),
WBEM_FLAG_BIDIRECTIONAL,
NULL,
&pEnumerator);
if(/*result != WBEM_S_NO_ERROR*/FAILED(result))
{
/* Failed! */
AfxMessageBox(L"Something Happend :(" + IntToStr(WBEM_S_NO_ERROR));
vector<__int64> ClearRetVal;
return ClearRetVal;
}
/* Get data */
__int64 tmpval;
int i = 0;
while(i++ < NumberOfProzessors)
{
VARIANT vtProp;
result = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if(uReturn != 0 )
{
VariantInit(&vtProp);
//swscanf(vtProp.bstrVal, L"%I64u", &ulVal[nCtr]);
result = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
Interfaces.push_back(vtProp.bstrVal);
//swscanf(vtProp.bstrVal,L"%d",&Usages[Usages.size()-1]);
VariantClear(&vtProp);
result = pclsObj->Get(L"BytesReceivedPerSec", 0, &vtProp, 0, 0);
Usages.push_back(vtProp.ullVal);
VariantClear(&vtProp);
result = pclsObj->Get(L"BytesSentPerSec", 0, &vtProp, 0, 0);
Usages.push_back(vtProp.ullVal);
VariantClear(&vtProp);
result = pclsObj->Get(L"Timestamp_Sys100NS", 0, &vtProp, 0, 0);
swscanf_s(vtProp.bstrVal, L"%I64u", &tmpval);
Usages.push_back(tmpval);
//Usages.push_back(vtProp.ullVal);
VariantClear(&vtProp);
//VERY IMPORTANT!! OTHERWISE MEMORY INCREASES!!
pclsObj->Release();
}
else
{
/* Ups? */
}
}
}
pEnumerator->Release();
return Usages;
}
void NEOsLcdClass::UpdateUsagesTimerFunction()
{
vector<__int64> NetUsage;
/* GET NET STATS */
NetUsage = GetNetUsages(NetInterfaces);
if(NetInterfaces.size() != TotalBytesReceived.size())
{
//RESET!!;
TotalBytesReceived.resize(NetInterfaces.size());
TotalBytesSent.resize(NetInterfaces.size());
TimeStamp_Sys100NS.resize(NetInterfaces.size());
l_TotalBytesReceived.resize(NetInterfaces.size());
l_TotalBytesSent.resize(NetInterfaces.size());
l_TimeStamp_Sys100NS.resize(NetInterfaces.size());
for(int i=0;i<(int)NetInterfaces.size();i++)
{
TotalBytesReceived[i] = NetUsage[i*3 + 0];
TotalBytesSent[i] = NetUsage[i*3 + 1];
TimeStamp_Sys100NS[i] = NetUsage[i*3 + 2];
l_TotalBytesReceived[i] = TotalBytesReceived[i];
l_TotalBytesSent[i] = TotalBytesSent[i];
l_TimeStamp_Sys100NS[i] = TimeStamp_Sys100NS[i];
}
}
for(i=0;i < NetInterfaces.size(); i++)
{
TotalBytesReceived[i] = NetUsage[i*3 + 0];
TotalBytesSent[i] = NetUsage[i*3 + 1];
TimeStamp_Sys100NS[i] = NetUsage[i*3 + 2];
}
tmpVal = "";
__int64 BytesReceived,BytesSent,TimeDif;
for(i=0;i < TotalBytesReceived.size(); i++)
{
BytesReceived = TotalBytesReceived[i] - l_TotalBytesReceived[i];
BytesSent = TotalBytesSent[i] - l_TotalBytesSent[i];
TimeDif = TimeStamp_Sys100NS[i] - l_TimeStamp_Sys100NS[i];
if(TimeDif > 0)
{
BytesReceived = (int)floor((double)10000000/TimeDif * BytesReceived);
BytesSent = (int)floor((double)10000000/TimeDif * BytesSent);
}
else
{
BytesReceived = 0;
BytesSent = 0;
}
//Reset Vals
l_TotalBytesReceived[i] = TotalBytesReceived[i];
l_TotalBytesSent[i] = TotalBytesSent[i];
l_TimeStamp_Sys100NS[i] = TimeStamp_Sys100NS[i];
}
}
Gruß