Are you looking for a scalable and secure monitoring solution for your technology and server infrastructure? Look no further than Sensu! Sensu is an open-source infrastructure and application monitoring system designed for container and non-container monitoring and multi-cloud infrastructure. With Sensu, you can monitor servers, application health, and services, and receive alert notifications to multiple targets with third-party integration.

In this tutorial, we will guide you through the process of installing Sensu Monitoring Solution on a Rocky Linux 9 server. We will also cover the installation and setup of Sensuctl, which allows you to manage Sensu via the command line terminal. Additionally, we will demonstrate how to install and configure Sensu Agent on both RHEL-based and Debian-based distributions. Finally, we will show you how to create system checks for monitoring servers via Sensu Agent.

Prerequisites

Before we begin, let’s ensure that you have the following requirements:

  • A Linux server with Rocky Linux 9.
  • A non-root user with sudo/root administrator privileges.
  • SELinux running in permissive mode.

For the purpose of this tutorial, we will be using the following servers:

Host

IP Address

Used as

sensu-rock

192.168.5.45

Sensu Go Backend

RPM-OS

192.168.5.80

Sensu Go Agent (RHEL-based)

DEB-OS

192.168.5.85

Sensu Go Agent (Debian-based)

Setting up the Repository

To begin the installation process, we first need to set up the repository. Follow the steps below:

Step 1: Enable Code Ready Builder (CRB) and EPEL repositories

Run the following command to enable the CRB repository and install the EPEL repository:

sudo dnf config-manager --set-enabled crb
sudo dnf install epel-release

Step 2: Add the Sensu repository

Next, add the Sensu repository to your Rocky Linux server by executing the following command:

curl -s https://packagecloud.io/install/repositories/sensu/stable/script.rpm.sh | sudo bash

Confirm that the Sensu repository has been added by running the following command:

sudo dnf repolist

You should see the crb,epel, and sensu_stable repositories listed.

Now that the repository setup is complete, let’s move on to installing the Sensu Go Backend.

Installing Sensu Go Backend

Sensu Go Backend is the main component of Sensu, powered by an embedded transport and etcd datastore. It provides a WebSocket for communication with Sensu Agents, an HTTP API for communication with Sensuctl, and a web UI dashboard accessible via a browser.

To install Sensu Go Backend, follow the steps below:

Step 1: Install Sensu Go Backend package

Enter the following command to install the sensu-go-backend package:

sudo dnf install sensu-go-backend

When prompted, enter y to confirm and press ENTER to proceed with the installation.

Step 2: Download the sample configuration file for Sensu Backend

Download the sample configuration file for Sensu Backend to /etc/sensu/backend.yml using the following command:

sudo curl -L https://docs.sensu.io/sensu-go/latest/files/backend.yml -o /etc/sensu/backend.yml

Open the downloaded file using the nano editor:

sudo nano /etc/sensu/backend.yml

Step 3: Configure Sensu Go Backend

Uncomment the following lines in the backend.yml file:

cache-dir: "/var/cache/sensu/sensu-backend"
config-file: "/etc/sensu/backend.yml"
log-level: "debug"
state-dir: "/var/lib/sensu/sensu-backend"

Save and close the file when you’re finished.

Step 4: Start and enable the Sensu Backend service

Start the Sensu Backend service by running the following command:

sudo systemctl start sensu-backend

Enable the service to start automatically at system startup:

sudo systemctl enable sensu-backend

To verify that the Sensu Backend service is running and enabled, use the following command:

sudo systemctl is-enabled sensu-backend
sudo systemctl status sensu-backend

Configuring Sensuctl Command Line

Sensuctl is a command line tool that allows you to manage Sensu instances. In this section, we will install Sensuctl and configure it to connect to the Sensu Backend server.

Step 1: Install Sensuctl

Install Sensuctl by running the following command:

sudo dnf install sensu-go-cli

Step 2: Verify Sensuctl installation

To verify that Sensuctl has been installed successfully, run the following commands:

which sensuctl
sensuctl --version

The output should display the path to the Sensuctl binary and the installed version, respectively.

Step 3: Configure Sensuctl connection to Sensu Backend

Configure the connection to your Sensu Backend server by running the following command:

sensuctl configure

You will be prompted to provide the following information:

  • Authentication method: username/password
  • Sensu Backend API URL: http://127.0.0.1:8080 (default)
  • Namespace: default
  • Preferred output format: json
  • Username: shapehost
  • Password: shapehost

To verify the connection details, use the following command:

sensuctl config view

This will display the connection details, confirming that Sensuctl is connected to the Sensu Backend via the HTTP API.

Step 4: Enable auto-completion for Sensuctl

To enable auto-completion for Sensuctl, install the bash-completion package by running the following command:

sudo dnf install bash-completion -y

Open the ~/.bashrc file using the nano editor:

sudo nano~/.bashrc

Add the following lines to enable bash completion for the root user:

if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

source <(sensuctl completion bash)

Save and exit the file.

Reload the ~/.bashrc file in your current session by running the following command:

source ~/.bashrc

To verify that the auto-completion is working, type sensuctl and press TAB. You should see a list of available options for the Sensuctl command.

Installing Sensu Agent

Sensu Agent is a lightweight client that runs on target servers to generate status and metrics, which are then sent to the Sensu Backend via WebSocket. In this section, we will install and set up Sensu Agent on both RHEL-based and Debian-based distributions.

Sensu Agent on RHEL-Based Distributions

If you are using a RHEL-based distribution, such as Rocky Linux, follow the steps below to install Sensu Agent:

Step 1: Open required ports

Before installing Sensu Agent, open the necessary ports on your firewall. Run the following commands:

sudo firewall-cmd --add-port={3030/tcp,3030/udp,3031/tcp,8125/udp} --permanent
sudo firewall-cmd --reload

Verify that the ports have been opened by running the following command:

sudo firewall-cmd --list-all

Step 2: Add Sensu repository and install Sensu Agent

Next, add the Sensu repository and install the Sensu Agent package by executing the following commands:

sudo dnf config-manager --set-enabled crb
sudo dnf install epel-release
curl -s https://packagecloud.io/install/repositories/sensu/stable/script.rpm.sh | sudo bash
sudo dnf install sensu-go-agent

Step 3: Configure Sensu Agent

Download the Sensu Agent configuration file to /etc/sensu/agent.yml:

sudo curl -L https://docs.sensu.io/sensu-go/latest/files/agent.yml -o/ etc/sensu/agent.yml

Open the configuration file using the nano editor:

sudo nano /etc/sensu/agent.yml

Uncomment the following lines and make the necessary changes:

name: "RPM-OS"
namespace: "default"
...
backend-url:
  - "ws://192.168.5.45:8081"
cache-dir: "/var/cache/sensu/sensu-agent"
config-file: "/etc/sensu/agent.yml"

Save the file and exit the editor.

Step 4: Start and enable Sensu Agent service

Start the Sensu Agent service by running the following command:

sudo systemctl start sensu-agent

Enable the service to start automatically at system startup:

sudo systemctl enable sensu-agent

To verify that the Sensu Agent service is running and enabled, use the following commands:

sudo systemctl is-enabled sensu-agent
sudo systemctl status sensu-agent

Sensu Agent on Debian-Based Distributions

If you are using a Debian-based distribution, such as Ubuntu, follow the steps below to install Sensu Agent:

Step 1: Open required ports

Before installing Sensu Agent, open the necessary ports on your firewall. Run the following commands:

sudo apt install ufw -y
sudo ufw allow OpenSSH
sudo ufw allow 3030/tcp
sudo ufw allow 3030/udp
sudo ufw allow 3031/tcp
sudo ufw allow 8125/udp
sudo ufw enable

Step 2: Add Sensu repository and install Sensu Agent

Next, add the Sensu repository and install the Sensu Agent package by executing the following commands:

sudo apt install debian-archive-keyring curl gnupg apt-transport-https -y
curl -s https://packagecloud.io/install/repositories/sensu/stable/script.deb.sh | sudo bash
sudo apt install sensu-go-agent

Step 3: Configure Sensu Agent

Download the Sensu Agent configuration file to /etc/sensu/agent.yml:

sudo curl -L https://docs.sensu.io/sensu-go/latest/files/agent.yml -o /etc/sensu/agent.yml

Open the configuration file using the nano editor:

sudo nano /etc/sensu/agent.yml

Uncomment the following lines and make the necessary changes:

name: "DEB-OS"
namespace: "default"
...
backend-url:
  - "ws://192.168.5.45:8081"
cache-dir: "/var/cache/sensu/sensu-agent"
config-file: "/etc/sensu/agent.yml"

Save the file and exit the editor.

Step 4: Start and enable Sensu Agent service

Start the Sensu Agent service by running the following command:

sudo systemctl start sensu-agent

Enable the service to start automatically at system startup:

sudo systemctl enable sensu-agent

To verify that the Sensu Agent service is running and enabled, use the following commands:

sudo systemctl is-enabled sensu-agent
sudo systemctl status sensu-agent

Verifying Agent via Sensu Go Backend and Sensuctl

Now that you have added the Sensu Agents to your monitoring solution, it’s time to verify their connection to the Sensu Go Backend.

Step 1: Verify via Sensu Go Backend Dashboard

Navigate to the Sensu Backend dashboard by opening your web browser and visiting the following URL: http://192.168.5.45:3000/.

Login with your username and password, and you should see the Sensu administration dashboard.

Click on the default namespace and you will find the entities RPM-OS and DEB-OS listed.

Step 2: Verify via Sensuctl Command Line

Back to the terminal, run the following command to verify the list of entities available on Sensu:

sensuctl entity list --format tabular

You should see the RPM-OS and DEB-OS entities listed.

With this verification, you have successfully added the Sensu Agents RPM-OS and DEB-OS to the Sensu Monitoring Solution.

Creating Checks for System Monitoring

With Sensu Agents connected to the Sensu Go Backend, you can now create checks to monitor various system metrics. In this section, we will guide you through creating checks for CPU usage, memory usage, and disk usage.

Step 1: Create a check for CPU usage

To create a check for CPU usage, run the following command:

sensuctl check create check_cpu \
--command 'check-cpu-usage -w 75 -c 90' \
--interval 60 \
--subscriptions system \
--runtime-assets sensu/check-cpu-usage

This command creates a check named check_cpu with the command check-cpu-usage -w 75 -c 90. The check will run every 60 seconds and is assigned to the system subscription. The sensu/check-cpu-usage asset is used to execute the check.

Step 2: Create a check for memory usage

To create a check for memory usage, run the following command:

sensuctl check create check_mem \
--command 'check-memory-usage -w 80 -c 90' \
--interval 60 \
--subscriptions system \
--runtime-assets sensu/check-memory-usage

This command creates a check named check_mem with the command check-memory-usage -w 80 -c 90. The check will run every 60 seconds and is assigned to the system subscription. The sensu/check-memory-usage asset is used to execute the check.

Step 3: Create a check for disk usage

To create a check for disk usage, run the following command:

sensuctl check create check_disk \
--command 'check-disk-usage --include-fs-type "xfs,ext4" --exclude-fs-path "/boot" --warning 90 --critical 95' \
--interval 60 \
--subscriptions system \
--runtime-assets sensu/check-disk-usage

This command creates a check named check_disk with the command check-disk-usage --include-fs-type "xfs,ext4" --exclude-fs-path "/boot" --warning 90 --critical 95. The check will run every 60 seconds and is assigned to the system subscription. The sensu/check-disk-usage asset is used to execute the check.

To verify the list of assets available on your Sensu Backend, run the following command:

sensuctl asset list --format tabular

You should see multiple assets that can be used to create checks for various system architectures.

To verify the list of checks you have created, run the following command:

sensuctl check list --format tabular

You should see the check_cpu,check_mem, and check_disk checks listed.

Apply System Checks to Monitor Agents/Hosts

Now that you have created the checks, it’s time to apply them to the entities RPM-OS and DEB-OS to monitor their metrics.

Step 1: Modify the entities

Run the following commands to modify the entities:

sensuctl entity update RPM-OS
sensuctl entity update DEB-OS

The entities should have the class agent and the subscription system.

Step 2: Verify the applied checks

Navigate back to the Sensu Backend dashboard and select the default namespace. Click on the Entities menu and you should see the system subscription added to both DEB-OS and RPM-OS.

Click on the DEB-OS entity to view the detailed monitoring information. You should see all the checks from the system subscription applied.

Repeat the same steps for the RPM-OS entity and verify that all the checks are applied.

With this, you have successfully applied the checks to your Sensu Agents RPM-OS and DEB-OS.

Conclusion

Congratulations! You have successfully installed Sensu Monitoring Solution on your Rocky Linux 9 server. You have also installed and configured Sensuctl to manage Sensu via the command line. Additionally, you have added Sensu Agents to both RHEL-based and Debian-based distributions and configured checks to monitor CPU usage, memory usage, and disk usage.

With Sensu, you can effectively monitor your infrastructure and receive notifications for any potential issues. If you need further assistance or want to explore more features of Sensu, refer to the official documentation.

Shape.host offers a reliable Cloud VPS hosting solution to ensure the smooth operation of your Sensu Monitoring Solution. Visit Shape.host to learn more about their services.