forked from mushorg/glutton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.go
43 lines (39 loc) · 900 Bytes
/
system.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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 <-ticker.C:
openFiles := countOpenFiles()
runningRoutines := countRunningRoutines()
g.logger.Info(fmt.Sprintf("[system ] running Go routines: %d and open files: %d, connections: %d",
openFiles, runningRoutines, g.processor.Connections.Length()))
case <-quit:
g.logger.Info("[system ] Monitoring stopped..")
ticker.Stop()
return
}
}
}()
}