Skip to content

Commit

Permalink
Renamed watchdog -> monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien committed Jan 22, 2013
1 parent cf5c09e commit ee37b1b
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 65 deletions.
21 changes: 21 additions & 0 deletions Contrib/monitoring_upstart.conf
@@ -0,0 +1,21 @@
# upstart - Monitoring Configuration File
# ========================================
# updated: 2011-02-28

description "Monitoring - service monitoring daemon"
author "Sebastien Pierre <sebastien@ffctn.com>"

start on (net-device-up and local-filesystems)
stop on runlevel [016]

respawn
console output

script
# NOTE: Change this to wherever the monitoring is installed
MONITORING_HOME=/opt/services/monitoring
cd $MONITORING_HOME
# NOTE: Change this to wherever your custom monitoring script is installed
python $MONITORING_HOME/monitoring.py
end script
# EOF
21 changes: 0 additions & 21 deletions Contrib/watchdog_upstart.conf

This file was deleted.

28 changes: 28 additions & 0 deletions ERROR
@@ -0,0 +1,28 @@
Exception in thread Thread-138266:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 505, in run
self.__target(*self.__args, **self.__kwargs)
File "/opt/lib/python/monitoring.py", line 1198, in _run
self.result = self.runnable.run(*self.args)
File "/opt/lib/python/monitoring.py", line 974, in run
pid = Process.GetWith(self.command)
File "/opt/lib/python/monitoring.py", line 281, in GetWith
if compare(cmdline, expression):
File "/opt/lib/python/monitoring.py", line 275, in <lambda>
def GetWith(self, expression, compare=(lambda a, b: fnmatch.fnmatch(a, b))):
File "/usr/lib/python2.7/fnmatch.py", line 43, in fnmatch
return fnmatchcase(name, pat)
File "/usr/lib/python2.7/fnmatch.py", line 79, in fnmatchcase
return _cache[pat].match(name) is not None
TypeError: expected string or buffer

Traceback (most recent call last):
File "/opt/apps/ngsexplorers/monitoring.conf", line 42, in <module>
Run("echo '' > /tmp/monitoring-default.log","/tmp")
File "/opt/lib/python/monitoring.py", line 1274, in run
runner = self.runnerForRule(rule, service, self.iteration)
File "/opt/lib/python/monitoring.py", line 1244, in runnerForRule
if iteration - runner.iteration < 5:
AttributeError: 'bool' object has no attribute 'iteration'
4 changes: 2 additions & 2 deletions Examples/example-service-isrunning.py
@@ -1,4 +1,4 @@
from watchdog import *
from monitoring import *
__doc__ = """How to ensure that a given (HTTP) service stays up and running."""
Monitor(
Service(
Expand All @@ -18,7 +18,7 @@
# We kill the 'myservice-start.py' script if it exists
# and (re)start it, so that the 'http://localhost:8000' will
# become available
# NOTE: Restart will make the process a child of the watchdog, so
# NOTE: Restart will make the process a child of the monitoring, so
# you might prefer to use something like upstart
Restart("myservice-start.py")
]
Expand Down
4 changes: 2 additions & 2 deletions Examples/example-service-monitoring.py
@@ -1,11 +1,11 @@
#!/usr/bin/env python
from watchdog import *
from monitoring import *
Monitor(
Service(
name = "google-search-latency",
monitor = (
HTTP(
GET="http://www.google.ca/search?q=watchdog",
GET="http://www.google.ca/search?q=monitoring",
freq=Time.s(1),
timeout=Time.ms(80),
fail=[
Expand Down
4 changes: 2 additions & 2 deletions Examples/example-system-health.py
@@ -1,4 +1,4 @@
from watchdog import *
from monitoring import *
Monitor (
Service(
name = "system-health",
Expand All @@ -18,7 +18,7 @@
SystemHealth(
cpu=0.90, disk=0.90, mem=0.90,
freq=Time.s(60),
fail=[Log(path="watchdog-system-failures.log")]
fail=[Log(path="monitoring-system-failures.log")]
),
)
)
Expand Down
8 changes: 4 additions & 4 deletions Makefile
@@ -1,4 +1,4 @@
# Watchdog makefile
# Monitoring makefile
# --------------------
#
# Revision 1.5.1 (24-Mar-2006)
Expand All @@ -24,7 +24,7 @@
# Project variables___________________________________________________________
#
# Project name. Do not put spaces.
PROJECT = watchdog
PROJECT = monitoring
PROJECT_VERSION = $(shell grep __version__ Sources/*.py | cut -d'"' -f2)

DOCUMENTATION = Documentation
Expand All @@ -38,10 +38,10 @@ DISTROCONTENT = $(DOCUMENTATION) $(SOURCES) $(TESTS) $(RESOURCES) \

# Project files_______________________________________________________________

PACKAGE = watchdog
PACKAGE = monitoring
MAIN =
MODULES = \
watchdog \
monitoring \

TEST_MAIN = $(TESTS)/$(PROJECT)Test.py
SOURCE_FILES = $(shell find $(SOURCES) -name "*.py")
Expand Down
15 changes: 10 additions & 5 deletions README.rst
@@ -1,8 +1,13 @@
Watchdog - Server monitoring and data-collection daemon
Monitoring - Server monitoring and data-collection daemon
==========================================================

We want...
----------
Monitoring is an API with a DSL feel to write monitoring daemons
in Python.

Use cases
---------

Monitoring works well for the following tasks:

* to be notified when incidents happen (email, XMPP, ZeroMQ...)
* automatic actions to be taken (restart, rm, git pull...)
Expand Down Expand Up @@ -38,11 +43,11 @@ python setup.py install
or

```
easy_install watchdog
easy_install monitoring
```

More?
-----

Read the `presentation on Watchdog <http://ur1.ca/45ku5>`_ (previously named
Read the `presentation on Monitoring <http://ur1.ca/45ku5>`_ (previously named
Watchdog).
3 changes: 3 additions & 0 deletions Scripts/monitoring
@@ -0,0 +1,3 @@
#!/usr/bin/python
import sys, monitoring
monitoring.command(sys.argv[1:])
3 changes: 0 additions & 3 deletions Scripts/watchdog

This file was deleted.

26 changes: 13 additions & 13 deletions Sources/watchdog.py → Sources/monitoring.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -----------------------------------------------------------------------------
# Project : Watchdog
# Project : Monitoring
# -----------------------------------------------------------------------------
# Author : Sebastien Pierre <sebastien@ffctn.com>
# License : Revised BSD Licensed
Expand All @@ -27,9 +27,9 @@

# File "sample-reporter.py", line 35, in <module>
# fail = [SendStat(ADKIT_STATSERVICE, "mediaserver.ms-1.failure")]
# File "/home/sebastien/Projects/Local/lib/python/watchdog.py", line 669, in run
# File "/home/sebastien/Projects/Local/lib/python/monitoring.py", line 669, in run
# Runner(rule,context=service,iteration=self.iteration).onRunEnded(self.onRuleEnded).run()
# File "/home/sebastien/Projects/Local/lib/python/watchdog.py", line 620, in run
# File "/home/sebastien/Projects/Local/lib/python/monitoring.py", line 620, in run
# self._thread.start()
# File "/usr/lib/python2.6/threading.py", line 474, in start
# _start_new_thread(self.__bootstrap, ())
Expand Down Expand Up @@ -188,7 +188,7 @@ def setup(self):
signal.signal(getattr(signal, sig), self._shutdown)
self.signalsRegistered.append(sig)
except Exception, e:
Logger.Err("[!] watchdog.Signals._registerSignals:%s %s\n" % (sig, e))
Logger.Err("[!] monitoring.Signals._registerSignals:%s %s\n" % (sig, e))

def _shutdown(self, *args):
"""Safely executes the callbacks registered in self.onShutdown."""
Expand Down Expand Up @@ -784,7 +784,7 @@ def successMessage(self, monitor, service, rule, runner):
return "%s %s %s" % (self.preamble(monitor, service, rule, runner), self.message, self.extractor(runner.result.value, runner))


class LogWatchdogStatus(Log):
class LogMonitoringStatus(Log):

def __init__(self, path=None, stdout=True, overwrite=False):
Log.__init__(self, path, stdout, overwrite)
Expand Down Expand Up @@ -848,7 +848,7 @@ def run(self, monitor, service, rule, runner):
class Restart(Action):
"""Restarts the process with the given command, killing the process if it
already exists, starting it if it doesn't. Use this one with care as the
process will become a child of the watchdog -- it's better to use
process will become a child of the monitoring -- it's better to use
start/stop scripts if the process is long-running."""

def __init__(self, command, cwd=None):
Expand Down Expand Up @@ -901,7 +901,7 @@ def run(self, monitor, service, rule, runner):

def send(self, monitor=None, service=None, rule=None, runner=None):
server = smtplib.SMTP(self.host)
origin = self.origin or "<Watchdog for %s> watchdog@%s" % (service and service.name, popen("hostname")[:-1])
origin = self.origin or "<Monitoring for %s> monitoring@%s" % (service and service.name, popen("hostname")[:-1])
message = string.Template(self.MESSAGE).safe_substitute({
"from": origin,
"to": self.recipient,
Expand Down Expand Up @@ -1051,7 +1051,7 @@ def run(self, monitor, service, rule, runner):
class Rule:
"""Rules return either a Sucess or Failure when run, and take actions
as 'fail' or 'success' arguments, which will be triggered by the
watchdog service."""
monitoring service."""

COUNT = 0

Expand Down Expand Up @@ -1344,7 +1344,7 @@ def getAction(self, nameOrAction):
# -----------------------------------------------------------------------------

class Pool:
"""Pools are used in Watchdog to limit the number of runners/rules executed
"""Pools are used in Monitoring to limit the number of runners/rules executed
at once. Pools have a maximum capacity, so that you can limit the numbers
of elements you create."""

Expand Down Expand Up @@ -1422,7 +1422,7 @@ def __init__(self, runable, context=None, iteration=None, pool=None, id=None):
self.id = id
self._thread = threading.Thread(target=self._run)
# We want the threads to be "daemonic", ie. they will all stop once
# the main watchdog stops.
# the main monitoring stops.
# SEE: http://docs.python.org/release/2.5.2/lib/thread-objects.html
self._thread.setDaemon(True)

Expand Down Expand Up @@ -1474,7 +1474,7 @@ def _run(self):
# -----------------------------------------------------------------------------

class Monitor:
"""The monitor is at the core of the Watchdog. Rules declared in registered
"""The monitor is at the core of the Monitoring. Rules declared in registered
services are run, and actions are executed according to the result."""

FREQUENCY = Time.s(5)
Expand All @@ -1484,7 +1484,7 @@ def __init__(self, *services):
self.services = []
self.isRunning = False
self.freq = self.FREQUENCY
self.logger = Logger(prefix="watchdog ")
self.logger = Logger(prefix="monitoring ")
self.iteration = 0
self.iterationLastDuration = 0
self.runners = {}
Expand Down Expand Up @@ -1639,7 +1639,7 @@ def getStatusMessage(self):

def command(args):
if len(args) != 1:
print "Usage: watchdog FILE"
print "Usage: monitoring FILE"
else:
with file(args[0],"r") as f:
exec f.read()
Expand Down
4 changes: 2 additions & 2 deletions Tests/test-action-email.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python
from watchdog import *
from monitoring import *
import json
config = json.loads(file("email.passwd").read())
action = Email(
"sebastien@ffctn.com",
"[Watchdog] Test", "Sample message",
"[Monitoring] Test", "Sample message",
config["smtp"],config["user"],config["password"]
)
Monitor(
Expand Down
2 changes: 1 addition & 1 deletion Tests/test-action-incident.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from watchdog import *
from monitoring import *
__doc__ = """
Fail every second, and only triggers the log result after at least 5 failures over 10 seconds
"""
Expand Down
4 changes: 2 additions & 2 deletions Tests/test-action-xmpp.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python
from watchdog import *
from monitoring import *
import json
config = json.loads(file("jabber.passwd").read())
action = XMPP(
"sebastien@ffctn.com",
"Watchdog: testing iteration #${iteration}@${timestamp}=${result}",
"Monitoring: testing iteration #${iteration}@${timestamp}=${result}",
config["user"], config["password"]
)
Monitor(
Expand Down
4 changes: 2 additions & 2 deletions Tests/test-looping-action.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python
from watchdog import *
from monitoring import *
import time

__doc__ = """
In this test we create a LoopingAction (an action that will never end). We want
to make sure that at the third iteration the watchdog won't be able to start
to make sure that at the third iteration the monitoring won't be able to start
the LoopingAction.
"""

Expand Down
13 changes: 7 additions & 6 deletions setup.py
Expand Up @@ -3,20 +3,21 @@
# See: <http://docs.python.org/distutils/introduction.html>
from distutils.core import setup
import os, sys
VERSION = eval(filter(lambda _:_.startswith("__version__"), file("Sources/watchdog.py").readlines())[0].split("=")[1])
VERSION = eval(filter(lambda _:_.startswith("__version__"), file("Sources/monitoring.py").readlines())[0].split("=")[1])
setup(
name = "watchdog",
name = "monitoring",
version = VERSION,
description = "Server monitoring and data-collection daemon",
author = "Sébastien Pierre",
author_email = "sebastien.pierre@gmail.com",
url = "http://github.com/sebastien/watchdog",
download_url = "https://github.com/sebastien/watchdog/tarball/%s" % (VERSION),
url = "http://github.com/sebastien/monitoring",
download_url = "https://github.com/sebastien/monitoring/tarball/%s" % (VERSION),
keywords = ["daemon", "services", "monitoring", "administration"],
install_requires = [],
package_dir = {"":"Sources"},
py_modules = ["watchdog"],
scripts = ["Scripts/watchdog"],
py_modules = ["monitoring"],
scripts = ["Scripts/monitoring"],
license = "License :: OSI Approved :: BSD License",
classifiers = [
"Programming Language :: Python",
"Development Status :: 3 - Alpha",
Expand Down

0 comments on commit ee37b1b

Please sign in to comment.