This code was tested on a Raspberry Pi 3 with Raspian Jessie, values were "pushed" to an influxDB and then were visualized with Grafana.
# first "go get" the goprocinfo library:
go get github.com/c9s/goprocinfo
# then run it with
go run main.go
goprocinfo uses /proc/stat
and /proc/meminfo
pseudo-files.
I follow the approach proposed here: Accurate calculation of CPU usage given in percentage in Linux
I follow the approach proposed here (by the htop
command author): How to calculate memory usage from /proc/meminfo (like htop)