MCPcopy Create free account
hub / github.com/OpenSN-Library/OpenSN-Library / readCpuUsage

Function readCpuUsage

daemon/utils/monitor.go:76–111  ·  view source on GitHub ↗
(filePath string)

Source from the content-addressed store, hash-verified

74}
75
76func readCpuUsage(filePath string) (float64, error) {
77 found := false
78 var usageUsec float64
79 f, err := os.Open(filePath)
80 if err != nil {
81 return usageUsec, err
82 }
83 defer f.Close()
84
85 r := bufio.NewReader(f)
86 for {
87 line, err := r.ReadString('\n')
88 if err != nil {
89 break
90 }
91 line = strings.TrimRight(line, "\n")
92 split := strings.Split(line, " ")
93 if len(split) < 2 {
94 continue
95 }
96 if split[0] == "usage_usec" {
97 usageUsec, err = strconv.ParseFloat(split[1], 64)
98 if err != nil {
99 return usageUsec, err
100 }
101 found = true
102 break
103 }
104 }
105
106 if !found {
107 return usageUsec, fmt.Errorf("field usage_usec not found")
108 }
109
110 return usageUsec, nil
111}
112
113func readUint64(filePath string) (uint64, error) {
114 var ret uint64

Callers 1

GetInstanceResourceInfoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected