Alerting and Monitoring with Sensu part 2
This is the second blog post about Sensu as an Alerting and Monitoring solution. If you did not read the first part I recommend you check it out here.
For this blog post, I will share a Vagrantfile so you have run sensu in your machine easily. To play with Sensu you need to have some components like:
* A sensu Client
* A sensu Server
* RabbitMQ
* Uchiwa for Sensu Server
TLDR; Check it out all file in my GitHub account.
client-config.json
sensu-client.json
uchiwa-config.json
provision.client.sh
provision-server.sh
vagrantfile
Once you download all files you can place all the files in the same directory, run:
PS: If you have issues, do this:
For this blog post, I will share a Vagrantfile so you have run sensu in your machine easily. To play with Sensu you need to have some components like:
* A sensu Client
* A sensu Server
* RabbitMQ
* Uchiwa for Sensu Server
TLDR; Check it out all file in my GitHub account.
client-config.json
This is the client configuration in Sensu. You should have one of this files per client. Most of time people do scripts to generate this file dynamically because often you just change the hostname and channels per client.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"client": { | |
"name": "10.10.99.50", | |
"address": "10.10.99.50", | |
"subscriptions": [ | |
"test" | |
] | |
} | |
} |
sensu-client.json
This config is how sensu client communicates with the server. Via RabbitMQ sending and receiving messages in a pub/sub-arch model.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rabbitmq": { | |
"host": "10.10.99.60", | |
"vhost": "/sensu", | |
"user": "sensu", | |
"password": "secret" | |
} | |
} |
This is the Uchiwa(Sensu Server Dashboard) configuration. You can have one instance for all your datacenters if you like. This goes with the sensu-server box.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"sensu": [ | |
{ | |
"name": "local-server(10.10.99.60)", | |
"host": "127.0.0.1", | |
"port": 4567, | |
"timeout": 5 | |
} | |
], | |
"uchiwa": { | |
"host": "0.0.0.0", | |
"port": 3000, | |
"interval": 5 | |
} | |
} |
This is the bash script file used by vagrant to provision sensu client box.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
wget -q http://repositories.sensuapp.org/apt/pubkey.gpg -O- | sudo apt-key add - | |
echo "deb http://repositories.sensuapp.org/apt sensu main" | sudo tee /etc/apt/sources.list.d/sensu.list | |
sudo apt-get update | |
sudo apt-get install sensu | |
sudo wget -O /etc/sensu/conf.d/client.json http://sensuapp.org/docs/0.21/files/client.json | |
sudo chown -R sensu:sensu /etc/sensu | |
sudo sensu-install -p disk-checks:1.0.2 | |
sudo mv /home/vagrant/sensu-client.json /etc/sensu/config.json | |
sudo mv /home/vagrant/client-config.json /etc/sensu/conf.d/client.json | |
sudo /etc/init.d/sensu-client start | |
sudo update-rc.d sensu-client defaults |
This is the bash script file used by vagrant to provision sensu server box.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Messaging with Rabbitmq | |
sudo wget http://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb | |
sudo dpkg -i erlang-solutions_1.0_all.deb | |
sudo apt-get update | |
sudo apt-get -y install erlang-nox=1:18.2 | |
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.0/rabbitmq-server_3.6.0-1_all.deb | |
sudo dpkg -i rabbitmq-server_3.6.0-1_all.deb | |
sudo /etc/init.d/rabbitmq-server start | |
sudo rabbitmqctl add_vhost /sensu | |
sudo rabbitmqctl add_user sensu secret | |
sudo rabbitmqctl set_permissions -p /sensu sensu ".*" ".*" ".*" | |
# Metric Store Redis | |
sudo apt-get -y install redis-server | |
sudo update-rc.d redis-server defaults | |
sudo /etc/init.d/redis-server restart | |
# Sensu | |
wget -q http://repositories.sensuapp.org/apt/pubkey.gpg -O- | sudo apt-key add - | |
echo "deb http://repositories.sensuapp.org/apt sensu main" | sudo tee /etc/apt/sources.list.d/sensu.list | |
sudo apt-get update | |
sudo apt-get install sensu -y | |
sudo wget -O /etc/sensu/config.json http://sensuapp.org/docs/0.21/files/config.json | |
sudo wget -O /etc/sensu/conf.d/check_disk.json http://sensuapp.org/docs/0.21/files/check_disk.json | |
sudo wget -O /etc/sensu/conf.d/default_handler.json http://sensuapp.org/docs/0.21/files/default_handler.json | |
sudo chown -R sensu:sensu /etc/sensu | |
sudo /etc/init.d/sensu-server start | |
sudo /etc/init.d/sensu-api start | |
sudo update-rc.d sensu-server defaults | |
sudo update-rc.d sensu-api defaults | |
# Sensu Client | |
sudo wget -O /etc/sensu/conf.d/client.json http://sensuapp.org/docs/0.21/files/client.json | |
sudo chown -R sensu:sensu /etc/sensu | |
sudo sensu-install -p disk-checks:1.0.2 | |
sudo /etc/init.d/sensu-client start | |
sudo update-rc.d sensu-client defaults | |
# Uchiwa - Dashboard | |
sudo apt-get install uchiwa -y | |
sudo mv /home/vagrant/uchiwa-config.json /etc/sensu/uchiwa.json | |
sudo /etc/init.d/uchiwa start |
This is the Vagrantfile itself which uses other previous files. As you see there is an array with the configs so we can use them in the main vagrant construct instead of duplication code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
servers=[ | |
{ | |
:hostname => "sensu-client", | |
:ip => "10.10.99.50", | |
:box => "ubuntu/trusty64", | |
:ram => 1024, | |
:cpu => 2, | |
:provision => "provision.client.sh" | |
}, | |
{ | |
:hostname => "sensu-server", | |
:ip => "10.10.99.60", | |
:box => "ubuntu/trusty64", | |
:ram => 2024, | |
:cpu => 4, | |
:provision => "provision-server.sh" | |
} | |
] | |
Vagrant.configure(2) do |config| | |
servers.each do |machine| | |
config.vm.define machine[:hostname] do |node| | |
node.vm.box = machine[:box] | |
node.vm.hostname = machine[:hostname] | |
node.vm.network "private_network", ip: machine[:ip] | |
if machine[:hostname] == "sensu-server" | |
node.vm.provision "file", source: "uchiwa-config.json", destination: "/home/vagrant/uchiwa-config.json" | |
else | |
node.vm.provision "file", source: "sensu-client.json", destination: "/home/vagrant/sensu-client.json" | |
node.vm.provision "file", source: "client-config.json", destination: "/home/vagrant/client-config.json" | |
end | |
node.vm.provision "shell", :path => machine[:provision] | |
node.vm.provider "virtualbox" do |vb| | |
vb.customize ["modifyvm", :id, "--memory", machine[:ram]] | |
end | |
end | |
end | |
end |
$ vagrant up
$ vagrant ssh sensu-server
$ vagrant ssh sensu-client
Go to http://10.10.99.60:3000/ Have Fun.
PS: If you have issues, do this:
vagrant ssh sensu-server sudo /etc/init.d/sensu-server restart sudo /etc/init.d/uchiwa restart
Cheers,
Diego Pacheco