Skip to content

Instantly share code, notes, and snippets.

@graphaelli

graphaelli/cgs.go

Created Dec 1, 2020
Embed
What would you like to do?
package main
import (
"log"
"os"
"path"
"strconv"
"github.com/davecgh/go-spew/spew"
"github.com/elastic/gosigar"
"github.com/elastic/gosigar/cgroup"
)
func main() {
pids, err := os.Readlink(path.Join(gosigar.Procd, "self"))
if err != nil {
panic(err)
}
pid, err := strconv.Atoi(pids)
if err != nil {
panic(err)
}
cgroups, err := cgroup.NewReader("", true)
if err != nil {
if err == cgroup.ErrCgroupsMissing {
log.Fatalf("cgroup data collection disabled: %v", err)
} else {
log.Fatalf("cgroup data collection disabled: %v", err)
}
return
}
selfStats, err := cgroups.GetStatsForProcess(pid)
if err != nil {
log.Fatalf("error getting group status: %v", err)
return
}
spew.Dump(selfStats)
log.Println(pid)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment