New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PerformanceCounters - Read OS counters on .NET Core #3906

Closed
manu-st opened this Issue Oct 16, 2015 · 21 comments

Comments

Projects
None yet
@manu-st
Copy link

manu-st commented Oct 16, 2015

Currently CoreFX generates the reference assembly System.Diagnostics.PerformanceCounter.dll however, there doesn't seem to be any counter part implementation for it, nor can I see an entry for this in the progress page at https://github.com/dotnet/corefx-progress/blob/master/src-diff/README.md.

Is this expected?

Thanks

@joshfree

This comment has been minimized.

Copy link
Member

joshfree commented Nov 23, 2015

related #4577

@karelz karelz modified the milestones: Future, 1.2.0 Nov 10, 2016

@karelz

This comment has been minimized.

Copy link
Member

karelz commented Nov 10, 2016

Next step: We need implementation of the Desktop API surface - Windows can just port it from Desktop. Mono has implementation on Linux, maybe we can leverage part of it here for Linux.

Complexity: Medium (packaging will be similar to Registry)

@karelz karelz changed the title PerformanceCounter status Add PerformanceCounter to .NET Core Nov 10, 2016

@karelz karelz added the port-to-core label Nov 19, 2016

@vancem

This comment has been minimized.

Copy link
Member

vancem commented Jan 25, 2017

Perf counters mean different things. Often people only want to READ existing perf counters. This is relative straightforward, and is the kind of thing that we might add (or others could simply make a clone of this that is .NET Core compatible). For this case, however we really would rather we identify the most important of these that are CROSS PLATFORM (e.g. working set, CPU usage ...), and provide a SIMPLER interface to get these that is platform neutral (basically a class or set of classes that have properties that represent he live value of this in a particular process).

However creating NEW performance counter (you are logging new data), is more problematic because windows Performance counters require ADMIN install, and are a MACHINE WIDE SHARED RESOURCE (which makes xcopy deployment and side-by-side problematic).

We would prefer that people who need to log use EventSources or EventCounters for this.

See Event Counter Tutorial for more on event counters.

See EventSource Tutorial for more on EventSource.

@karelz

This comment has been minimized.

Copy link
Member

karelz commented Feb 9, 2017

Note: Fully x-plat Performance Counters are tracked by #4577.

@roji

This comment has been minimized.

Copy link
Contributor

roji commented Feb 9, 2017

Just wanted to second @vancem's distinction between reading existing perf counters vs. creating a publishing new ones. I maintain Npgsql, which publishes connection pool perf information on Windows (just like SqlClient does), and it's important for something like this to be possible in a x-plat way with .NET Core.

@galvesribeiro

This comment has been minimized.

Copy link
Member

galvesribeiro commented Feb 9, 2017

@roji yeah we understand that. Perhaps we should have a revamp on those counters in .Net Core to make it crossplat.

@karelz karelz changed the title Add PerformanceCounter to .NET Core PerformanceCounter - Read Windows OS counters on .NET Core Mar 2, 2017

@karelz karelz changed the title PerformanceCounter - Read Windows OS counters on .NET Core PerformanceCounter - Read OS counters on .NET Core Mar 2, 2017

@danmosemsft

This comment has been minimized.

Copy link
Member

danmosemsft commented Mar 14, 2017

Also note that if and when we implement this, the ref definition is incomplete. It is missing at least these from its desktop counterparts:

MembersMustExist : Member 'System.Diagnostics.PerformanceCounter.CloseSharedResources()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Diagnostics.PerformanceCounter.Decrement()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Diagnostics.PerformanceCounter.Dispose(System.Boolean)' does not exist in the implementation but it does exist in the contract.
@karelz

This comment has been minimized.

Copy link
Member

karelz commented May 3, 2017

Looks like PerformanceCoutners are used for example by NLog, we could look at it as example of customer usage, to see how to migrate such code to .NET Core / .NET Standard.

@bloudraak

This comment has been minimized.

Copy link

bloudraak commented May 4, 2017

I started a project to allow an external system to get performance metrics. I'm really interested not only in extracting metrics or"performance counters", but an API to discover them and report them for a given process.

I'm actively working on making it possible for Prometheus amongst others to extract metrics from an aspnet core process.

So in summary, I'd like to discover what metrics are available in the process (be it specific to the app, a subsystem like EF or ASPNET, platform like GC or exceptions/sec , or OS like memory, disk queue length.

@karelz

@karelz karelz changed the title PerformanceCounter - Read OS counters on .NET Core PerformanceCounters - Read OS counters on .NET Core May 26, 2017

@mi-hol

This comment has been minimized.

Copy link

mi-hol commented Jul 20, 2017

Also Powershell Core is affected by missing basic PerformanceCounter features like ElapsedTime https://github.com/PowerShell/PowerShell/issues/4295
From my view adding just the basic 'read' counters dealing with time measures would be a great improvement for many use cases and would boost compatibility!
This improvement could potentially be accomplished within just a few hours :)

@danmosemsft

This comment has been minimized.

Copy link
Member

danmosemsft commented Jul 20, 2017

@evil-shrike

This comment has been minimized.

Copy link

evil-shrike commented Aug 22, 2017

Currently (2.0) we can reference a nuget/assembly lib built for full .net in .net core 2.0. But if that library uses PerformanceCounterType we'll get runtime exception like:
Message: System.TypeLoadException : Could not load type 'System.Diagnostics.PerformanceCounterType' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I understand that it's expected. But is these any workaround for this? Like a nuget package with stubs for all PerformanceCounters types?

@danmosemsft

This comment has been minimized.

Copy link
Member

danmosemsft commented Aug 22, 2017

@brianrob

This comment has been minimized.

Copy link
Member

brianrob commented Aug 22, 2017

I suspect that there are no workarounds at this time as PerformanceCounters are a desktop-only feature. Do you have a scenario where you need to reference this type other than for using PerformanceCounters, which don't currently run on core?

@evil-shrike

This comment has been minimized.

Copy link

evil-shrike commented Aug 22, 2017

I encountered runtime exception Could not load type 'System.Diagnostics.PerformanceCounterType' while tried to use Devart's ado.net provider for Postgres (built for .net fw 3.5) on core2.

@danmosemsft

This comment has been minimized.

Copy link
Member

danmosemsft commented Sep 11, 2017

Folks who would use this on .NET Core please thumb up the top post.

@smbecker

This comment has been minimized.

Copy link

smbecker commented Sep 12, 2017

For those that need this sooner, I used this article to implement what I needed. Then I just light up the various perf counters that I need when running on windows.

@danmosemsft

This comment has been minimized.

Copy link
Member

danmosemsft commented Nov 20, 2017

This port is done (eg #24579)!

It is currently up on nuget marked preview. It will be marked stable next year, but can be used now (we don't know of issues with it.) It is included in the new compat pack. so it's easiest to just reference that to get it.

I'll close this as complete - please try out the package and open new issues with any bugs you find.

@blugri

This comment has been minimized.

Copy link

blugri commented Nov 23, 2017

I am trying to use this in a .NET core 2.0 application to use a 3rd party library that is written in .NETFramework,Version=v4.6.1. Unfortunately I still get the following exception

TypeLoadException: Could not load type 'System.Diagnostics.PerformanceCounter' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

@danmosemsft Am I doing something wrong? Should your port solve my issue?

Cheers

@danmosemsft

This comment has been minimized.

Copy link
Member

danmosemsft commented Nov 23, 2017

@blugri can you please instead reference the full compat pack and see I'd that fixes this?
https://www.nuget.org/packages/Microsoft.Windows.Compatibility

@blugri

This comment has been minimized.

Copy link

blugri commented Nov 24, 2017

@danmosemsft Thanks. It is working :-)

MikeBairdRocks added a commit to MikeBairdRocks/akka-monitoring that referenced this issue Dec 13, 2017

Upgraded .csproj to VS2017 format
Upgraded libraries to support .NetStandard1.6 (Except PerformanceCounters. see dotnet/corefx#3906)
Upgraded to Akka.NET v1.3.2.
Upgraded to Microsoft.ApplicationInsights v2.4.0.
Upgraded to Newtonsoft.Json v10.0.3.
Upgraded to StatsDClient v3.0.86.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment