How can I get the total amount of memory/RAM attached to a system in Go? I want to use native code only if possible. I have found a library that wraps linux sysinfo command. Is there a more elegant way?
Besides runtime.MemStats you can use gosigar to monitor system memory.
cgo & linux solution
package main
// #include <unistd.h>
import "C"
func main() {
println(C.sysconf(C._SC_PHYS_PAGES)*C.sysconf(C._SC_PAGE_SIZE), " bytes")
}