Windows性能計數器應用(PART1)git
Windows性能計數器應用(PART2)緩存
Windows性能計數器應用(PART3)網絡
Windows性能計數器應用(PART4)tcp
{
// PerformanceCounter(CategoryName,CounterName,InstanceName)
performanceNetCounterCategory = newPerformanceCounterCategory("Network Interface");
interfaces = performanceNetCounterCategory.GetInstanceNames();
int length = interfaces.Length;
if (length > 0)
{
trafficSentCounters = newPerformanceCounter[length];
trafficReceivedCounters = newPerformanceCounter[length];
}
for (int i = 0; i < length; i++)
{
//初始化PerformanceCounter類的新的只讀實例。ide
//第一個參數:「 categoryName」-與該性能計數器關聯的性能計數器類別(性能對象)的名稱。性能
//第二個參數:「 CounterName」-性能計數器的名稱。ui
//第三個參數:「 instanceName」-性能計數器類別實例的名稱,若是類別包含單個實例,則爲空字符串(「」)。spa
trafficReceivedCounters[i] = new PerformanceCounter("Network Interface", "Bytes Sent/sec", interfaces[i]);
trafficSentCounters[i] =new PerformanceCounter("Network Interface", "Bytes Sent/sec", interfaces[i]);
}
//網絡接口全部名稱的列表
for (int i = 0; i < length; i++)
{
Console.WriteLine("Name netInterface: {0}", performanceNetCounterCategory.GetInstanceNames()[i]);
}
}
public void getProcessorCpuTime()
{
float tmp = cpuProcessorTime.NextValue();
CPUProcessorTime = (float)(Math.Round((double)tmp, 1));
// Environment.ProcessorCount:返回內核總數
}
public void getCpuPrivilegedTime()
{
float tmp = cpuPrivilegedTime.NextValue();
CPUPrivilegedTime = (float)(Math.Round((double)tmp, 1));
}
public void getCpuinterruptTime()
{
float tmp = cpuInterruptTime.NextValue();
CPUInterruptTime = (float)(Math.Round((double)tmp, 1));
}
public void getcpuDPCTime()
{
float tmp = cpuDPCTime.NextValue();
CPUDPCTime = (float)(Math.Round((double)tmp, 1));
}
public void getPageFile()
{
PageFile = pageFile.NextValue();
}
public void getProcessorQueueLengh()
{
ProcessorQueueLengh = processorQueueLengh.NextValue();
}
public void getMemAvailable()
{
MEMAvailable = memAvailable.NextValue();
}
public void getMemCommited()
{
MEMCommited = memCommited.NextValue() / (1024 * 1024);
}
public void getMemCommitLimit()
{
MEMCommitLimit = memCommitLimit.NextValue() / (1024 * 1024);
}
public void getMemCommitedPerc()
{
float tmp = memCommitedPerc.NextValue();
//返回內存提交限制的值orm
MEMCommitedPerc = (float)(Math.Round((double)tmp, 1));
}
public void getMemPoolPaged()
{
float tmp = memPollPaged.NextValue() / (1024 * 1024);
MEMPoolPaged = (float)(Math.Round((double)tmp, 1));
}
public void getMemPoolNonPaged()
{
float tmp = memPollNonPaged.NextValue() / (1024 * 1024);
MEMPoolNonPaged = (float)(Math.Round((double)tmp, 1));
}
public void getMemCachedBytes()
{
//返回以MB爲單位的已緩存內存的值對象
MEMCached = memCached.NextValue() / (1024 * 1024);
}
public void getDiskQueueLengh()
{
DISCQueueLengh = diskQueueLengh.NextValue();
}
public void getDiskRead()
{
float tmp=diskRead.NextValue()/1024;
DISKRead = (float)(Math.Round((double)tmp,1));
}
public void getDiskWrite()
{
float tmp=diskWrite.NextValue()/1024;
DISKWrite = (float)(Math.Round((double)tmp,1)); // round 1 digit decimal
}
public void getDiskAverageTimeRead()
{
float tmp = diskAverageTimeRead.NextValue() * 1000;
DISKAverageTimeRead = (float)(Math.Round((double)tmp, 1)); // round 1 digit decimal
}
public void getDiskAverageTimeWrite()
{
float tmp = diskAverageTimeWrite.NextValue()*1000;
DISKAverageTimeWrite = (float)(Math.Round((double)tmp, 1)); // round 1 digit decimal
}
public void getDiskTime()
{
float tmp = diskTime.NextValue();
DISKTime = (float)(Math.Round((double)tmp, 1));
}
public void getHandleCountCounter()
{
HANDLECountCounter = handleCountCounter.NextValue();
}
public void getThreadCount()
{
THREADCount = threadCount.NextValue();
}
public void getContentSwitches()
{
CONTENTSwitches = (int)Math.Ceiling(contentSwitches.NextValue());
}
public void getsystemCalls()
{
SYSTEMCalls = (int)Math.Ceiling(systemCalls.NextValue());
}
public void getCurretTrafficSent()
{
int length = interfaces.Length;
float sendSum = 0.0F;
for (int i = 0; i < length; i++)
{
sendSum += trafficSentCounters[i].NextValue();
}
float tmp = 8 * (sendSum / 1024);
NetTrafficSend = (float)(Math.Round((double)tmp, 1));
}
public void getCurretTrafficReceived()
{
int length = interfaces.Length;
float receiveSum = 0.0F;
for (int i = 0; i < length; i++)
{
receiveSum += trafficReceivedCounters[i].NextValue();
}
float tmp = 8 * (receiveSum / 1024);
NetTrafficReceive = (float)(Math.Round((double)tmp, 1));
}
public void getSampleTime()
{
SamplingTime =DateTime.Now;
}
}
Windows性能計數器應用(PART1)
Windows性能計數器應用(PART2)
Windows性能計數器應用(PART3)
Windows性能計數器應用(PART4)
Windows性能計數器應用(PART6)