zoukankan      html  css  js  c++  java
  • 如何创建自定义性能计数器

    为什么要创建自定义的性能计数器?

    You create categories and custom performance counters if you want to track data that is not captured by the standard counters provided with Microsoft Windows. For example, you might create a custom counter to track the total number of users logged on to your Web site, or to track the orders processed per second by your site. When you create a counter, you add it to a performance counter category, and you assign it a type that governs how it will behave.

    参考:

    http://msdn.microsoft.com/zh-cn/library/ty9fywea(v=VS.71).aspx

    创建自定义的性能计数器的方法:

    Creating a Single Performance Counter Using PerformanceCounterCategory

     

    1. Create a new text file named CreateCounter.cs and add the following code.

    // CreateCounter.cs

    using System;

    using System.Diagnostics;

    public class CustomCounter

    {

    public static void Main()

    {

    Console.WriteLine("Creating custom counter");

    CreateCounter();

    Console.WriteLine("Done");

    Console.ReadLine();

    }

    public static void CreateCounter()

    {

    if (!PerformanceCounterCategory.Exists("MySingleCategory"))

    {

    PerformanceCounterCategory.Create ("MySingleCategory",

    "My New Perf Category Description", "MyCounter",

    "My New Perf Counter Desc");

    }

    else

    {

    Console.WriteLine("Counter already exists");

    }

    }

    }

    2. Compile the code using the following command line.

    csc.exe /out:CreateCounter.exe /t:exe /r:system.dll CreateCounter.cs

    3. Run CreateCounter.exe from a command prompt to create your new performance

    counter.

    CreateCounter.exe

    Validating Your Performance Counter Category and Performance Counter

    Use Regedt32.exe to verify that your performance counter category and your custom performance counter are created in the following registry folder.

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

    The performance counter category is named MySingleCategory, and the performance counter is named MyCounter.

     

    Using Server Explorer

    If you have Visual Studio .NET, you can create a custom performance counter manually by using Server Explorer.

    _ To create a custom performance counter with Server Explorer

    1. Open Server Explorer and connect to your local server.

    2. Right-click Performance Counters and select Create New Category.

    3. Enter MyCategory in the category name box and optionally enter a description in the Performance Counter Builder box.

    4. Click New at the bottom of the form and enter MyCounter in the counter name box.

    5. Click OK.

     

    Calling PerformanceCounter.Increment

    The following ASP.NET page shows you how to use your custom counter. This code calls PerformanceCounter.Increment to set the new counter value.

    IncrementCounter.aspx

    <%@ language=C# %>

    <%@ import namespace="System.Diagnostics" %>

    <script runat=server>

    void IncrementCounter(Object sender, EventArgs e)

    {

    // get an instance of our perf counter

    PerformanceCounter counter = new PerformanceCounter();

    counter.CategoryName = "mySingleCategory";

    counter.CounterName = "myCounter";

    counter.ReadOnly = false;

    // increment and close the perf counter

    counter.Increment();

    counter.Close();

    Response.Write("Counter is incremented");

    }

    </script>

    <form runat=server>

    <input type="submit" id="btnSubmit" Value="Increment Counter"

    OnServerClick="IncrementCounter" runat=server />

    </form>

     

     

    参考:

    1、《Improving .NET Application Performance and Scalability》

    2、http://msdn.microsoft.com/zh-cn/library/cc437982(v=vs.71).aspx

  • 相关阅读:
    Ubuntu下安装KVM
    Ubuntu下配置libvirt环境
    漏洞复现-Flask-SSTI服务端模板注入
    CTF-杂项笔记
    Tomcat后台爆破指南
    漏洞复现-CVE-2018-15473-ssh用户枚举漏洞
    漏洞复现-CVE-2018-8715-Appweb
    漏洞复现-CVE-2016-4437-Shiro反序列化
    漏洞复现-fastjson1.2.24-RCE
    漏洞复现-CVE-2017-4971-Spring Web Flow 远程代码执行
  • 原文地址:https://www.cnblogs.com/preftest/p/1933928.html
Copyright © 2011-2022 走看看