I read the doc and know expvar provides interface for global variables. But I don't understand the design purpose for this pkg. Need some expert opnion on this
评论:
Loves_Portishead:
Loves_Portishead:The idea is to make the running process inspectable. The stdlib package debug/pprof for example can be used to set up an http server that gives GC and go routine stats. You can do the same to allow a 3rd party to inspect your process by making your "server" type implement the relevant methods so you can effortlessly see what it's doing from outside.
xopherus:Update to clarify "3rd party" in my initial description means something like collectd or telegraf with the JSON input source plugins.
fmpwizard:Exactly. You can use this with Consul to put active resource stats within a health check, and alert on that. Or you could dump the stats to Prometheus to set up time-series data.
marksteve4:For a concrete example, at work we have a batch process that can take several hours. We use expvars to tell us where in the whole process we are at any given time, originally they were string vars but because we use datadog for monitoring, and they only support numeric values, we keep a list of numeric constants.
We also have other variables to tell us the rate at which we are processing the data that comes in. It is really handy and easy to setup.
Orange_Tux:it's easy to understand
marksteve4:We use in service to monitor how many requests have been succesfully processed and how many failed.
I while ago I write a blog post about it: expvar in action.
Orange_Tux:the link is broken
Thanks for noticing. It has been fixed now.
