Monitors Go application that exposes its metrics with the use of
expvar package from the Go standard library. The package produces charts for Go runtime memory statistics and optionally any number of custom charts.
go_expvar module produces the following charts:
Heap allocations in kB
- alloc: size of objects allocated on the heap
- inuse: size of allocated heap spans
Stack allocations in kB
- inuse: size of allocated stack spans
MSpan allocations in kB
- inuse: size of allocated mspan structures
MCache allocations in kB
- inuse: size of allocated mcache structures
Virtual memory in kB
- sys: size of reserved virtual address space
- live: number of live objects in memory
GC pauses average in ns
- avg: average duration of all GC stop-the-world pauses
Monitoring Go applications
Netdata can be used to monitor running Go applications that expose their metrics with the use of the expvar package included in Go standard library.
expvar package exposes these metrics over HTTP and is very easy to use.
Consider this minimal sample below:
When imported this way, the
expvar package registers a HTTP handler at
exposes Go runtime's memory statistics in JSON format. You can inspect the output by opening
the URL in your browser (or by using
You can of course expose and monitor your own variables as well. Here is a sample Go application that exposes a few custom variables:
Apart from the runtime memory stats, this application publishes two counters and the number of currently running Goroutines and updates these stats every second.
In the next section, we will cover how to monitor and chart these exposed stats with
the use of
Using Netdata go_expvar module
go_expvar module is disabled by default. To enable it, edit
python.d.conf (to edit it on your system run
/etc/netdata/edit-config python.d.conf), and change the
go_expvar variable to
Next, we need to edit the module configuration file (found at
/etc/netdata/python.d/go_expvar.conf by default) (to
edit it on your system run
/etc/netdata/edit-config python.d/go_expvar.conf). The module configuration consists of
jobs, where each job can be used to monitor a separate Go application. Let's see a sample job configuration:
Let's go over each of the defined options:
This is the job name that will appear at the Netdata dashboard. If not defined, the job_name (top level key) will be used.
This is the URL of the expvar endpoint. As the expvar handler can be installed in a custom path, the whole URL has to be specified. This value is mandatory.
Whether to enable collecting stats about Go runtime's memory. You can find more information about the exposed values at the runtime package docs.
Enables the user to specify custom expvars to monitor and chart. Will be explained in more detail below.
collect_memstats is disabled and no
extra_charts are defined, the plugin will
disable itself, as there will be no data to collect!
Apart from these options, each job supports options inherited from Netdata's
and its base
UrlService class. These are:
Monitoring custom vars with go_expvar
Now, memory stats might be useful, but what if you want Netdata to monitor some custom values
that your Go application exposes? The
go_expvar module can do that as well with the use of
extra_charts configuration variable.
extra_charts variable is a YaML list of Netdata chart definitions.
Each chart definition has the following keys:
Note: please do not use dots in the chart or line ID field. See this issue for explanation.
Please see these two links to the official Netdata documentation for more information about the values:
Each chart can define multiple lines (dimensions). A line definition is a key-value mapping of line options. Each line can have the following options:
Please see the following link for more information about the options and their default values: External plugins - dimensions
Apart from top-level expvars, this plugin can also parse expvars stored in a multi-level map; All dicts in the resulting JSON document are then flattened to one level. Expvar names are joined together with '.' when flattening.
In the above case, the exported variables will be available under
counters.cnt2 expvar_keys. If the flattening results in a key collision,
the first defined key wins and all subsequent keys with the same name are ignored.
python.d/go_expvar.conf configuration file using
edit-config from the your agent's config
directory, which is typically at
The configuration below matches the second Go application described above. Netdata will monitor and chart memory stats for the application, as well as a custom chart of running goroutines and two dummy counters.
Netdata charts example
The images below show how do the final charts in Netdata look.