Sensu is a versatile open-source infrastructure and application monitoring system designed to cater to both container and non-container monitoring needs in multi-cloud environments. With its scalability, security, and integration capabilities, Sensu provides a comprehensive monitoring solution for your technology and server infrastructure. It allows you to monitor servers, application health, and services, and send alert notifications to multiple targets through third-party integration. In this guide, we will take you through the step-by-step process of installing and configuring the Sensu Monitoring Solution on an Ubuntu 22.04 server. We will also show you how to set up the Sensu-go-client for managing Sensu and install the Sensu Agent on the target host for basic system monitoring.
Before we begin, please ensure that you have the following prerequisites:
- Two Ubuntu 22.04 servers – The first server will serve as the Sensu Server, while the second server will be the target server to monitor.
- A non-root user with sudo/root administrator privileges.
Let’s get started with the installation process.
Adding the Sensu Repository
Sensu provides its own repository for easy installation on various operating systems, including Linux, macOS, Windows, and FreeBSD. In this step, we will set up the Sensu repository on both the Sensu Server and the target monitoring system.
- Update the package index and install some basic packages to your system by running the following commands:
sudo apt update sudo apt install wget curl gnupg2 apt-transport-https
- Add the Sensu stable repository to your systems using the following command:
curl -s https://packagecloud.io/install/repositories/sensu/stable/script.deb.sh | sudo bash
Installing and Configuring Sensu Go Backend
The Sensu Go Backend is the main component of the Sensu Monitoring Platform. It provides a web administration dashboard, an HTTP API for managing Sensu via the command-line, and WebSockets for target machines/agents to connect.
- Install the Sensu Go Backend on the Sensu Server by running the following command:
sudo apt install sensu-go-backend
- Download the sample configuration file for the Sensu Go Backend by running the following commands:
sudo curl -L https://docs.sensu.io/sensu-go/latest/files/backend.yml -o /etc/sensu/backend.yml sudo nano /etc/sensu/backend.yml
- Uncomment the following lines in the 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 the file and exit the editor.
- Start and enable the Sensu Go Backend service by running the following commands:
sudo systemctl start sensu-backend sudo systemctl enable sensu-backend
- Verify the status of the Sensu Go Backend service by running the following command:
sudo systemctl is-enabled sensu-backend sudo systemctl status sensu-backend
Initializing the Sensu Go Backend
Now that the Sensu Go Backend is installed, we need to initialize it by setting up the admin password and generating some configurations.
- Set up the environment variables for the admin user and password by running the following commands:
export SENSU_BACKEND_CLUSTER_ADMIN_USERNAME=sensuadmin export SENSU_BACKEND_CLUSTER_ADMIN_PASSWORD=sensupassword
Note: Replace ‘sensuadmin’ with your desired admin username and ‘sensupassword’ with your desired admin password.
- Initialize the Sensu Go Backend installation by running the following command:
sensu-backend init
- Open a web browser and visit the server IP address followed by the TCP port 3000 (e.g., http://192.168.5.100:3000). You should see the Sensu login page.
- Log in with the username and password you set during the initialization process and click ‘SIGN-IN’.
- After logging in, you will be directed to the Sensu administration dashboard, indicating that the Sensu Go Backend installation is complete.
Installing and Configuring sensuctl
Now that the Sensu Go Backend is installed and configured, we can proceed to install the Sensu Go Client, also known as ‘sensuctl’, on the Sensu Server. Sensuctl is a command-line utility that allows you to manage Sensu via the terminal server.
- Install the Sensu Go Client by running the following command:
sudo apt install sensu-go-cli
- Open the ‘~/.bashrc’ file using the following command:
nano ~/.bashrc
- Add the following lines to the bottom of the file to enable auto-complete for the ‘sensuctl’ command:
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 the file and exit the editor.
- Reload your current session by running the following command:
source ~/.bashrc
- Verify that the ‘sensuctl’ command auto-complete is working by typing ‘sensuctl’ and pressing the TAB key. You should see a list of available options for the command.
- Configure the connection to the Sensu Server by running the following command:
sudo sensuctl configure
- Follow the prompts to provide the necessary configurations, including authentication method, Sensu Backend API URL, namespace, preferred output format, username, and password.
- Verify the current configuration by running the following command:
sudo sensuctl config view
Installing Sensu Agent on the Target Machine
The Sensu Agent is a lightweight client that runs on the target machines you want to monitor. It communicates with the Sensu Server via WebSockets, enabling features such as self-registration, sending keepalive messages, and executing monitoring checks.
Before proceeding, ensure that you have added the Sensu repository and run the following commands on the target machine (in this example, the server is named ‘machine1’).
- Install the Sensu Agent by running the following command:
sudo apt install sensu-go-agent
- Download the configuration file for the Sensu Agent by running the following commands:
sudo curl -L https://docs.sensu.io/sensu-go/latest/files/agent.yml -o /etc/sensu/agent.yml sudo nano /etc/sensu/agent.yml
- Modify the default configuration with the following lines, replacing ‘machine1’ with the hostname of the target machine and ‘192.168.5.100’ with the IP address of the Sensu Server:
name: "machine1" namespace: "default" ... backend-url: - "ws://192.168.5.100:8081" cache-dir: "/var/cache/sensu/sensu-agent" config-file: "/etc/sensu/agent.yml"
- Save the file and exit the editor.
- Start and enable the ‘sensu-agent’ service by running the following commands:
sudo systemctl start sensu-agent sudo systemctl enable sensu-agent
- Verify the status of the ‘sensu-agent’ service by running the following command:
sudo systemctl is-enabled sensu-agent sudo systemctl status sensu-agent
- Switch back to the Sensu Server terminal and verify that the target machine ‘machine1’ is available by running the following ‘sensuctl’ command:
sensuctl entity list --format tabular
Setting up Checks for Monitoring System
In Sensu, checks define what you want to monitor, such as CPU usage, memory usage, disk usage, and more. Checks are part of the Assets, which are shareable and reusable runtime environments. In this step, we will create checks for monitoring CPU usage, memory usage, and disk usage on the target machine ‘machine1’.
- Update the entity or target machine ‘machine1’ by running the following ‘sensuctl’ command:
sensuctl entity update machine1
- Add the necessary assets to your Sensu Server by running the following ‘sensuctl’ commands:
sensuctl asset add sensu/check-cpu-usage sensuctl asset add sensu/check-memory-usage sensuctl asset add sensu/check-disk-usage
- Verify the list of assets on the Sensu Server by running the following ‘sensuctl’ command:
sensuctl asset list
- Create a check named ‘check_cpu’ for monitoring CPU usage by running the following ‘sensuctl’ command. Adjust the settings in the ‘command’ option as needed:
sensuctl check create check_cpu --command'check-cpu-usage -w 75 -c 90' --interval 60 --subscriptions system --runtime-assets sensu/check-cpu-usage
- Create a check named ‘check_mem’ for monitoring memory usage by running the following ‘sensuctl’ command. Adjust the settings in the ‘command’ option as needed:
sensuctl check create check_mem --command 'check-memory-usage -w 80 -c 90' --interval 60 --subscriptions system --runtime-assets sensu/check-memory-usage
- Create a check named ‘check_disk’ for monitoring disk usage by running the following ‘sensuctl’ command. Adjust the settings in the ‘command’ option as needed:
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
- Verify the list of checks on the Sensu Server by running the following ‘sensuctl’ command:
sensuctl check list
- Go back to the Sensu administration dashboard in your web browser. Ensure that you are in the ‘default’ namespace and click on ‘Entities’. You should see the target machine ‘machine1’ listed with a status of OK.
- Click on ‘machine1’ to view the details of the monitoring. You should see all the checks you created being executed and running.
Congratulations! You have successfully installed and configured the Sensu Monitoring Solution on your Ubuntu 22.04 Server. You have also learned the basic usage of the Sensuctl command for managing the Sensu backend and monitored a Linux host machine using the Sensu Agent. Additionally, you have set up assets and checks for system monitoring on the Sensu Server.
For more information about cloud hosting solutions and Cloud VPS services, visit Shape.host. Shape.host offers reliable, efficient, and scalable cloud hosting solutions to empower your business.