From 0e64b4838811d27a98f7913ed48fda6f36c2522e Mon Sep 17 00:00:00 2001 From: Marco Ochse <t3chn0m4g3@gmail.com> Date: Fri, 18 May 2018 20:47:54 +0000 Subject: [PATCH] turn logging noiselevel down --- docker/glutton/Dockerfile | 1 + docker/glutton/dist/system.go | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 docker/glutton/dist/system.go diff --git a/docker/glutton/Dockerfile b/docker/glutton/Dockerfile index 4531dcaf..0507d55e 100644 --- a/docker/glutton/Dockerfile +++ b/docker/glutton/Dockerfile @@ -19,6 +19,7 @@ RUN apk -U --no-cache add \ mkdir -p /opt/go/ && \ go get -d github.com/mushorg/glutton && \ go get -u github.com/golang/dep/cmd/dep && \ + mv /root/dist/system.go /opt/go/src/github.com/mushorg/glutton/ && \ cd /opt/go/src/github.com/mushorg/glutton/ && \ /opt/go/bin/dep ensure && \ make build && \ diff --git a/docker/glutton/dist/system.go b/docker/glutton/dist/system.go new file mode 100644 index 00000000..2b94acc7 --- /dev/null +++ b/docker/glutton/dist/system.go @@ -0,0 +1,38 @@ +package glutton + +import ( + "fmt" + "log" + "os" + "os/exec" + "runtime" + "strings" + "time" +) + +func countOpenFiles() int { + out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -p %v", os.Getpid())).Output() + if err != nil { + log.Fatal(err) + } + lines := strings.Split(string(out), "\n") + return len(lines) - 1 +} + +func countRunningRoutines() int { + return runtime.NumGoroutine() +} + +func (g *Glutton) startMonitor(quit chan struct{}) { + ticker := time.NewTicker(10 * time.Second) + go func() { + for { + select { + case <-quit: + g.logger.Info("[system ] Monitoring stopped..") + ticker.Stop() + return + } + } + }() +}