yaorg / node-measured

A Node metrics library for measuring and reporting application-level metrics, inspired by Coda Hale, Yammer Inc's Dropwizard Metrics Libraries
https://yaorg.github.io/node-measured/
MIT License
517 stars 52 forks source link

Re-hydration from previous state #73

Open pocesar opened 4 years ago

pocesar commented 4 years ago

Right now, I'm accessing the "private" members directly, and assigning them manually. would be good to have an static method, like fromJSON(theOneReturnedFromtoJSON) to initialize the classes using a previous state.

fieldju commented 4 years ago

This sounds reasonable. I really dislike the method name toJson that all the metrics impl, because some of them do NOT return JSON, should really be getValue() or getPayload().

Since this lib is inspired from Dropwizard see: https://github.com/dropwizard/metrics/blob/4.1-development/metrics-core/src/main/java/com/codahale/metrics/Gauge.java#L25

So maybe the static initializer could be fromValue.

pocesar commented 4 years ago

recreating the internal representation is harder than I expected, there are too many moving parts (new class instances, and their internals as well)