performancecounter

How to display bytes received per second in C#

一曲冷凌霜 提交于 2019-12-12 02:46:44
问题 I'm trying to display the received bytes per second and have them displayed in the console once a second. The I am presented with a Invalid Operation Exception once it reaches .nextvalue. PerformanceCounter NetworkDownSpeed = new PerformanceCounter("Network Interface", "Bytes Received/sec"); float CurrentNetworkDownSpeed = (int)NetworkDownSpeed.NextValue(); while (true) { Console.WriteLine("Current Network Download Speed: {0}MB", CurrentNetworkDownSpeed); Thread.Sleep(1000); } 回答1: Sorry for

Why is obtaining Process related data using Performance Counters causing so many GC?

痴心易碎 提交于 2019-12-12 00:10:46
问题 I have an assembly which monitors the performance statistics of a number of our micro services running on a machine. The code is using performance counters to obtain and publish the data as below: _counters = new Dictionary<string, PerformanceCounter> { ["System Memory Available Bytes"] = new PerformanceCounter { CategoryName = "Memory", CounterName = "Available Bytes", ReadOnly = true }, ["System CPU Usage %"] = new PerformanceCounter { CategoryName = "Processor", CounterName = "% Processor

Performance counter throws SecurityException

。_饼干妹妹 提交于 2019-12-11 23:22:44
问题 This is the code: private static void CreateCounter() { if (PerformanceCounterCategory.Exists("DemoCategory")) PerformanceCounterCategory.Delete("DemoCategory"); CounterCreationDataCollection ccdArray = new CounterCreationDataCollection(); CounterCreationData ccd = new CounterCreationData(); ccd.CounterName = "RequestsPerSecond"; ccd.CounterType = PerformanceCounterType.NumberOfItems32; ccd.CounterHelp = "Requests per second"; ccdArray.Add(ccd); PerformanceCounterCategory.Create("DemoCategory

Cannot attach to a network adapter on one VM, same code works on another VM

泄露秘密 提交于 2019-12-11 16:53:11
问题 I need to get performance counters from the network card. To make things easy, the user selects the needed adapter by typing an index number in a console application. This is the code that gets the user input and creates performance counter instance var connectionNames = NetworkCardLocator.GetConnectedCardNames().ToArray(); log.Debug("Please select one of the available connections"); log.Debug("--"); for (int i = 0; i < connectionNames.Count(); i++) { log.Debug(i + ". " + connectionNames[i]);

Why a call to PerformanceCounter is slow?

我只是一个虾纸丫 提交于 2019-12-11 08:08:45
问题 I'm working on a server that reads the '% CPU' and 'Available memory' from PerformanceCounters. It works good on my development machine. But on actual servers, it is really slow to read from these two PerformanceCounters. at least at the first two read operations. It can take up to 4-6 minutes performing the code below: Stopwatch watch = new Stopwatch(); Log.Instance.Debug("Going to initialize Diagnostic's PerformanceCounters"); watch.Start(); m_CPUPerformanceCounter = new PerformanceCounter(

Getting 0 bytes in results for the given Process using performance counter in c#

半腔热情 提交于 2019-12-11 07:38:34
问题 I'm creating a C# WinForm Application which will display Network Activity (Bytes Received / Bytes Sent) for a given Process (For Example: Process name 's chrome.exe ) and Speed in Megabyte/s generated by the Process. My application uses Performance Counter Class to get the Process activities like IO Read Bytes/sec for received bytes and IO Writes Bytes/sec for sent bytes. But, it's giving me 0 Bytes as a result, which's very weird because chrome.exe is running and its definitely using some

Counter is not single instance, an instance name needs to be specified

…衆ロ難τιáo~ 提交于 2019-12-11 06:55:12
问题 In developing a performance monitoring console app, what is passed into the getcategories method?: PerformanceCounter[] pcArr = pc.GetCounters(string instance); When using the no param overload, a runtime exception is thrown: Counter is not single instance, an instance name needs to be specified. Also, how do you decide between a static utility method or an extension method? For example, I may use a certain utility method quite frequently but then it would be best to add that as an extension

InternetExplorer automation object + PerformanceCounter = not working?

只谈情不闲聊 提交于 2019-12-11 04:27:56
问题 I'm currently trying to build a simple component which should monitor, if the user opens a window with a specific URL (IE only). So I wrote this component and everything works fine, so I integrated it with the application, where it was needed. The problem is, in this application PerformanceCounters are used, and these seem to disturb the behaviour of the InternetExplorer automation object. So I wrote this little sample to demonstrate the problem: using System; using System.Collections.Generic

Where can I find documentation for publishing data to perfmon in C++?

大兔子大兔子 提交于 2019-12-11 04:09:18
问题 Years ago I wrote some code to "publish" data for perfmon to consume. Using those counters is pretty well documented, but I found it challenging to find (at the time) good documentation and sample code to publish the data for perfmon. Does anyone know where I can get this documentation? I also seem to recall some class wrappers, but I may be mistaken. EDIT: I did find this, and I will keep looking for "custom application performance counters". 回答1: You're bringing back old memories! From 1998

C# Instance Name to Use For Network Interface Performance Counter

眉间皱痕 提交于 2019-12-11 03:15:13
问题 I'm trying to add some system monitoring functions to a WPF app I am working on and I would like to add a bandwidth use monitor. Right now I have a CPU and a RAM counter working but I can't figure out what to use for the Performance Counter instance name (sorry if that isn't the correct term). This is what I'm using so far: PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); PerformanceCounter ramCounter = new PerformanceCounter("Memory",