-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Allow inspecting connections and statements #178
Comments
The driver itself does not count the number of its own connections nor does it keep references to its connections or statements. But it could definitely be done with the current database/sql package, the data is there, but not available via an exported API. |
For the reflection way of doing things, also take a look at https://github.com/arnehormann/mirror - it enables safe usage of unsafe and is imported by sqlinternals. Just send me an email If you need pointers or any other kind of help with the code (at gmail.com). |
@xaprb Is there still demand for this? |
The best way to do this IMO is to offer cumulative counters since the beginning of time. These counters could be subtracted from each other in some cases to offer snapshots of the state right now:
You could e.g. subtract There are probably other ideas but that's my ideas at the moment. |
Unless we lock the complete driver, we can't read all those values atomically. So if you read the number of connections opened first, then the number of connections closed, the difference might be negative. |
I'm not sure I agree the complete driver has to be locked. Make a struct
with fields for these stats and guard it with a mutex. But you know better
than I.
|
Can the expvar package be leveraged for this? In my projects that have http interfaces, that's where I'd want to expose these values. |
I feel non of them are MySQL specific. |
DB.Stats is already the first step in this direction. This kind information should be provided by the database interface, not by the underlying driver. And as @methane said, this is not specific to MySQL. On a driver level we could only collect global stats, since we don't know to which pool a connection or statement belongs. Please request it for addition in database/sql instead. |
As far as I can tell neither database/sql nor this driver let you do things like see how many connections are open, inspect them, or look at what statements have been prepared but not closed. It is often very helpful to do that in order to debug problems in the application. For example, I'm working on such a thing right now -- I think I'm leaking prepared statements but it's hard to tell without adding a lot of logging around every db.Prepare() and stmt.Close() call.
Is something like this reasonable to consider adding into the driver so that you could get those kinds of things and emit metrics to a monitoring system, write to a log, or something else as a result?
The text was updated successfully, but these errors were encountered: