MySqlConnector icon indicating copy to clipboard operation
MySqlConnector copied to clipboard

Extract metrics from a connection pool

Open felipe-rochac opened this issue 6 years ago • 7 comments

Is there a way to extract some metrics from the pool like idle connections, connections in use, available connections... ?

felipe-rochac avatar Apr 29 '18 20:04 felipe-rochac

There is not currently any such method.

Do you know of another ADO.NET provider that exposes similar metrics? (Just curious if there's an existing example of exposing such an API.)

bgrainger avatar Apr 29 '18 21:04 bgrainger

We can gather it from the MySql Oracle driver through the reflection, however, I'm wondering if we can do it in this driver in a more elegant way

felipe-rochac avatar Apr 29 '18 22:04 felipe-rochac

Interesting question indeed! Would a pull-request be accepted which introduces some metrics abstraction on the lines of the logging abstraction? I'm thinking about aIMySqlConnectorMetricsProvider kind of thing.

daniel-munch-cko avatar Feb 13 '20 18:02 daniel-munch-cko

I am looking for guidance (from the ADO.NET or ASP.NET Core team) about high-performance instrumentation with EventSource or DiagnosticSource (#471). One can also imagine exposing Prometheus-style metrics or integrating with OpenTracing, and I'd like to do it in a way that's standardised with other ADO.NET providers, not just implemented in an ad-hoc way.

It would also be extremely important to implement in a zero-overhead way when not activated, e.g., to not impact TFB performance benchmarks.

bgrainger avatar Feb 13 '20 20:02 bgrainger

I see, thanks! I've stumbled over #471 after I wrote this comment and figured this would be the way to go anyway.

daniel-munch-cko avatar Feb 14 '20 12:02 daniel-munch-cko

https://github.com/mysql-net/MySqlConnector/issues/1137 provides a link to SQL Server Provider Statistics, which is an in-memory (?) Dictionary enabled via a connection-string setting. This could provide a template for a low-overhead approach, but also seems like it might be an historical method that would now be implemented instead with OpenTelemetry.

bgrainger avatar Feb 14 '22 19:02 bgrainger

We can now use System.Diagnostics.Metrics for integration-agnostic metrics: https://docs.microsoft.com/en-us/dotnet/core/diagnostics/metrics-instrumentation

spacentropy avatar Jun 01 '22 07:06 spacentropy

Hi, @bgrainger. Do you have any update for this topic?

tarasevichvlad avatar Feb 16 '23 09:02 tarasevichvlad

Based on Metric APIs comparison, System.Diagnostics.Metrics (.NET 6.0 and later) is the best approach to use for tracking metrics.

This namespace doesn't appear to be used by Npsql or Microsoft.Data.SqlClient, so there's no "prior art" to adapt for MySQL.

bgrainger avatar Feb 19 '23 04:02 bgrainger

@bgrainger https://www.npgsql.org/doc/diagnostics/metrics.html It is possible to create metrics view as maked in pgsql?

tarasevichvlad avatar Feb 20 '23 08:02 tarasevichvlad

Using System.Diagnostics.Metrics in MySqlConnector would make it possible for dotnet-counters monitor MySqlConnector -p <PID> to produce similar output to that table, yes.

bgrainger avatar Feb 20 '23 18:02 bgrainger

@bgrainger If I understand correctly, this is currently not implemented. I have searched the repository and have not found any evidence of the System.Diagnostics.Metrics namespace being used. Right?

tarasevichvlad avatar Apr 25 '23 14:04 tarasevichvlad

Correct; this issue is still open because the change has not been implemented.

bgrainger avatar Apr 26 '23 21:04 bgrainger

I opened a PR with a proposal for a specification for using System.Diagnostics.Metrics to implement the OpenTelemetry Semantic Conventions for Database Metrics: https://github.com/mysql-net/MySqlConnector/pull/1328.

This will provide a way to "extract some metrics from the pool like idle connections, connections in use, available connections" using the latest supported .NET APIs.

bgrainger avatar Jun 10 '23 23:06 bgrainger