4x Affordable, 99.95% SLA, 24x& Video Support, 100+ Countires

Configure Sensu Monitoring Rabbitmq And Redis On Ubuntu 14 04

Introduction

Sensu is a monitoring equipment written in Ruby that uses RabbitMQ as a communication broker and Redis for storing data. It is well-suited for monitoring cloud environments.

Sensu connects the production from "check" scripts with "handler" scripts to create a robust monitoring and alert system. check scripts can run on many nodes, and report on whether a definite condition is met, such as that Apache is running. Handler scripts can take an action like sending an alert email.

Both the "check" scripts and the "handler" scripts run on the Sensu master server, which is accountable for scoring check actions among Sensu client servers and processing check results. If a check triggers an event, it is passed to the handler, which will take a selected action.

an instance of this is a check that monitors the states of an apache web server. The check will be run on the Sensu cases. If the check reports a server as down, the Sensu server will pass the event to the handler, which can trigger an action like sending an email or gathering downtime metrics.

In this tutorial we will be installing and configuring one Sensu master server and one Sensu client server.

Prerequisites

In order to set up Sensu, you will need:

  • One master node machine running Ubuntu 14.04. This is the node you will use to view all of the monitoring data.
  • At least one more node that you want to observe, running Ubuntu 14.04.

Create a sudo user on each machine. First, create the user with the adduser regulate, replacing the username with the name you want to use.

adduser username

This will create the user and the befitting environment directory and team. You will be prompted to set a password for the brand-new user and confirm the password. You will also be prompted to enter the user's information. Confirm the user information to create the user.

Next, grant the user sudo rights with the visudo regulate.

visudo

This will ajar the /etc/sudoers register. In the User right specification part add another line for the created user so it looks like this (with your specified username instead of username):

# User right specification
root ALL=(ALL:ALL) ALL
username ALL=(ALL:ALL) ALL

Save the register and switch to the brand-new user.

su - username

modify the system packages and enhance them.

sudo apt-get update && sudo apt-get -y upgrade

Step One Installation on the Master

First, we will set up the Sensu master server. This requires RabbitMQ, Redis, Sensu itself, and the Uchiwa dashboard, along with some aiding program.

Add the RabbitMQ source to the APT source database.

echo "deb http://www.rabbitmq.com/debian/ testing main" | sudo tee -a /etc/apt/sources.list.d/rabbitmq.list

Download and add the signing important for RabbitMQ.

curl -L -o ~/rabbitmq-signing-key-public.asc http://www.rabbitmq.com/rabbitmq-signing-key-public.asc

sudo apt-key add ~/rabbitmq-signing-key-public.asc

Install RabbitMQ and Erlang.

sudo apt-get update && sudo apt-get install -y rabbitmq-server erlang-nox

The RabbitMQ service should start automatically. If it doesn't, start it with the following regulate.

sudo service rabbitmq-server start

Sensu uses SSL for obtain communication between its elements and RabbitMQ. Although it is feasible to use Sensu without SSL, it is highly discouraged. To generate certificates, download Sensu's certificate generator to the /tmp directory and generate the SSL certificates.

cd /tmp && wget http://sensuapp.org/docs/0.13/tools/ssl_certs.tar && tar -xvf ssl_certs.tar

cd ssl_certs && ./ssl_certs.sh generate

Create a rabbitmq SSL directory and copy over the certificates.

sudo mkdir -p /etc/rabbitmq/ssl && sudo cp /tmp/ssl_certs/sensu_ca/cacert.pem /tmp/ssl_certs/server/cert.pem /tmp/ssl_certs/server/key.pem /etc/rabbitmq/ssl

Create and edit the /etc/rabbitmq/rabbitmq.config register.

sudo vi /etc/rabbitmq/rabbitmq.config

Add the following lines to the register. This configures the RabbitMQ SSL listener to listen on port 5671 and to use the generated certificate authority and server certificate. It will also verify the connection and fail if there is no certificate.

[
    {rabbit, [
    {ssl_listeners, [5671]},
    {ssl_options, [{cacertfile,"/etc/rabbitmq/ssl/cacert.pem"},
                   {certfile,"/etc/rabbitmq/ssl/cert.pem"},
                   {keyfile,"/etc/rabbitmq/ssl/key.pem"},
                   {verify,verify_peer},
                   {fail_if_no_peer_cert,true}]}
  ]}
].

Restart RabbitMQ.

sudo service rabbitmq-server restart

Create a rabbitmq realistic host and user for Sensu. action the password (pass). You'll need this password later when you configure the Sensu server and the cases to be observed .

sudo rabbitmqctl add_vhost /sensu
sudo rabbitmqctl add_user sensu pass
sudo rabbitmqctl set_permissions -p /sensu sensu ".*" ".*" ".*"

Install Redis.

sudo apt-get -y install redis-server

The Redis service should start automatically. If it doesn't, start it with the following regulate. (Note that if Redis is already running you will receive the error: "Starting redis-server: failed.")

sudo service redis-server start

Add the sources and keys to install Sensu.

wget -q http://repos.sensuapp.org/apt/pubkey.gpg -O- | sudo apt-key add -

echo "deb     http://repos.sensuapp.org/apt sensu main" | sudo tee -a /etc/apt/sources.list.d/sensu.list

Install Sensu and Uchiwa (Uchiwa is the monitoring dashboard).

sudo apt-get update && sudo apt-get install -y sensu uchiwa

Sensu needs the obtain connection information to RabbitMQ. Make a ssl directory for Sensu and copy over the generated certs.

sudo mkdir -p /etc/sensu/ssl && sudo cp /tmp/ssl_certs/client/cert.pem /tmp/ssl_certs/client/key.pem /etc/sensu/ssl

Now all of the elements for Sensu monitoring are installed.

Step Two Configuration on the Master

Now we need to configure Sensu. We'll create solo configuration records in the /etc/sensu/conf.d folder for easier readability and management. Unless you've configured the services and components mentioned in the config files on separate machines, you can leave most sample values shown below unchanged. Alternately, /etc/sensu/config.json.example<^> is another example configuration file you can copy and use to configure Sensu.

Create and edit the rabbitmq.json register.

sudo vi /etc/sensu/conf.d/rabbitmq.json

Add the following lines, which will allow Redis to connect securely to the RabbitMQ example using your SSL certificate. The user and pass should be the units you set for the RabbitMQ realistic host.

{
  "rabbitmq": {
    "ssl": {
      "cert_chain_file": "/etc/sensu/ssl/cert.pem",
      "private_key_file": "/etc/sensu/ssl/key.pem"
    },
    "host": "localhost",
    "port": 5671,
    "vhost": "/sensu",
    "user": "sensu",
    "password": "pass"
  }
}

Create and edit the redis.json register.

sudo vi /etc/sensu/conf.d/redis.json

Add the following lines, which include the connection information for Sensu to accesses the Redis example.

{
  "redis": {
    "host": "localhost",
    "port": 6379
  }
}

Create and edit the api.json register.

sudo vi /etc/sensu/conf.d/api.json

Add the following lines, which include the connection information for Sensu to accesses the API service.

{
  "api": {
    "host": "localhost",
    "port": 4567
  }
}

Create and edit the uchiwa.json register.

sudo vi /etc/sensu/conf.d/uchiwa.json

Add the following lines. These include the connection information for the Uchiwa dashboard to accesses the Sensu API. You can optionally create an username and password in the uchiwa block for dashboard authentication. If you want the dashboard to be publicly accessible, just leave it as is.

{
    "sensu": [
        {
            "name": "Sensu",
            "host": "localhost",
            "ssl": false,
            "port": 4567,
            "path": "",
            "timeout": 5000
        }
    ],
    "uchiwa": {
        "port": 3000,
        "stats": 10,
        "refresh": 10000
    }
}

In this instance, we'll have the Sensu master server observe itself as a client. So, create and edit the client.json register.

sudo vi /etc/sensu/conf.d/client.json

Add the following lines and edit the name ideal for the Sensu client. This is the name for the server that you will see in the Uchiwa dashboard. The name cannot have spaces or distinctive characters.

You can leave the addresseses ideal as localhost since we are monitoring this server. We will be creating an akin register again later for every client host to be observed .

{
  "client": {
    "name": "server",
    "addresseses": "localhost",
    "subscriptions": [ "ALL" ]
  }
}

Enable the Sensu services to start automatically.

sudo update-rc.d sensu-server defaults
sudo update-rc.d sensu-client defaults
sudo update-rc.d sensu-api defaults
sudo update-rc.d uchiwa defaults

Start the Sensu services.

sudo service sensu-server start
sudo service sensu-client start
sudo service sensu-api start
sudo service uchiwa start

At this point, you can accesses Sensu at http://ip-addresseses:3000.

Sensu default dashboard

Step Three Installation on the Client

You will need to install Sensu on every client device to be observed .

While still on the Sensu master server, copy the SSL certificates to the client server's /tmp covering using SCP. Replace user and IP below with the sudo user and IP addresseses of the client server.

scp /tmp/ssl_certs/client/cert.pem /tmp/ssl_certs/client/key.pem user@ip:/tmp

On the client to be observed , add the Sensu important and source.

wget -q http://repos.sensuapp.org/apt/pubkey.gpg -O- | sudo apt-key add -
echo "deb     http://repos.sensuapp.org/apt sensu main" | sudo tee -a /etc/apt/sources.list.d/sensu.list

Install Sensu.

sudo apt-get update && sudo apt-get -y install sensu

You need to give the client with connection information to RabbitMQ. Make a ssl directory for Sensu and copy the certificates in the /tmp covering that were written from the Sensu master server.

sudo mkdir -p /etc/sensu/ssl && sudo cp /tmp/cert.pem /tmp/key.pem /etc/sensu/ssl

Create and edit the rabbitmq.json register.

sudo vi /etc/sensu/conf.d/rabbitmq.json

Add the following lines. Edit the host value to use the IP addresseses of the RabbitMQ server; that is, the IP addresseses of the Sensu master server. The user and password belief Synonyms/Hypernyms should be the units you set for the RabbitMQ realistic host on the Sensu master server.

{
  "rabbitmq": {
    "ssl": {
      "cert_chain_file": "/etc/sensu/ssl/cert.pem",
      "private_key_file": "/etc/sensu/ssl/key.pem"
    },
    "host": "1.1.1.1",
    "port": 5671,
    "vhost": "/sensu",
    "user": "sensu",
    "password": "pass"
  }
}

give configuration information for this Sensu server by creating and editing the client.json register.

sudo vi /etc/sensu/conf.d/client.json

Add the following lines. You should edit the name ideal to what you want this server to be labelled in the Uchiwa dashboard. The name cannot have spaces or distinctive characters.

You can leave the addresseses ideal set to localhost, since we are monitoring this Sensu client server.

{
  "client": {
    "name": "client1",
    "addresseses": "localhost",
    "subscriptions": [ "ALL" ]
  }
}

Enable and start the client.

sudo update-rc.d sensu-client defaults

sudo service sensu-client start

You should now see the client on the cases tab on the Sensu Dashboard.

Step Four Set Up a Check

Now that Sensu is running we need to add a check on both servers. We're going to create a ruby script that will check if Apache is running.

If you don't have Apache installed, install it now on both the Sensu master server and the Sensu client server.

sudo apt-get install -y apache2

Apache should be running by failure on both servers.

Before installing the sensu-plugin gem, make convinced you have all the demanded libraries. Install the Ruby libraries and the build-essential library on both the Sensu master server and the Sensu client server.

sudo apt-get install -y ruby ruby-dev build-essential

Install the sensu-plugin gem on both the Sensu master server and the Sensu client server.

sudo gem install sensu-plugin

Create a check-apache.rb register in the Sensu plugins covering and adjust the register permissions on both the Sensu master server and the Sensu client server.

sudo touch /etc/sensu/plugins/check-apache.rb && sudo chmod 755 /etc/sensu/plugins/check-apache.rb

Edit the check-apache.rb register on both the Sensu master server and the Sensu client server.

sudo vi /etc/sensu/plugins/check-apache.rb

Add the following lines, which script the processes of checking Apache.

#!/usr/bin/env ruby

procs = `ps aux`
running = false
procs.each_line do |proc|
  running = true if proc.include?('apache2')
end
if running
  puts 'OK - Apache daemon is running'
  exit 0
else
  puts 'WARNING - Apache daemon is NOT running'
  exit 1
end

Create and edit the check_apache.json register on only the Sensu master server.

sudo vi /etc/sensu/conf.d/check_apache.json

Add the following lines that will run the script to check Apache every 60 seconds.

{
  "checks": {
    "apache_check": {
      "command": "/etc/sensu/plugins/check-apache.rb",
      "interval": 60,
      "subscribers": [ "ALL" ]
    }
  }
}

Restart the Sensu server and API on the Sensu master server.

sudo service sensu-server restart && sudo service sensu-api restart

Restart the Sensu client on the Sensu client server.

sudo service sensu-client restart

After a few minutes, you should see the check be on the "Checks" tab in the Sensu Dashboard.

Stop the Apache service on either server to try-out that the script is working.

sudo service apache2 stop

an alert should show up on the Events dashboard after a few minutes. depression on the alert to view more information and to take action such as silencing or resolving it.

In this illustration, Apache has been stopped on the client server. This is the cases page.

Sensu dashboard clients

Start the Apache service to stop the warnings.

sudo service apache2 start

Step Five Set Up a Handler

trainers can send notification emails or send data to other applications like Graphite based on events. Here, we will create a handler that sends an email if the Apache check fails. Please note that your server needs to be configured to send email. You can use this affix Tutorial to set up an easy mail server. (You may want to have mail sent to an user on the Sensu master server for the uncomplicated configuration.)

On the Sensu master server, create and edit the handler_email.json register.

sudo vi /etc/sensu/conf.d/handler_email.json

Add the following lines, replacing [email protected] with the email addresseses where you want to receive notifications. Depending on your mail server setup, it may be easiest to set this to an alias for a user on the Sensu master server. This handler is called "email" and will use the mail utility to send an alert email with the subject "sensu event" to the specified email addresseses.

{
  "trainers": {
    "email": {
      "type": "pipe",
      "command": "mail -s 'sensu event' [email protected]"
    }
  }
}

Edit the check_apache.json.

sudo vi /etc/sensu/conf.d/check_apache.json

Add the brand-new trainers line with the email handler in the apache_check block.


{
  "checks": {
    "apache_check": {
      "command": "/etc/sensu/plugins/check-apache.rb",
      "interval": 60,
      "trainers": ["default", "email"],
      "subscribers": [ "ALL" ]
    }
  }
}

Restart sensu-api and sensu-server.

sudo service sensu-api restart && sudo service sensu-server restart

Stop the Apache service again to try-out the email alert. You should get one every 60 seconds.

sudo service apache2 stop

Your email should look somewhat like the following:

Return-Path: <[email protected]>
...
Subject: sensu event
To: <[email protected]>
...
From: [email protected] (Sensu Monitoring Framework)

{"id":"481c85c4-485d-4f25-b835-cea5aef02c69","client":{"name":"Sensu-Master-Server","addresseses":"localhost","subscriptions":["ALL"],"version":"0.13.1","timestamp":1411681990},"check":{"command":"/etc/sensu/plugins/check-apache.rb","interval":60,"trainers":["default","email"],"subscribers":["ALL"],"name":"apache_check","issued":1411682001,"executed":1411682001,"duration":0.023,"output":"WARNING - Apache daemon is NOT running\n","status":1,"history":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","1"]},"occurrences":1,"action":"create"}

Start the Apache service again to stop collecting email alerts.

sudo service apache2 start

Conclusion

Sensu is a versatile monitoring tool with its plugins and the custom scripts you can write for it. You can also create trainers to do almost anything with the data. Keep exploring to get it just right for you.

Reference: digitalocean