001  <% @Page Language="C#" %>
002  <% @Import Namespace="System.Diagnostics" %>
003  <% @Import Namespace="System.Net" %>
004  <script language="C#" runat="server">
005  void Page_Load(Object Src, EventArgs E)
006  {
007   if (!Page.IsPostBack)
008   {
009   PerformanceCounterCategory[] arrCategories = PerformanceCounterCategory.GetCategories();
010   Category.DataSource = arrCategories;
011   Category.DataBind();
012   }
013  }
014  
015  void OnDisplayCategory(Object sender, EventArgs e)
016  {
017   string strCategory = Category.SelectedItem.Value;
018   PerformanceCounterCategory pcInfo = new PerformanceCounterCategory(strCategory);
019   PerformanceCounter[] arrCntrs = pcInfo.GetCounters("");
020   Counters.DataSource = arrCntrs;
021   Counters.DataBind();
022   CounterInstances.Items.Clear();
023  }
024  
025  void OnCounterInfo(Object sender, EventArgs e)
026  {
027   string strCategory = Category.SelectedItem.Value;
028   CounterInstances.Items.Clear();
029  
030   PerformanceCounterCategory pcCat = new PerformanceCounterCategory(strCategory);
031   string[] arrInstanceNames = pcCat.GetInstanceNames();
032   if (arrInstanceNames.GetLength(0) > 1)
033   {
034   CounterInstances.DataSource = arrInstanceNames;
035   CounterInstances.DataBind();
036   }
037  }
038  
039  void SubmitBtn_Click(Object sender, EventArgs e)
040  {
041   string strCategory = Category.SelectedItem.Value;
042   string strCounter = Counters.SelectedItem.Value;
043   string strInstanceName = "";
044  
045   if (CounterInstances.Items.Count > 0)
046   strInstanceName = CounterInstances.SelectedItem.Value;
047  
048   try
049   {
050   PerformanceCounter pc = new PerformanceCounter(strCategory, strCounter, strInstanceName);
051   // get the current value
052   float dResult = pc.NextValue();
053   Message.Text = "<" + strCategory + "> [" + strCounter + "] {" + strInstanceName + "} = " + dResult.ToString();
054   }
055   catch (Exception exc)
056   {
057   Message.Text = exc.ToString();
058   }
059  }
060  
061  </script>
062  
063  <html>
064  <head><title>Query performance counters</title></head>
065  <body>
066  <h3>Performance Counter auslesen</h3>
067  
068  <form runat="server" method="post">
069  <table width="400">
070  <tr><td>Kategorie:</td><td>Counter:</td><td>Instances</td></tr>
071  <tr><td valign="top">
072  <asp:dropdownlist id="Category" AutoPostBack="True"
073   DataTextField="CategoryName" DataValueField="CategoryName"
074   runat=server OnSelectedIndexChanged="OnDisplayCategory" />
075  </td><td valign="top">
076  <asp:ListBox id="Counters" Width="200px" runat="server"
077   DataTextField="CounterName" DataValueField="CounterName"
078   AutoPostBack="True"
079   OnSelectedIndexChanged="OnCounterInfo"/>
080  </td><td valign="top">
081  <asp:ListBox id="CounterInstances" Width="100px" runat="server" />
082  </td></tr>
083  </table>
084  <asp:button OnClick="SubmitBtn_Click" text="Lookup" runat="server"/>
085  </form>
086  
087  <p>
088  <asp:Label id="Message" runat="server" />
089  </p>
090  
091  </body>
092  </html>