Usuario:Luis.perez/sistemaspyaytozgz/watchdog
De WikiEducator
Por ahora no está disponible por defecto en distribuciones. Basta con descargar:
https://raw.github.com/sebastien/watchdog/master/Sources/watchdog.py
e incluirlo en el pythonpath.
O bien clonar o descargar el repo https://github.com/sebastien/watchdog.git
e instalarlo mediante
$ python setup.py install
Ejemplo básico:
from watchdog import * Monitor( Service( name="apache-ensure-up", monitor=( HTTP( GET="http://localhost:80/", freq=Time.ms(500), fail=[ Print("Apache is down!!") ] ) ) ) ).run()
Enviando emails:
HTTP( GET="http://myservice.com/, freq=Time.ms(500), fail=[ Email( "admin@company.com", "[Watchdog] Service unreachable", "Latency over 500ms", "smtp.company.com", "username", "password" ] )
Incidentes, varios errores en un determinado tiempo:
HTTP( GET="http://myservice.com/, freq=Time.ms(500), fail=[ Incident( errors = 5, during = Time.s(10) actions = [ ... ] ] )
Monitorizando la salud del sistema:
SystemInfo( freq=Time.s(1), success = ( LogResult("myserver.system.mem=", extract=lambda r,_:r["memoryUsage"]), LogResult("myserver.system.disk=", extract=lambda r,_:reduce(max,r["diskUsage"].values())), LogResult("myserver.system.cpu=", extract=lambda r,_:r["cpuUsage"]), ) ), Delta( Bandwidth("eth0", freq=Time.s(1)), extract = lambda v:v["total"]["bytes"]/1000.0/1000.0, success = [LogResult("myserver.system.eth0.sent=")] ), SystemHealth( cpu=0.90, disk=0.90, mem=0.90, freq=Time.s(60), fail=[Print("Health compromised!!")] )