Disable Metrics at runtime
I realize there was an issue created concerning disabling metrics (https://github.com/etishor/Metrics.NET/issues/5) and it was closed. This is a feature I think would be very useful, as often we only want to metrics when something is amiss; so if it could be turned on and off at runtime that would be very useful.
@dekenless the metrics library should add a very very small overhead to code running in production and because of this the library is designed to be always running or be completely disabled at startup.
You can completely disable the metrics library by adding a line to the config file. The main goal of this setting is to allow users to measure the impact and the overhead of the metrics library.
Adding support for turning the library on and off at runtime (not just at startup) is currently very hard to do. The reason is that since the application has been running, user objects will have references to metric objects (timers, counters etc) possibly in static readonly fields and these references would point to real metrics objects, and not to the NoOp versions that are used when metrics are disabled. Adding another layer of indirection to handle this, would impact the normal flow and intended usage of the library and it is not something i'm willing to do without a very good reason.
In conclusion, my suggestion would be to leave the metrics enabled in production - as they will always provide valuable information. To measure the impact of having the metrics enabled you can use the config setting to disable/enable them.
If the impact is noticeable, I would appreciate it if you could post more details. I'm running metrics in prod in a few projects and never noticed the impact, not even when measurements are taken on critical-path.
OK, I will handle it on my end as this is a must for my implementation as it is quite possible to have ~500 metrics (timers and counters). We need to insure that in a production environment the act of reporting on things does not inadvertently affect performance and if it does we need to be able to disable it without bringing down the service.
How about at least being able to stop the MetricsHttpListener at runtime?
What about something like what twitter server supports:
/admin/metrics Watch specific stats and extract them via http queries.
curl "localhost:8090/admin/metrics?m=clnt/crocodile/requests&m=clnt/crocodile/failures" [ { "name" : "clnt/crocodile/requests", "delta" : 643.0, "value" : 517342.0 }, { "name" : "clnt/crocodile/failures", "delta" : 90.0, "value" : 77430.0 } ]