The expvar package - Metrics for Go

Dec 17, 2014

Last week I discovered a mysterious package in the Go standard library, expvar. A google search turned up
little content on it. Undiscovered APIs for exploring? How exciting! I immediately dove in
and what I found was neat yet unsurprising.

The expvar package allows a Go process to expose variables to the public via an HTTP endpoint that emits
JSON. The simplest usage requires you to do two things in your custom code:

1. Import the package - this has the side effect of registering the /debug/vars HTTP endpoint.

(Put that blob into JSONLint if you want to see a more readable but verbose version.)

By default, Go's runtime exposes data about command line arguments, memory usage and garbage collection with very little effort, all
built into the standard library. Simple and easy yet powerful, like most Go functionality.

Wherein I Mix in some Awesome

Well, I'm even more excited because the next version of Inspeqtor Pro will have a Web UI for visualizing the
memory and GC data which the Go runtime exposes. This type of functionality is always what I've wanted in
production and with almost no effort. Sweet.

Here's a prototype I'm working on right now. You modify your Go daemon to expose the expvar memory data and
Inspeqtor Pro can give you this real-time memory visualization.

The Future

I'd love to see other runtimes expose similar data via HTTP/JSON. Can Ruby or Python expose similar data?
What about the JVM? Rubinius recently discussed their VM metrics support, let's see other runtimes do the same!
Make it easy to expose and tooling will appear to support it.