-
Notifications
You must be signed in to change notification settings - Fork 51
/
netcls.go
44 lines (37 loc) · 1.02 KB
/
netcls.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
package cgnetcls
import (
"io/ioutil"
"path/filepath"
"go.uber.org/zap"
)
// receiver definition.
type netCls struct {
markchan chan uint64
ReleaseAgentPath string
TriremePath string
}
var basePath = "/sys/fs/cgroup/net_cls"
var markval uint64 = Initialmarkval
// GetCgroupList geta list of all cgroup names
func GetCgroupList() []string {
var cgroupList []string
filelist, err := ioutil.ReadDir(filepath.Join(basePath, TriremeBasePath))
if err != nil {
return cgroupList
}
for _, file := range filelist {
if file.IsDir() {
cgroupList = append(cgroupList, file.Name())
}
}
return cgroupList
}
// GetAssignedMarkVal -- returns the mark val assigned to the group
func GetAssignedMarkVal(cgroupName string) string {
mark, err := ioutil.ReadFile(filepath.Join(basePath, TriremeBasePath, cgroupName, markFile))
if err != nil || len(mark) < 1 {
zap.L().Error("Unable to read markval for cgroup", zap.String("Cgroup Name", cgroupName), zap.Error(err))
return ""
}
return string(mark[:len(mark)-1])
}