系统相关
首页 > 系统相关> > Windows性能计数器应用(PART4)

Windows性能计数器应用(PART4)

作者:互联网

Windows性能计数器应用(PART1)

Windows性能计数器应用(PART2)

Windows性能计数器应用(PART3)

SysField.XML文件指定在日志文件中存储PerformanceCounter()值所需的所有参数以及性能计数器的采样时间。

:应用程序存储日志文件的文件夹。

:日志文件的文件名。

:指定一个布尔值

:单个日志文件存储的最大记录数

PerformanceCounter()的采样间隔

为了每天生成一个日志文件,我们需要将MaxNumberRecordsInLogFile设置为等于:

MaxNumberRecordsInLogFile =(一天中的第二个)/ PollingSysParamsInterval

如果我们每1秒采样一次(PollingSysParamsInterval = 1),则MaxNumberRecordsInLogFile = 86400secondi /(1秒)= 86400

使用存储在app.config中的参数可以定义我们要包含在采样中的性能参数以及性能计数器的结构(顺序)。

app.config的完整结构报告如下:

<?xml version =“ 1.0”?>

<Start>

<ADD key=“ NodeName”value=“ false” />

<ADD key=“ CPUProcessorTime”value=“ true” />

<ADD key=“ CPUPrivilegedTime”value=“ true” />

<ADD key =“ MEMPoolNonPaged” value =“ true” />

<ADD key =“ DISKTime” value =“ true” />

<ADD key =“ HANDLECountCounter” value =“ true” />

<ADD key =“ THREADCount” value =“ true“ />

<ADD key =“ CONTENTSwitches” value =“ true” />

<ADD key =“ SYSTEMCalls” value =“ true” />

<ADD key =“ NumProcess” value =“ true” />

<ADD key =“ NetTrafficSend” value = “ true” /

键值的含义是比较清楚的,与每个键关联的值是布尔值:

编译应用程序时,Visual Studio将在bin \ debug文件夹中自动创建一个名为<您的应用程序名称> .exe.config的文件。编译应用程序时,app.config的内容将自动复制到此新的配置文件中。当将应用程序交付给最终用户时,您必须交付exe和名为<您的应用程序名称> .exe.config的新配置文件,而不是app.config。用户可以在<您的应用程序名称> .exe.config中修改数据重新启动后,文件和应用程序将从配置文件读取数据。在app.config中更改(key,value)的顺序可确定将性能计数器的其他顺序打印到控制台和日志文件中。

该项目使用名为SysParams的公共类来存储所有性能计数器。

public class SysParams

{

public string NodeName { get; set; }

public float CPUProcessorTime { get; set; }

public float CPUPrivilegedTime { get; set; }

public float CPUInterruptTime { get; set; }

public float CPUDPCTime { get; set; }

public float MEMAvailable { get; set; }

public float MEMCommited { get; set; }

public float MEMCommitLimit { get; set; }

public float MEMCommitedPerc { get; set; }

public float MEMPoolPaged { get; set; }

public float MEMPoolNonPaged { get; set; }

public float MEMCached { get; set; }

public float PageFile { get; set; }

public float ProcessorQueueLengh { get; set; }

public float DISCQueueLengh { get; set; }

public float DISKRead {get; set;}

public float DISKWrite { get; set; }

public float DISKAverageTimeRead { get; set; }

public float DISKAverageTimeWrite { get; set; }

public float DISKTime { get; set; }

public float HANDLECountCounter { get; set; }

public float THREADCount { get; set; }

public int CONTENTSwitches { get; set; }

public int SYSTEMCalls { get; set; }

public float NetTrafficSend { get; set; }

public float NetTrafficReceive { get; set; }

public DateTime SamplingTime { get; set; }

 

private PerformanceCounter cpuProcessorTime = new PerformanceCounter("Processor", "% Processor Time", "_Total");

private PerformanceCounter cpuPrivilegedTime = new PerformanceCounter("Processor", "% Privileged Time", "_Total");

private PerformanceCounter cpuInterruptTime = new PerformanceCounter("Processor", "% Interrupt Time", "_Total");

private PerformanceCounter cpuDPCTime = new PerformanceCounter("Processor", "% DPC Time", "_Total");

private PerformanceCounter memAvailable = new PerformanceCounter("Memory", "Available MBytes", null);

private PerformanceCounter memCommited = new PerformanceCounter("Memory", "Committed Bytes", null);

private PerformanceCounter memCommitLimit = new PerformanceCounter("Memory", "Commit Limit", null);

private PerformanceCounter memCommitedPerc = new PerformanceCounter("Memory", "% Committed Bytes In Use", null);

private PerformanceCounter memPollPaged = new PerformanceCounter("Memory", "Pool Paged Bytes", null);

private PerformanceCounter memPollNonPaged = new PerformanceCounter("Memory", "Pool Nonpaged Bytes", null);

private PerformanceCounter memCached = new PerformanceCounter("Memory", "Cache Bytes", null);

private PerformanceCounter pageFile = new PerformanceCounter("Paging File", "% Usage", "_Total");

private PerformanceCounter processorQueueLengh = new PerformanceCounter("System", "Processor Queue Length", null);

private PerformanceCounter diskQueueLengh = new PerformanceCounter("PhysicalDisk", "Avg. Disk Queue Length", "_Total");

private PerformanceCounter diskRead = new PerformanceCounter("PhysicalDisk", "Disk Read Bytes/sec", "_Total");

private PerformanceCounter diskWrite = new PerformanceCounter("PhysicalDisk", "Disk Write Bytes/sec", "_Total");

private PerformanceCounter diskAverageTimeRead = new PerformanceCounter("PhysicalDisk", "Avg. Disk sec/Read", "_Total");

private PerformanceCounter diskAverageTimeWrite = new PerformanceCounter("PhysicalDisk", "Avg. Disk sec/Write", "_Total");

private PerformanceCounter diskTime = new PerformanceCounter("PhysicalDisk", "% Disk Time", "_Total");

private PerformanceCounter handleCountCounter = new PerformanceCounter("Process", "Handle Count", "_Total");

private PerformanceCounter threadCount = new PerformanceCounter("Process", "Thread Count", "_Total");

private PerformanceCounter contentSwitches = new PerformanceCounter("System", "Context Switches/sec", null);

private PerformanceCounter systemCalls = new PerformanceCounter("System", "System Calls/sec", null);

private PerformanceCounterCategory performanceNetCounterCategory;

private PerformanceCounter[] trafficSentCounters;

private PerformanceCounter[] trafficReceivedCounters;

private string[] interfaces = null;

public void initNetCounters()

Windows性能计数器应用(PART1)

Windows性能计数器应用(PART2)

Windows性能计数器应用(PART3)

Windows性能计数器应用(PART5)

标签:PerformanceCounter,set,get,Windows,private,计数器,PART4,new,public
来源: https://blog.51cto.com/djclouds/2475521