()
| 22 | |
| 23 | |
| 24 | def 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 | |
| 54 | if __name__ == "__main__": |
no test coverage detected