Install Sensu Agent on Rocky Linux

|
Last Updated:
|
|

This guide will take you through how to install Sensu agent on Rocky Linux systems. In order to start collecting remote system metrics for monitoring using Sensu Go server, you need to install Sensu agents on the hosts being monitored.

Install Sensu Agent on Rocky Linux

Install Sensu RPM repository;

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

Install Sensu Agent

Once the repository is installed, ran the command below to install Sensu agent;

sudo dnf install sensu-go-agent

Sample installation command output;

Dependencies resolved.
============================================================================================================================================================================
 Package                                     Architecture                        Version                                    Repository                                 Size
============================================================================================================================================================================
Installing:
 sensu-go-agent                              x86_64                              6.7.1-6231                                 sensu_stable                              6.6 M

Transaction Summary
============================================================================================================================================================================
Install  1 Package

Total download size: 6.6 M
Installed size: 19 M
Is this ok [y/N]: y
Downloading Packages:
sensu-go-agent-6.7.1-6231.x86_64.rpm                                                                                                        1.1 MB/s | 6.6 MB     00:06    
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                       1.1 MB/s | 6.6 MB     00:06     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Running scriptlet: sensu-go-agent-6.7.1-6231.x86_64                                                                                                                   1/1 
  Preparing        :                                                                                                                                                    1/1 
  Running scriptlet: sensu-go-agent-6.7.1-6231.x86_64                                                                                                                   1/1 
  Installing       : sensu-go-agent-6.7.1-6231.x86_64                                                                                                                   1/1 
  Running scriptlet: sensu-go-agent-6.7.1-6231.x86_64                                                                                                                   1/1 
  Verifying        : sensu-go-agent-6.7.1-6231.x86_64                                                                                                                   1/1 
Installed products updated.

Installed:
  sensu-go-agent-6.7.1-6231.x86_64                                                                                                                                          

Complete!

Configure and Run Sensu Agent

You can run Sensu agent with or without defining a configuration file.

To run without defining a configuration file on the foreground, use the command below

sudo -u sensu sensu-agent start --backend-url <sensu-server-web-socket-url>

Sensu backend web socket listens on port 8081. Ensure this port is opened on the Sensu backend server to allow agents to connect. The protocol is WS or WSS. (websocket on http/websocket on https)

sudo -u sensu sensu-agent start --backend-url ws://127.0.0.1:8081

or

sudo -u sensu sensu-agent start --backend-url ws://192.168.56.124:8081

Sample output;

{"component":"agent","level":"info","msg":"compacting api queue","time":"2022-05-07T02:42:24-04:00"}
{"component":"agent","level":"info","msg":"finished api queue compaction","time":"2022-05-07T02:42:24-04:00"}
{"component":"agent","level":"info","msg":"using password auth","time":"2022-05-07T02:42:24-04:00"}
{"component":"agent","level":"info","msg":"configuration successfully validated","time":"2022-05-07T02:42:24-04:00"}
{"component":"agent","level":"info","msg":"starting statsd server on address: 127.0.0.1:8125","time":"2022-05-07T02:42:24-04:00"}
{"component":"agent","level":"info","msg":"starting UDP listener on address: 127.0.0.1:3030","time":"2022-05-07T02:42:24-04:00"}
{"component":"agent","level":"info","msg":"starting api on address: 127.0.0.1:3031","time":"2022-05-07T02:42:24-04:00"}
{"component":"agent","event":{"Title":"Gostatsd started","Text":"Gostatsd started","DateHappened":1651905744,"Hostname":"localhost.localdomain","AggregationKey":"","SourceTypeName":"","Tags":null,"SourceIP":"","Priority":1,"AlertType":0},"level":"info","msg":"statsd received an event","time":"2022-05-07T02:42:24-04:00"}
{"component":"agent","level":"info","msg":"starting TCP listener on address: 127.0.0.1:3030","time":"2022-05-07T02:42:24-04:00"}
{"component":"agent","level":"info","msg":"connecting to backend URL \"ws://192.168.56.129:8081\"","time":"2022-05-07T02:42:24-04:00"}
{"component":"agent","level":"info","msg":"successfully connected","time":"2022-05-07T02:42:24-04:00"}
{"component":"agent","content_type":"application/octet-stream","level":"info","msg":"message received","payload_size":31,"time":"2022-05-07T02:42:25-04:00","type":"entity_config"}
{"check":"keepalive","component":"agent","entity":"localhost.localdomain","event_uuid":"48e54a4e-ddd6-4f0e-9f94-b78497385c28","level":"info","msg":"sending event to backend","time":"2022-05-07T02:42:25-04:00"}
{"component":"agent","content_type":"application/octet-stream","level":"info","msg":"message received","payload_size":169,"time":"2022-05-07T02:42:25-04:00","type":"entity_config"}
{"check":"keepalive","component":"agent","entity":"localhost.localdomain","event_uuid":"6d2b8024-bbfb-4f80-b1aa-252777e7daf7","level":"info","msg":"sending event to backend","time":"2022-05-07T02:42:45-04:00"}
...

To run Sensu agent as a service, you need a configuration file. Download and install the sample Sensu agent configuration file;

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

This is how sample config looks like;

---
# Sensu agent configuration


##
# agent configuration
##
#name: "hostname"
#namespace: "default"
#subscriptions:
#  - example
#labels:
#  example_key: "example value"
#annotations:
#  example/key: "example value"
#agent-managed-entity: false
#allow-list: /etc/sensu/check-allow-list.yaml
#assets-burst-limit: 100
#assets-rate-limit: 1.39
#backend-handshake-timeout: 15
#backend-heartbeat-interval: 30
#backend-heartbeat-timeout: 45
#backend-url:
#  - "ws://127.0.0.1:8081"
#cache-dir: "/var/cache/sensu/sensu-agent"
#config-file: "/etc/sensu/agent.yml"
#deregister: false
#deregistration-handler: "example_handler"
#detect-cloud-provider: false
#disable-assets: false
#keepalive-critical-timeout: 0
#keepalive-handlers:
#  - slack
#  - email
#keepalive-interval: 20
#keepalive-warning-timeout: 120
log-level: "debug" # available log levels: panic, fatal, error, warn, info, debug
#user: "agent"
#password: "P@ssw0rd!"
#redact:
#  - password
#  - passwd
#  - pass
#  - api_key
#  - api_token
#  - access_key
#  - secret_key
#  - private_key
#  - secret
#require-fips: false
#require-openssl: false


##
# api configuration
##
#api-host: "127.0.0.1"
#api-port: 3031
#disable-api: false
#events-burst-limit: 10
#events-rate-limit: 10.0


##
# socket configuration
##
#socket-host: "127.0.0.1"
#socket-port: 3030
#disable-sockets: false


##
# statsd configuration
##
#statsd-disable: false
#statsd-event-handlers:
#  - example_handler
#statsd-flush-interval: 10
#statsd-metrics-host: "127.0.0.1"
#statsd-metrics-port: 8125


##
# tls configuration
##
#cert-file: "/path/to/tls/agent.pem"
#trusted-ca-file: "/path/to/tls/ca.pem"
#key-file: "/path/to/tls/agent-key.pem"
#insecure-skip-tls-verify: false

The default Sensu backend URL is ws://127.0.0.1:8081.

If you are using a remove Sensu backend;

sudo vim /etc/sensu/agent.yml

update the backend url from;

#backend-url:
#  - "ws://127.0.0.1:8081"

To (replace <sensu-backend-IP> with Sensu backend IP address);

backend-url:
  - "ws://<sensu-backend-IP>:8081"

At the very least, Sensu agent just requires the backend url to be defined.

Next, start and enable the Sensu agent service to run on system boot;

sudo systemctl enable --now sensu-agent

Check the Status;

systemctl status sensu-agent
● sensu-agent.service - The Sensu Agent process.
     Loaded: loaded (/lib/systemd/system/sensu-agent.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-05-07 01:17:26 EAT; 3s ago
   Main PID: 4246 (sensu-agent)
      Tasks: 7 (limit: 1133)
     Memory: 8.3M
        CPU: 62ms
     CGroup: /system.slice/sensu-agent.service
             └─4246 /usr/sbin/sensu-agent start -c /etc/sensu/agent.yml

May 07 01:17:27 debian11 sensu-agent[4246]: {"component":"agent","header":"Accept: application/octet-stream","level":"debug","msg":"setting header","time":"2022-05-07T01:1>
May 07 01:17:28 debian11 sensu-agent[4246]: {"component":"agent","level":"info","msg":"successfully connected","time":"2022-05-07T01:17:28+03:00"}
May 07 01:17:28 debian11 sensu-agent[4246]: {"component":"agent","header":"Accept: [application/octet-stream application/json]","level":"debug","msg":"received header","ti>
May 07 01:17:28 debian11 sensu-agent[4246]: {"component":"agent","format":"protobuf","level":"debug","msg":"setting serialization/deserialization","time":"2022-05-07T01:17>
May 07 01:17:28 debian11 sensu-agent[4246]: {"component":"agent","header":"Content-Type: application/octet-stream","level":"debug","msg":"setting header","time":"2022-05-0>
May 07 01:17:28 debian11 sensu-agent[4246]: {"component":"agent","level":"debug","msg":"maxSessionLength is 0s, agent won't periodically disconnect","time":"2022-05-07T01:>
May 07 01:17:28 debian11 sensu-agent[4246]: {"component":"agent","content_type":"application/octet-stream","level":"info","msg":"message received","payload_size":143,"time>
May 07 01:17:28 debian11 sensu-agent[4246]: {"component":"agent","level":"debug","msg":"received an entity config from the backend","time":"2022-05-07T01:17:28+03:00"}
May 07 01:17:28 debian11 sensu-agent[4246]: {"component":"agent","level":"debug","msg":"successfully received the initial entity config","time":"2022-05-07T01:17:28+03:00"}
May 07 01:17:28 debian11 sensu-agent[4246]: {"check":"keepalive","component":"agent","entity":"debian11","event_uuid":"14a4c0f8-301c-4fe2-9db3-119c8a53274a","level":"info

In case of any issue, check the logs using journalctl command;

journalctl -u sensu-agent

Sensu Agents listens on ports 3030/tcp,udp for the Sensu agent socket and 3031/tcp for Sensu API;

ss -altnp | grep sensu
LISTEN 0      4096       127.0.0.1:3030      0.0.0.0:*    users:(("sensu-agent",pid=1180,fd=10))
LISTEN 0      4096       127.0.0.1:3031      0.0.0.0:*    users:(("sensu-agent",pid=1180,fd=12))

Very Sensu Agents Connectivity with Sensu Backend Server

Login back to Sensu backend and confirm the status of the agents.

sensu agent rocky

As you can see, we have two remote agents under the default entity. sensu-system entity is the Sensu backend itself.

Install Sensu Agent on Rocky Linux

You can click on any of the respective agent entities to view more details;

Install Sensu Agent on Rocky Linux

Sensu is now installed and running!

Next, follow the guide below to learn how to monitor Linux system metrics using Sensu.

How to Monitor Linux System Metrics using Sensu

Reference

Install Sensu

Other Tutorials;

Install Sensu Go on Ubuntu 22.04

Install Sensu Agent on Ubuntu/Debian

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment