github.com/georgethebeatle/containerd@v0.2.5/containerd/main_linux.go (about) 1 package main 2 3 import ( 4 "os" 5 "runtime" 6 "time" 7 8 "github.com/Sirupsen/logrus" 9 "github.com/cloudfoundry/gosigar" 10 "github.com/docker/containerd/osutils" 11 "github.com/rcrowley/go-metrics" 12 ) 13 14 func processMetrics() { 15 var ( 16 g = metrics.NewGauge() 17 fg = metrics.NewGauge() 18 memg = metrics.NewGauge() 19 ) 20 metrics.DefaultRegistry.Register("goroutines", g) 21 metrics.DefaultRegistry.Register("fds", fg) 22 metrics.DefaultRegistry.Register("memory-used", memg) 23 collect := func() { 24 // update number of goroutines 25 g.Update(int64(runtime.NumGoroutine())) 26 // collect the number of open fds 27 fds, err := osutils.GetOpenFds(os.Getpid()) 28 if err != nil { 29 logrus.WithField("error", err).Error("containerd: get open fd count") 30 } 31 fg.Update(int64(fds)) 32 // get the memory used 33 m := sigar.ProcMem{} 34 if err := m.Get(os.Getpid()); err != nil { 35 logrus.WithField("error", err).Error("containerd: get pid memory information") 36 } 37 memg.Update(int64(m.Size)) 38 } 39 go func() { 40 collect() 41 for range time.Tick(30 * time.Second) { 42 collect() 43 } 44 }() 45 }