Answered by:
PerformanceCounterCategory -> GetInstanceNames do not return all instances (SMB Client Shares)

Question
-
Hi
I'm trying to get a list of all InstanceNames on the PerformanceCategory "SMB Client Shares" in C# like this:
PerformanceCounterCategory smbClientShares = new PerformanceCounterCategory("SMB Client Shares"); smbClientShares.ReadCategory(); string[] instances = smbClientShares.GetInstanceNames(); foreach(string inst in instances) { Console.WriteLine(inst); }
The case is that this do not return all InstanceNames on "SMB Client Shares" that I see when I look in PerfMon. My C# code returns "*" and "_Total". But PerfMon do also show instanceNames like "\cl-sofs-smb\VMs1", "\cl-sofs-smb\VMs2" and "\cl-sofs-smb\VMs3"
Doing the same operation in PowerShell gives me this:
PS C:\> (New-Object System.Diagnostics.PerformanceCounterCategory("SMB Client Shares")).GetInstanceNames() * _Total PS C:\> PS C:\> PS C:\> Get-Counter -ListSet "SMB Client shares" CounterSetName : SMB Client Shares MachineName : . CounterSetType : MultiInstance Description : This counter set displays information about server shares that are being accessed by the client us ing SMB protocol version 2 or higher. Paths : {\SMB Client Shares(*)\Credit Stalls/sec, \SMB Client Shares(*)\Metadata Requests/sec, \SMB Client Shares(*)\Avg. Data Queue Length, \SMB Client Shares(*)\Avg. Write Queue Length...} PathsWithInstances : {\SMB Client Shares(\cl-sofs-smb\VMs3)\Credit Stalls/sec, \SMB Client Shares(\localhost \IPC$)\Credit Stalls/sec, \SMB Client Shares(\cl-sofs-smb\VMs2)\Credit Stalls/sec, \SMB Client Shares(\cl-sofs-smb\VMs1)\Credit Stalls/sec...} Counter : {\SMB Client Shares(*)\Credit Stalls/sec, \SMB Client Shares(*)\Metadata Requests/sec, \SMB Client Shares(*)\Avg. Data Queue Length, \SMB Client Shares(*)\Avg. Write Queue Length...} PS C:\>
Can anyone explain why I get more PerformanceCounter instances returned when I use the PowerShell Get-Counter than when I use the C# function? And how can I get all the missing instance names with use of C# ??
Br. Rune
Wednesday, May 11, 2016 6:44 AM
Answers
-
Hi Kristin
Thanks for your help :) I have submitted feedback in https://connect.microsoft.com/VisualStudio/feedback/details/2723276/performancecountercategory-getinstancenames-do-not-return-all-instances
Br. Rune
- Proposed as answer by Kristin Xie Friday, May 20, 2016 1:09 AM
- Marked as answer by DotNet Wang Monday, May 23, 2016 1:27 PM
Thursday, May 19, 2016 11:24 AM
All replies
-
Hi Br.Rune,
>>The case is that this do not return all InstanceNames on "SMB Client Shares" that I see when I look in PerfMon. My C# code returns "*" and "_Total".
Yes, I also tested on my side, it is the same as yours. One instance for each processor and an instance called _Total which means the total processor time used on all processors.
>>how can I get all the missing instance names with use of C# ??
Please try to use the following code.
class Program { static void Main(string[] args) { PerformanceCounterCategory smbClientShares = new PerformanceCounterCategory("SMB Client Shares"); smbClientShares.ReadCategory(); //string[] instances = smbClientShares.GetInstanceNames(); //Console.WriteLine(smbClientShares.CategoryName); //Console.WriteLine(smbClientShares.MachineName); //foreach (string inst in instances) //{ // Console.WriteLine(inst); //} ListCounters("SMB Client Shares"); ListInstances(smbClientShares, "*"); Console.Read(); } public static void ListCounters(string categoryName) { PerformanceCounterCategory category = PerformanceCounterCategory.GetCategories().First(c => c.CategoryName == categoryName); Console.WriteLine("{0} [{1}]", category.CategoryName, category.CategoryType); string[] instanceNames = category.GetInstanceNames(); if (instanceNames.Length > 0) { // MultiInstance categories foreach (string instanceName in instanceNames) { ListInstances(category, instanceName); } } else { // SingleInstance categories ListInstances(category, string.Empty); } } private static void ListInstances(PerformanceCounterCategory category, string instanceName) { Console.WriteLine(" {0}", instanceName); PerformanceCounter[] counters = category.GetCounters(instanceName); foreach (PerformanceCounter counter in counters) { Console.WriteLine(" {0}", counter.CounterName); } } }
Here is the result
Hope this helps!
Best regards,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Edited by Kristin Xie Thursday, May 12, 2016 7:34 AM
Thursday, May 12, 2016 7:32 AM -
Hi. Thanks for your answer :)
I still with this code only get the "*" and "_Total" instancename returned. In other words still missing the actual SMB Client share instances i have on my system. The powershell Get-Counter cmdlet do some magic to return PathsWithInstances and not ony Paths. The mystery is what C# code is behind finding "PathsWithInstances". Would be very happy if I could get help solving this mystery :)
Br. Rune
Tuesday, May 17, 2016 4:56 PM -
Hi. Thanks for your answer :)
I still with this code only get the "*" and "_Total" instancename returned. In other words still missing the actual SMB Client share instances i have on my system. The powershell Get-Counter cmdlet do some magic to return PathsWithInstances and not ony Paths. The mystery is what C# code is behind finding "PathsWithInstances". Would be very happy if I could get help solving this mystery :)
Br. Rune
@Br.Rune,
Since I don't know what your real scenario is. Do you try my code as above? How about the result? Please let me know.
Best regards,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Wednesday, May 18, 2016 9:21 AM -
Hi Kristin
Yes, I have tried your code. And this code for the "SMB Client Shares" PerformanceCategory do return the instances "*" and "_Total".
As shown by the Powershell command above the PathsWithInstances output shows that I have some more instances on my system that the C# code do not return. This is also true if I look in the PerfMon:
So my question is why is not the C# GetInstanceNames not able to find/return all the instances for this "SMB CLient Shares" PerformanceCategory? Could it be because of the "\" in these instance names?
Br. Rune
Thursday, May 19, 2016 7:41 AM -
Hi Br.Rune,
It is weird, I suspect it's a product issue and I would recommend you submit a feedback in http://connect.microsoft.com. Someone who comes from Microsoft will help you support this.
If you finish submit, please also remember to post the link here. I will help you vote it.
Best regards,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
- Edited by Kristin Xie Thursday, May 19, 2016 8:28 AM
Thursday, May 19, 2016 8:27 AM -
Hi Kristin
Thanks for your help :) I have submitted feedback in https://connect.microsoft.com/VisualStudio/feedback/details/2723276/performancecountercategory-getinstancenames-do-not-return-all-instances
Br. Rune
- Proposed as answer by Kristin Xie Friday, May 20, 2016 1:09 AM
- Marked as answer by DotNet Wang Monday, May 23, 2016 1:27 PM
Thursday, May 19, 2016 11:24 AM -
Hi Kristin
Thanks for your help :) I have submitted feedback in https://connect.microsoft.com/VisualStudio/feedback/details/2723276/performancecountercategory-getinstancenames-do-not-return-all-instances
Br. Rune
@Br. Rune,
I also suggest you add a simplified demo to the attachment. But not just this MSDN link. It could be better for someone who researches this issue.
Best regards,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Friday, May 20, 2016 1:12 AM -
Hi Kristin
Thanks for your help :) I have submitted feedback in https://connect.microsoft.com/VisualStudio/feedback/details/2723276/performancecountercategory-getinstancenames-do-not-return-all-instances
Br. Rune
Hi Br. Rune,
Have you ever found a solution to this?
Thursday, July 13, 2017 7:43 AM