Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved SystemHealth with better reporting

  • Loading branch information...
commit 46dbf7391283746e0bfc3b753cd9a4a7c3054061 1 parent 8ec0c1d
@sebastien authored
Showing with 30 additions and 10 deletions.
  1. +30 −10 Sources/watchdog.py
View
40 Sources/watchdog.py
@@ -574,6 +574,12 @@ def __init__(self, value=True, message=None):
self.value = value
self.duration = None
+ def isSuccess( self ):
+ return True
+
+ def isFailure( self ):
+ return False
+
def __str__(self):
return str(self.value)
@@ -590,6 +596,12 @@ def __init__(self, message="Failure", value=None):
self.value = value
self.duration = None
+ def isSuccess( self ):
+ return False
+
+ def isFailure( self ):
+ return True
+
def __str__(self):
return str(self.message)
@@ -990,7 +1002,7 @@ def __repr__(self):
class SystemHealth(Rule):
"""Defines thresholds for key system health stats."""
- def __init__(self, freq, cpu=0.90, disk=0.90, mem=0.90, fail=(), success=()):
+ def __init__(self, freq=Time.s(1), cpu=0.90, disk=0.90, mem=0.90, fail=(), success=()):
"""Monitors the system health with the following thresholds:
- 'cpu' (0.90 by default)
@@ -1012,22 +1024,30 @@ def run(self):
- ['disk', <actual value:float>, <threshold value:float>, <mount point:string>]
"""
- errors = []
- cpu = System.CPUUsage()
- mem = System.MemoryUsage()
+ errors = {}
+ values = {}
+ cpu = System.CPUUsage()
+ mem = System.MemoryUsage()
disk = System.DiskUsage()
if cpu > self.cpu:
- errors.append(("cpu", cpu, self.cpu))
+ errors["cpu"] = (cpu, self.cpu)
+ else:
+ values["cpu"] = (cpu, self.cpu)
if mem > self.mem:
- errors.append(("mem", mem, self.mem))
+ errors["cpu"] = (mem, self.mem)
+ else:
+ values["mem"] = (mem, self.mem)
for mount, usage in disk.items():
if usage > self.disk:
- errors.append(("disk", usage, self.disk))
+ errors.setdefault("disk", {})
+ errors["disk"][mount] = (usage, self.disk)
+ else:
+ values.setdefault("disk", {})
+ values["disk"][mount] = (usage, self,disk)
if errors:
- return Failure(errors)
+ return Failure("errors with %s" % (", ".join(errors.keys())), value=dict(values=values, errors=errors))
else:
- return Success()
-
+ return Success(value=dict(values=values))
class ProcessInfo(Rule):
"""Returns statistics about the process with the given command, the rule

0 comments on commit 46dbf73

Please sign in to comment.
Something went wrong with that request. Please try again.