At Agira, Technology Simplified, Innovation Delivered, and Empowering Business is what we are passionate about. We always strive to build solutions that boost your productivity.

How To Get Started With Sensu – A Full Stack Monitoring Tool

  • By Manigandan
  • April 27, 2018
  • 2506 Views

What Is Sensu?

Sensu is an open-source platform that provides the full-stack monitoring solution for your problems. Through Sensu you can progressively monitor your servers, services, application health, and business KPIs, etc. On the other hand, it can also collect and analyze custom metrics. And it can keep you updated when something happens, you will be notified through email or phone call (customized). Precisely you can do all these competitive monitoring analyses for your business with Sensu.
Steps are required to configure Sensu for Linux and Ubuntu platforms.

  • Sensu Installation and configuration
  • Install and Configure RabbitMQ
  • Install Redis server
  • Install and Configure Uchiwa Dashboard Setup
  • Installing & Configuring Plugins
  • Enabling Email Alerts Using Postfix

Sensu Installation and configuration

Before installing Sensu, it is recommended to update your system to the latest stable version.
You can use the below command to update your system

sudo apt-get update

Install and Configure RabbitMQ

RabbitMQ supports multiple messaging protocols. It can be deployed in distributed and federated configurations to meet high-scale availability.
The following command will add Erlang repository and will add Erlang public key to your trusted key list.
sudo wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb

sudo dpkg -i erlang-solutions_1.0_all.deb

sudo wget -O- https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | sudo apt-key add –
Next, update the repository with below command

sudo apt-get update

Once the repository is updated, install Erlang-nox

sudo apt-get install socat erlang-nox

Next, We need to download and install the latest version of RabbitMQ repository.
sudo wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server_3.6.10-1_all.deb

sudo dpkg -i rabbitmq-server_3.6.10-1_all.deb

Update the repository

sudo apt-get update

Finally, Install the RabbitMQ server using the following command

sudo apt-get install rabbitmq-server

After installing rabbitmq-server , Start the RabbitMQ service and enable it.

sudo systemctl start rabbitmq-server
sudo systemctl enable rabbitmq-server

Next, we need to create a RabbitMQ vhost and user for Sensu application.

sudo rabbitmqctl add_vhost /sensu
sudo rabbitmqctl add_user sensu password

Use the following command to provide the permission for users to access Sensu
sudo rabbitmqctl set_permissions -p /sensu sensu “.*” “.*” “.*”
[Related: Tips To Optimize Angular Application To Increase The Website Speed ]

Installing Redis Server

Once you are done with the RabbitMQ configuration, then start installing Redis server. Because Sensu uses Redis server to store their data.
Note:
Redis is an open-source, in-memory data structure store, used as a database, cache and message broker.
Install Redis Server with below command,

sudo apt-get install redis-server
sudo apt-get install apt-transport-https

Once the redis-server installation is complete, start the Redis server and enable it.

sudo systemctl start Redis-server
sudo systemctl enable Redis-server

Sensu Installation

First, add Sensu GPG key
sudo wget -O- https://sensu.global.ssl.fastly.net/apt/pubkey.gpg | sudo apt-key add –
Next, add the Sensu repository by creating sensu.list file inside /etc/apt/sources.list.d
sudo vi /etc/apt/sources.list.d/sensu.list
Then add the following line
deb https://sensu.global.ssl.fastly.net/apt sensu main
Next, update the repository

sudo apt-get update

Now, use the following command to install the Sensu

sudo apt-get install sensu

After installing Sensu, you will need to configure Sensu for RabbitMQ and Redis.
By default, Sensu will load configuration from /etc/sensu/conf.d/ directory.
Now copy and paste the below code to create a rabbitmq.json file inside the following directory /etc/sensu/conf.d
File path: sudo vi /etc/sensu/conf.d/rabbitmq.json

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

Next, create redis.json file with the following command
File path: sudo vi /etc/sensu/conf.d/redis.json

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

Next, create a api.json file to include the connection information for Sensu to access API
File path: sudo vi /etc/sensu/conf.d/api.json

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

Install and Configure the Uchiwa Dashboard

Basically Sensu does not come with the Dashboard to monitor Sensu through a web interface. So, we need to install an open-source Dashboard Uchiwa to your system.

  • Add the public key to the Uchiwa repository

sudo wget -O- https://sensu.global.ssl.fastly.net/apt/pubkey.gpg | sudo apt-key add –
File Path: /etc/apt/sources.list.d

sudo vi /etc/apt/sources.list.d/uchiwa.list

Add this repository to the uchiwa.list file.

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

Next, update the repository

sudo apt-get update

Once the system is updated, install Uchiwa

sudo apt-get install uchiwa

The following command used to the configuration file for the Uchiwa dashboard.
File path: sudo vi /etc/sensu/uchiwa.json

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

Next, configuration file for Uchiwa client
File path: /etc/sensu/conf.d/client.json

{
"client": {
"name": "sensu-server",
"address": "127.0.0.1",
"environment": "sensu",
"subscriptions": [ "linux"],
"keepalive":
{
"handler": "mailer",
"thresholds": {
"warning": 250,
"critical": 300
}
},
"socket": {
"bind": "127.0.0.1",
"port": 3030
}
}
}

Next, add transport file to the following location
File Path: sudo vi /etc/sensu/conf.d/transport.json

{
"transport":
{
"name": "rabbitmq",
"reconnect_on_error": true
}
}

Finally use the following command to restart & enable the Sensu and Uchiwa service.

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

Now you can monitor your Dashboard through access path : http://127.0.0.1:3001 or http://<yourpublicip>:<your givenpostnumber>

Plugin Installation & Configurations

Here i have explained the configuration process for primary plugins and you can also add more plugins if required,
Go to the following location and run the listed commands to install the plugins
cd /opt/sensu/embedded/bin/

sudo sensu-install -p cpu-checks
sudo sensu-install -p disk-checks
sudo sensu-install -p memory-checks
sudo sensu-install -p nginx
sudo sensu-install -p process-checks
sudo sensu-install -p load-checks
sudo sensu-install -p vmstats
sudo sensu-install -p mailer

Configuring CPU Check File
Copy and paste the below code to the specified path.
Configuration Path: Sudo vi /etc/sensu/conf.d/check_cpu.json

{
"checks": {
"check-cpu": {
"handlers": ["mailer"],
"command": "/opt/sensu/embedded/bin/check-cpu.rb -w 80 -c 90 ",
"interval": 60,
"occurrences": 5,
"subscribers": [ "linux" ]
}
}
}

Similarly, you can configure all the plugins as listed,

Configuring Memory Check File

Configuration Path: sudo vi /etc/sensu/conf.d/check_memory.json

{
"checks": {
"check_memory_linux": {
"handlers": ["mailer"],
"command": "/opt/sensu/embedded/bin/check-memory-percent.rb -w 90 -c 95",
"interval": 60,
"occurrences": 5,
"subscribers": [ "linux" ]
}
}
}

Configuring Disk Usage File

Configuration Path: sudo vi /etc/sensu/conf.d/check_disk_usage.json

{
"checks": {
"check-disk-usage-linux": {
"handlers": ["mailer"],
"command": "/opt/sensu/embedded/bin/check-disk-usage.rb -w 80 -c 90",
"interval": 60,
"occurrences": 5,
"subscribers": [ "linux" ]
}
}
}

Configuring Nginx Service File

Configuration Path: sudo vi /etc/sensu/conf.d/nginx_process.json

{
"checks": {
"check-process-nginx-master": {
"command"     : "/opt/sensu/embedded/bin/check-process.rb -p 'nginx: master process' -C 1",
"handlers"    : ["mailer"],
"interval"    :   60,
"standalone"  :   true
}
}
}

Enabling Email Alerts Using Postfix

Sudo apt-get install postfix

After installing and configuring postfix, include the following json handler files
sudo vi etc/sensu/conf.d/ handler_mail.json

{
"handlers": {
"mailer": {
"type": "pipe",
"command": "/opt/sensu/embedded/bin/handler-mailer.rb"
}
}
}
 
sudo vi /etc/sensu/conf.d/mailer.json
 
{
"mailer": {
"admin_gui": "http://localhost:3001/",
"mail_from": "from@domain.com”,
"mail_to": "to@domain.com",
"smtp_address": "localhost",
"smtp_port": "25",
"smtp_domain": "localhost"
}
}

Finally, Restart the services

sudo service sensu-server restart
sudo service sensu-client restart
sudo service uchiwa restart

Now you can monitor the Dashboard through the access path: http://127.0.0.1:3001 or http://<yourpublicip>:<your givenpostnumber>

Turn your vision to magnificent reality With
Our Web and Mobile Solutions

Manigandan

An ideal Full Stack Developer, having around 5+ years of experience in web development arena, expertise in AngularJS, Nodejs, PHP and also scoring 6 years of experience in Networking & Window servers. A perfect all-rounder has fondness to play diverse role. he always strives to match perfection and likely remains the best in whatever role he takes.