-
Notifications
You must be signed in to change notification settings - Fork 72
Go Memory Monitoring
The Go language makes it really easy to expose runtime metrics for Go's memory usage and garbage collector. Inspeqtor can display graphs of this data for real-time monitoring in production!
This feature does require code changes within your Go daemon. Your daemon must expose its expvar data:
import _ "expvar"
- Start an HTTP server to make the data available on a port:
sock, err := net.Listen("tcp", "localhost:4001")
if err != nil {
return err
}
go func() {
fmt.Println("HTTP now available at port 4001")
http.Serve(sock, nil)
}()
You should now be able to hit http://localhost:4001/debug/vars and see a blob of JSON.
Now configure Inspeqtor's .inq file to fetch and expose this data:
check service etcd with port 4001
expose memstats
if memstats:Alloc > 1m for 2 cycles then alert
with port 4001
tells Inspeqtor which port to fetch the expvar data. Inspeqtor must be running on the same machine as the daemon. expose memstats
tells Inspeqtor to enable the Web UI to visualize the memstats within the expvar data. Notice you can also write typical Inspeqtor rules against the memstats metrics.
You can find Inspeqtor Pro's Web UI on http://localhost:4677/memory/. 4677 is INSP on an old telephone handset.
Inspeqtor tracks five memstats metrics; you can write rules as normal against them:
- Alloc - current amount of allocated memory (gauge)
- TotalAlloc - total amount of allocated memory for all time (counter)
- HeapAlloc - current heap size (gauge)
- NumGC - total number of garbage collections (counter)
- PauseTotalNs - total GC pause (counter)
Example:
check service etcd with port 4001
# ensure we aren't garbage collecting really frequently
if memstats:NumGC > 1/sec then alert
if memstat:Alloc > 100m then alert