# Zookeeper Node Monitoring Daemon
[![# of downloads](https://pypip.in/d/zk_monitor/badge.png)](https://pypi.python.org/pypi/zk\_monitor)
This is a simple daemon for monitoring particular Zookeeper nodes for
compliance with a given set of specifications (ie, minimum number of
registered nodes). In the event that a path changes and becomes out of
spec, (too few nodes, for example), an alert is fired off to let you know.
## Clustered Design
*zk_monitor* is designed to operate in clustered mode with multiple redundant
agents running on multiple servers. The agents talk to eachother through
Zookeeper using a common path and a series of locks/znodes. You can run as
many agents as you want, but only one will ever handle sending off alerts.
Most of the connection and *zk_monitor* specific settings are managed via
$ python runserver.py --help
Usage: runserver.py <options>
--version show program's version number and exit
-h, --help show this help message and exit
-z ZOOKEEPER, --zookeeper=ZOOKEEPER
Zookeeper Server (def: localhost:2181)
Zookeeper ACL Username
Zookeeper ACL Password
-c CLUSTER_NAME, --cluster_name=CLUSTER_NAME
Unique cluster name (ie, prod-zookeeper-monitor)
Prefix path in Zookeeper for all zk_monitor clusters
-f FILE, --file=FILE Path to YAML file with znodes to monitor.
-p PORT, --port=PORT Port to listen to (def: 8080)
-l LEVEL, --level=LEVEL
Set logging level (INFO|WARN|DEBUG|ERROR)
-s SYSLOG, --syslog=SYSLOG
Log to syslog. Supply facility name. (ie "local0")
The list of paths that you want to monitor are supplied via a YAML
formatted configuration file. Here's an example file:
### Alerter Configuration
In the above example, you'll see that two of the paths have an 'alerter/email'
parameter configured. With this in place, any path spec violations will result
in an email fired off to that address. The third path does not have any
settings, which means that no alert will actually be sent off in the event of
a spec violation.
### Simple Execution
$ python runserver.py -l INFO -z localhost:2181 -f test.yaml
2014-05-31 16:20:25,862  [nd_service_registry] [__init__]: (INFO) Initializing ServiceRegistry object
2014-05-31 16:20:25,863  [nd_service_registry] [_connect]: (INFO) Connecting to Zookeeper Service (localhost:2181)
2014-05-31 16:20:25,867  [nd_service_registry] [_state_listener]: (INFO) Zookeeper connection state changed: CONNECTED
2014-05-31 16:20:25,868  [nd_service_registry] [__init__]: (INFO) Initialization Done!
2014-05-31 16:20:25,868  [zk_monitor.monitor] [_stateListener]: (INFO) Service registry connection state: True
## REST Interface
Though not necessary for alerting purposes, you can access the a JSON-formatted
REST interface for the intentionally inspecting the status of the app, and
the current compliance of your watched Zookeeper nodes.
This page provides a simple live status of the app and its monitors.
$ curl --silent http://localhost:8080/status
"/services/foo/min_1": "Found children (0) less than minimum (1)",
"/services/foo/min_3": "Found children (2) less than minimum (3)"
### Class/Object Architecture
| | Connection to Zookeeper
| | Handles dispatching of all alerts to Alerter objects
| +-- alerts.email.EmailAlerter
| | | Sends Email-Based Alerts Asynchronously
| | |
| | +-- tornadomail.backends.smtp.EmailBackend()
| +-- alerts.rest.HipChatAlerter
| | Sends Hipchat Alerts Asynchronously
| | Handles node-to-node communication via Zookeeper
| +-- Registers /zk_monitor/agent/<agent name="">
| | Monitors all configured paths
| +-- Obj Ref -> alerts.Dispatcher
| | Alerts are fired off to the Dispatcher, the Dispatcher
| | handles determining whether or not the alert is a dup, a shift
| | from in-compliance to out-of-compliance (or vice versa),
| | and which Alerters to fire off (Hipchat, Email, etc).
| | Handles all web requests
| +-- web.app.getApplication()
| +-- root.RootHandler
| | URL: /
| +-- state.StateHandler
| | URL: /state
| | Obj Ref -> nd_service_registry.KazooServiceRegistry
| | Obj Ref -> monitor.Monitor
# Create a dedicated Python virtual environment and source it
virtualenv --no-site-packages .venv
# Install the dependencies
# Run the tests
### Postfix on Mac OSX
If you want to develop on a Mac OSX host, you need to enable email the
*postfix* daemon on your computer. Here's how!
--- /System/Library/LaunchDaemons/org.postfix.master.plist.bak 2014-06-02 11:45:24.000000000 -0700
+++ /System/Library/LaunchDaemons/org.postfix.master.plist 2014-06-02 11:47:07.000000000 -0700
@@ -9,8 +9,6 @@
@@ -18,5 +16,8 @@
Restart the service:
sudo launchctl unload org.postfix.master.plist
sudo launchctl load org.postfix.master.plist
TODO: Brief introduction on what you do with files - including link to relevant help section.