Monitoring: How To Install Sensu on Ubuntu 16.04 Server

Sensu Monitoring Logo

Introduction – Sensu Monitoring

Sensu is a free and open source tool for composing a monitoring system. It is entirely written in Ruby. It uses RabbitMQ to handle messages and Redis to store its data.
Sensu focuses on composability and extensibility, allowing to reuse monitoring checks and plugins from tools like Nagios and Zabbix.
This framework was designed to work with software like Puppet, Chef and Ansible, and it does not required additional workflow.
As stated in the documentation, “all versions of Sensu (including Sensu Enterprise) are based on the same core components and functionality, which are provided by the Sensu open-source software project and collectively referred to as Sensu Core. Sensu Core provides multiple processes, including the Sensu server (sensu-server), Sensu API (sensu-api), and Sensu client (sensu-client).

Installer packages are available for most modern operating systems via native installer packages (e.g. .deb, .rpm, .msi, .pkg, etc) which are available for download from the Sensu website, and from package manager repositories for APT (for Ubuntu/Debian systems), and YUM (for RHEL/CentOS).”

In this tutorial we will show how to install Sensu on an Ubuntu 16.04 server.

Install RabbitMQ

RabbitMQ runs on top of Erlang, so, first of all, we will install Erlang in our server.

Erlang is not available in Ubuntu repositories, but provides its own. Let’s add it and the Erlang public key to the trusted key list, by executing the following command:

$ wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
# dpkg -i erlang-solutions_1.0_all.deb
$ wget -O- https://packages.erlang-solutions.com/ubuntuerlang_solutions.asc | sudo apt-key add -

Next, update the repositories list with the following

apt

command:

# apt-get update -y

Once

apt

has updated its list, it is possible to install Erlang by executing the following command:

# apt-get install socat erlang-nox

At this point, we can download and install RabbitMQ. As we have done for Erlang, first of all it is required to add the RabbitMQ repository:

$ wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server_3.6.10-1_all.deb
# dpkg -i rabbitmq-server_3.6.10-1_all.deb

Update the repositories list with the following command:

# apt-get update

Finally, we can install RabbitMQ server with the following

apt

command:

# apt-get install rabbitmq-server

Once the installation is complete, start RabbitMQ and enable it to start at boot time. Execute the commands:

# systemctl start rabbitmq-server
# systemctl enable rabbitmq-server

Create vhost and User for Sensu

Next, we need to create a RabbitMQ

vhost

and user for Sensu. You can do this by running the following command:

# rabbitmqctl add_vhost /sensu
# rabbitmqctl add_user sensu your-password
# rabbitmqctl set_permissions -p /sensu sensu ".*" ".*" ".*"

At this point, we can install the Redis server.

Install Redis Server

As anticipated in the introduction, Sensu uses Redis server to store data.
By default, Redis is available in Ubuntu repository, so we can install it by executing the following command:

# apt-get install redis-server apt-transport-https -y

Once the installation is complete, we can start Redis and enable it to start at boot time:

# systemctl start redis-server
# systemctl enable redis-server

Install and Configure Sensu

The next step is to install Sensu. It is not available in Ubuntu repositories, but, as we said in the introduction, the project provides its own repository for Ubuntu. Add Sensu public key and repository to

apt

repositories list.

First of all, add the key, by executing the following

gpg

command:

$ wget -q https://sensu.global.ssl.fastly.net/apt/pubkey.gpg -O- | sudo apt-key add -

Next, we need to add the Sensu repository. Create a

sensu.list

file in

/etc/apt/sources.list.d

directory:

# $EDITOR /etc/apt/sources.list.d/sensu.list

In this file, paste the following content:

deb https://sensu.global.ssl.fastly.net/apt xenial main

Save and exit. Update the repositories list:

# apt-get update

Finally, install Sensu:

# apt-get install sensu

Configure Sensu

Once the installation is finished, we need to configure Sensu for using with RabbitMQ and Redis. By default, Sensu will load configuration from

/etc/sensu/conf.d/

directory. This is where we will create the RabbitMQ, Redis, and Api configuration files.

For the RabbitMQ part, create a

rabbitmq.json

file in

/etc/sensu/conf.d

:

# $EDITOR /etc/sensu/conf.d/rabbitmq.json

To connect Sensu to RabbitMQ, paste the following content in the opened file:

{
 "rabbitmq": {
     "host": "127.0.0.1",
     "port": 5672,
     "vhost": "/sensu",
     "user": "sensu",
     "password": "your-password"
   }
}

Save and exit.

Next, in the same way, create the

redis.json

file:

# $EDITOR /etc/sensu/conf.d/redis.json

There, paste the following content:

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

Save and exit

Next, create the

api.json

file:

# nano /etc/sensu/conf.d/api.json

Paste the following lines:

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

Save and exit.

Install and Configure Uchiwa Dashboard

By default, after the installation Sensu does not provide the Dashboard to monitor Sensu through a user-friendly web interface.

The framework was originally designed as an API-based monitoring solution, enabling operations teams to compose monitoring solutions where Sensu provides the monitoring instrumentation, collection of telemetry data, scalable event processing, comprehensive APIs and plugins for sending data to dedicated dashboard solutions. However, as the project matured, it was natural to work on a monitoring interface. As a result, today there are two dashboards: Uchiwa (for Sensu Core users), and the Sensu Enterprise Dashboard (for Sensu Enterprise customers).
In this tutorial, we will install the Uchiwa Dashboard.

First, add the public key by executing the following command:

$ wget -q https://sensu.global.ssl.fastly.net/apt/pubkey.gpg -O- | sudo apt-key add -

Next, add a Uchiwa repository by creating the

uchiwa.list

file inside the

/etc/apt/sources.list.d

directory:

# $EDITOR /etc/apt/sources.list.d/uchiwa.list

Here, paste:

deb https://sensu.global.ssl.fastly.net/apt xenial main

Save and exit.
Next, update the repositories list with the following command:

# apt-get update

Once

apt

has updated its repositories list, we can install Uchiwa by executing the following command:

# apt-get install uchiwa

Configure Uchiwa

Once the installation is finished, create a configuration file for Uchiwa:


# nano /etc/sensu/conf.d/uchiwa.json

Here, paste the following content:


{"sensu": [
    { "name": "Sensu",
      "host": "localhost",
      "port": 4567, "timeout": 10
    }
  ],
  "uchiwa": {
      "host": "0.0.0.0",
      "port": 3000,
      "refresh": 10
      }
}

Save and exit.

Finally, restart Sensu and Uchiwa and enable them to start at boot time:

# systemctl start sensu-server
# systemctl enable sensu-server
# systemctl start sensu-api
# systemctl enable sensu-api
# systemctl start sensu-client
# systemctl enable sensu-client
# systemctl start uchiwa
# systemctl enable uchiwa

Configure UFW Firewall

Uchiwa listens on port 3000, so we need to allow it through the UFW firewall. Execute the following command:

# ufw allow 3000

Conclusion

This concludes the tutorial. We have seen how to install and configure Sensu and the Uchiwa Dashboard  on a server running Ubuntu 16.04.