Accessing Speech Server Perfmon Counters
I recently had a need to access the Perfmon counters for Speech Server from a C# program. Since I didn't know how to do this my first step was to search the Internet for some code samples. That turned out to be harder than I though as I really didn't find much help.
So I did what I should have done first and turned to the help docs. As it turns out it really isn't that hard to do. First you will need to add "using System.Diagnostics;" to your application. after that the following code will get you a list of the Speech Server counters (these are for MSS 2007).
// **************************************************
// Get a list of Speech Server Counters
// **************************************************
private void button2_Click(object sender, EventArgs e)
{
System.Diagnostics.PerformanceCounter[] mypc;
System.Diagnostics.PerformanceCounterCategory mycat =
new System.Diagnostics.PerformanceCounterCategory("SpeechService");
// Remove the current contents of the textBox
this.textBox1.Clear();
// Retrieve the counters.
mypc = mycat.GetCounters();
// Add the retrieved counters to the list.
for (int i = 0; i < mypc.Length; i++)
{
this.textBox1.Text += mypc[i].CounterName + Environment.NewLine;
}
}
The example places a list of counters into a Textbox but you can do what you want with them.
This example will show the current values for the requested counters -
// **************************************************
// Get the Active calls from the counters
// **************************************************
private void button3_Click(object sender, EventArgs e)
{
this.textBox1.Clear();
System.Diagnostics.PerformanceCounter MyCtr = new System.Diagnostics.PerformanceCounter();
MyCtr.CategoryName = "SpeechService";
MyCtr.CounterName = "Active Incoming Calls";
this.textBox1.Text += MyCtr.CounterName + ": " + MyCtr.NextValue() + Environment.NewLine;
MyCtr.CounterName = "Active Outgoing Calls";
this.textBox1.Text += MyCtr.CounterName + ": " + MyCtr.NextValue() + Environment.NewLine;
MyCtr.CounterName = "Active Application Instances";
this.textBox1.Text += MyCtr.CounterName + ": " + MyCtr.NextValue() + Environment.NewLine;
}
To get the correct value for the PerformanceCounterCategory all you have to do is run Perfmon and then click on add counters. Expand the drop down list under "Performance object" and you will see a list of valid values. I choose "SpeechService" which gave me a list of the Speech Server counters that I used for the second example..
I'll leave you with the task of combining the two samples to create a method that will get a list of all of the counters and their values.