performancecounter

Performance Counter - System.InvalidOperationException: Category does not exist

点点圈 提交于 2019-11-28 06:33:42
I have following class that returns number of current Request per Second of IIS. I call RefreshCounters every minute in order to keep Requests per Second value refreshed (because it is average and if I keep it too long old value will influence result too much)... and when I need to display current RequestsPerSecond I call that property. public class Counters { private static PerformanceCounter pcReqsPerSec; private const string counterKey = "Requests_Sec"; public static object RequestsPerSecond { get { lock (counterKey) { if (pcReqsPerSec != null) return pcReqsPerSec.NextValue().ToString("N2")

List all processes and their current memory & CPU consumption?

这一生的挚爱 提交于 2019-11-28 05:04:40
How can I get a list of all processes in C# and then for each process current memory and CPU consumption? Sample code is highly appreciated. The Process class has a GetProcesses method that will let you enumerate the running processes and list a bunch of stats like memory usage and CPU time. Look at the documentation under properties for the stats. Memory usage is a complex matter. There is really no single number, that describe the usage. Please see Russinovich's excellent series on the matter. The first installment is here: http://blogs.technet.com/markrussinovich/archive/2008/07/21/3092070

Multiple Processors and PerformanceCounter C#

有些话、适合烂在心里 提交于 2019-11-28 04:08:44
问题 I'm trying to figure out how to gather the current usage percentage of each individual processor on my computer. If I use "System.Environment.ProcessorCount;" I can get the number of processors on my computer and it currently returns "2". I either don't know what I'm looking for or there isn't very much info about this on the internet. The following is the code I'm currently using to get the total current usage percentage of all processors combined. protected PerformanceCounter cpuCounter =

PerformanceCounters on .NET 4.0 & Windows 7

点点圈 提交于 2019-11-28 03:41:09
I have a program that works fine on VS2008 and Vista, but I'm trying it on Windows 7 and VS2010 / .NET Framework 4.0 and it's not working. Ultimately the problem is that System.Diagnostics.PerformanceCounterCategory.GetCategories() (and other PerformanceCounterCategory methods) is not working. I'm getting a System.InvalidOperationException with the message "Cannot load Counter Name data because an invalid index '' was read from the registry." I can reproduce this with the very simple program shown below: class Program { static void Main(string[] args) { foreach (var pc in System.Diagnostics

What are the best ASP.NET performance counters to monitor? [closed]

一个人想着一个人 提交于 2019-11-28 03:20:46
There are truckloads of counters available in perfmon for ASP.NET. What are the best (I am thinking of choosing 5-10) that will be the best to monitor in our test environment so that we can feed back to developers. I am thinking of things like request time, request queue length, active sessions etc. For a normal (not performance/stress testing) you would be OK with the following: Request Bytes Out Total (very important especially for web (not intranet) applications) Requests Failed Requests/Sec Errors During Execution Errors Unhandled During Execution Session SQL Server Connections Total State

In a C# Program, I am trying to get the CPU usage percentage of the application but it always shows 100

倾然丶 夕夏残阳落幕 提交于 2019-11-28 03:10:46
问题 Here is my code. PerformanceCounter cpuCounter = new PerformanceCounter(); cpuCounter.CategoryName = "Processor"; cpuCounter.CounterName = "% Processor Time"; cpuCounter.InstanceName = "_Total"; // will always start at 0 dynamic firstValue = cpuCounter.NextValue(); System.Threading.Thread.Sleep(1000); dynamic secondValue = cpuCounter.NextValue(); return secondValue; There are a lot of people here that are getting the problem that this returns zero, I however am getting 100 at all times, and I

Counter of type RateOfCountsPerSecond32 always shows 0

冷暖自知 提交于 2019-11-28 02:49:27
问题 I have a windows service that serves messages of some virtual queue via a WCF service interface. I wanted to expose two performance counters - The number of items on the queue The number of items removed from the queue per second The first one works fine, the second one always shows as 0 in PerfMon.exe, despite the RawValue appearing to be correct. I'm creating the counters as such - internal const string PERF_COUNTERS_CATEGORY = "HRG.Test.GDSSimulator"; internal const string PERF_COUNTER

PerformanceCounter reporting higher CPU usage than what's observed

牧云@^-^@ 提交于 2019-11-28 02:05:24
I'm currently doing this: PerformanceCounter cpuUsage = new PerformanceCounter("Processor", "% Processor Time", "_Total"); cpuUsage.NextValue(); System.Threading.Thread.Sleep(1000); RV = cpuUsage.NextValue(); I call the function periodically to get CPU usage. When I monitor the system in TaskManager, the CPU usage reported by PerformanceCounter is consistently 15-20% higher than what TaskManager reports (30% in TaskManager = 50% from PerformanceCounter). Maybe there's documentation that I overlooked, but does anyone have an explanation? Maybe the CPU usage at the instant it checks is higher

Retrieve performance counter value in a language-independent way

穿精又带淫゛_ 提交于 2019-11-27 18:22:35
问题 Under Windows, performance counters have different names, depending on the operating system language. For example, on an English Windows version, there is the performance counter \Processor(_Total)\% Processor Time . The same counter is called \Prozessor(_Total)\Prozessorzeit (%) on a German Windows version. Is there any way to retrieve the performance counter value in a language-independent way (using C++ or C#)? Or is there an alternative to get the processor load of the whole computer

What is the performance hit of Performance Counters

最后都变了- 提交于 2019-11-27 18:20:07
When considering using performance counters as my companies' .NET based site, I was wondering how big the overhead is of using them. Do I want to have my site continuously update it's counters or am I better off to only do when I measure? The performance impact is negligible in updating. Microsoft's intent is that you always write to the performance counters. It's the monitoring of (or capturing of) those performance counters that will cause a degradation of performance. So, only when you use something like perfmon to capture the data. In effect, the performance counter objects will have the