MCPcopy Create free account
hub / github.com/apache/cloudstack / main

Function main

systemvm/debian/root/health_checks/cpu_usage_check.py:24–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22
23
24def main():
25 entries = getHealthChecksData("systemThresholds")
26 data = {}
27 if entries is not None and len(entries) == 1:
28 data = entries[0]
29
30 if "maxCpuUsage" not in data:
31 print("Missing maxCpuUsage in health_checks_data systemThresholds, skipping")
32 exit(3)
33
34 maxCpuUsage = float(data["maxCpuUsage"])
35 cmd = "top -b -n2 -p 1 | fgrep \"Cpu(s)\" | tail -1 | " \
36 "awk -F 'id,' " \
37 "'{ split($1, vs, \",\"); idle=vs[length(vs)]; " \
38 "sub(\"%\", \"\", idle); printf \"%.2f\", 100 - idle }'"
39 pout = Popen(cmd, shell=True, stdout=PIPE)
40 if pout.wait() == 0:
41 currentUsage = float(pout.communicate()[0].decode().strip())
42 if currentUsage > maxCpuUsage:
43 print("CPU Usage " + str(currentUsage) +
44 "% has crossed threshold of " + str(maxCpuUsage) + "%")
45 exit(1)
46 print("CPU Usage within limits with current at "
47 + str(currentUsage) + "%")
48 exit(0)
49 else:
50 print("Failed to retrieve cpu usage using " + cmd)
51 exit(3)
52
53
54if __name__ == "__main__":

Callers 1

cpu_usage_check.pyFile · 0.70

Calls 4

getHealthChecksDataFunction · 0.90
exitFunction · 0.85
waitMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected