-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
procs.go
57 lines (48 loc) · 879 Bytes
/
procs.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
47
48
49
50
51
52
53
54
55
56
57
package funcs
import (
"github.com/open-falcon/falcon-plus/common/model"
"github.com/open-falcon/falcon-plus/modules/agent/g"
"github.com/toolkits/nux"
"log"
"strings"
)
func ProcMetrics() (L []*model.MetricValue) {
reportProcs := g.ReportProcs()
sz := len(reportProcs)
if sz == 0 {
return
}
ps, err := nux.AllProcs()
if err != nil {
log.Println(err)
return
}
pslen := len(ps)
for tags, m := range reportProcs {
cnt := 0
for i := 0; i < pslen; i++ {
if is_a(ps[i], m) {
cnt++
}
}
L = append(L, GaugeValue(g.PROC_NUM, cnt, tags))
}
return
}
func is_a(p *nux.Proc, m map[int]string) bool {
// only one kv pair
for key, val := range m {
if key == 1 {
// name
if val != p.Name {
return false
}
} else if key == 2 {
// cmdline
if !strings.Contains(p.Cmdline, val) {
return false
}
}
}
return true
}