-
Notifications
You must be signed in to change notification settings - Fork 151
/
unicorn_memory.go
46 lines (41 loc) · 1.11 KB
/
unicorn_memory.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
44
45
46
package mpunicorn
import (
"fmt"
"strings"
)
func workersMemory() (string, error) {
out, err := pipedCommands.Output(
[]string{"ps", "auxw"},
[]string{"grep", "[u]nicorn"},
[]string{"grep", "-v", "master"},
[]string{"awk", "{m+=$6*1024} END{print m;}"},
)
if err != nil {
return "", fmt.Errorf("Cannot get unicorn workers memory: %s", err)
}
return strings.Trim(string(out), "\n"), nil
}
func masterMemory() (string, error) {
out, err := pipedCommands.Output(
[]string{"ps", "auxw"},
[]string{"grep", "[u]nicorn"},
[]string{"grep", "master"},
[]string{"awk", "{m+=$6*1024} END{print m;}"},
)
if err != nil {
return "", fmt.Errorf("Cannot get unicorn master memory: %s", err)
}
return strings.Trim(string(out), "\n"), nil
}
func workersMemoryAvg() (string, error) {
out, err := pipedCommands.Output(
[]string{"ps", "auxw"},
[]string{"grep", "[u]nicorn"},
[]string{"grep", "-v", "master"},
[]string{"awk", "{mem=$6*1024+mem; proc++} END{print mem/proc}"},
)
if err != nil {
return "", fmt.Errorf("Cannot get unicorn memory average: %s", err)
}
return strings.Trim(string(out), "\n"), nil
}