Watchmen is lightweight node.js based website and service monitoring tool. This is a cheatsheet to setup Wachmen on a Raspberry Pi.
I’m running Watchmen on a Raspberry Pi with Raspbian and I’m starting it via Systemd.
Since Watchmen runs on node.js start by installing node:
Install Latest Node
sudo apt remove nodejs # to remove old version of node if installed curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - sudo apt install nodejs node -v
If you’re running on an older ARMv6 based Pi (Pi 1 or Pi Zero), use these commands to install node:
wget http://node-arm.herokuapp.com/node_latest_armhf.deb sudo dpkg -i node_archive_armhf.deb node -v
More detailed instructions can be found here.
sudo apt-get update sudo apt-get install -y redis-server
In the startup config file /etc/systemd/system/multi-user.target.wants/redis-server.service change the following line to match the Watchmen install directory location:
Start and check the status of the redis server:
sudo systemctl daemon-reload sudo systemctl start redis-server redis-cli ping or redis-cli -p 1216 ping sudo systemctl status redis-server
Install git & Watchmen
sudo apt -y install git git clone https://github.com/iloire/watchmen.git cd watchmen npm install
Edit the redis.conf File
Edit the redis.conf file in the watchmen directory and update the home directory to the location where you’ve just installed Watchmen.
You may also need to change the redis port. The default Watchmen configuration expects to find redis at port 1216.
Let’s start everything manually to make sure it works:
redis-server redis.conf node run-monitor-server.js node run-web-server.js
You should now be able to browse to the Watchmen home page at http://localhost:3000. After doing that stop the two Watchmen node processes.
Setup Environment Variables
Set any Watchmen environment variables you need to be set at runtime in the .env file in the Watchmen home directory. For instance:
Install foreman to help with setup Watchmen as a server under Systemd.
sudo npm install -g foreman
Now start Watchmen manually using Foreman and then confirm that you can browse to http://localhost:3000
Create the systemd startup files:
sudo nf export --app watchmen--user root -t systemd -o /lib/systemd/system/
The following files are created in /lib/systemd/system:
watchmen-monitor-1.service # Starts run-monitor-server.js watchmen-monitor.target # Requires watchmen.target, Wants watchmen-monitor-1.service watchmen.target # Wanted-by multi-user.target, Wants watchmen-monitor.target watchmen-web.target watchmen-web-1.service # Starts run-web-server.js watchmen-web.target # Requires watchmen.target, Wants watchmen-web-1.service
Enable the Service:
sudo systemctl enable watchmen.target
You need to tell Systemd about the new configuration files:
sudo systemctl daemon-reload
You can then start Watchmen with the command:
sudo systemctl start watchmen.target
Console messages under Systemd with Raspbian are written to /var/log/daemon.log
MQTT with Watchmen
I use MQTT with Watchmen to integrate website monitoring with my IoT tools. I wrote a plugin on to do this which you can find on github here.