Table of Contents | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Prerequisites
A running EC2 instance.
A running hivemq HiveMQ setup.
ssh SSH and sudo access to the ec2 EC2 instance.
Prometheus Setup
Install Prometheus on EC2 instance
SSH into your ec2 EC2 instance and switch to root user
Download Prometheus (e.g. wget …) and untar the file (tar -xzfv …)
Rename the unzipped folder. e.g.
mv prometheus-2.2250.01.linux-amd64 prometheus-files
Create a Prometheus user, and required directories, and make Prometheus the user as the owner of those directories.
Code Block sudo useradd --no-create-home --shell /bin/false prometheus sudo mkdir /etc/prometheus sudo mkdir /var/lib/prometheus sudo chown prometheus:prometheus /etc/prometheus sudo chown prometheus:prometheus /var/lib/prometheus
Copy prometheus and Copy Prometheus and promtool binary from prometheus-files folder to
/usr/local/bin
and change the ownership to prometheus user.
...
Move the consoles and console_libraries directories from prometheus-files to
/etc/
prometheus folderprometheus
folder and change the ownership to prometheus user.
...
Setup Prometheus Configuration
All the prometheus Prometheus configurations should be present in /etc/prometheus/prometheus.yml file.
...
Now you will be able to access the prometheus UI Prometheus UI on 9090 port of the prometheus serverPrometheus server.
Code Block |
---|
http://<ec2-auto-assigned-ip>:9090/graph |
In case of EC2, replace this IP with Auto-assigned IP address
Setup HiveMQ Prometheus
...
Extension
On your ec2 EC2 instance, go to your hivemq folder and cd into the extensions folder
Download and unzip the latest HiveMQ Prometheus extensionExtension. The default configuration is already set in
prometheusConfiguration.properties
. This usually does not need to be changedStart hivemq by executing
run.sh
under hivemq/bin folder(please make sure its it is executable (chmod +x run.sh)You can confirm if the extension worked well by:
checking hivemq Checking HiveMQ logs.
Go to
http://<ec2-auto-assigned-ip>/metrics
, it should show scrapped metrics page.
Connecting Prometheus to scrape HiveMQ Metrics
Access Your Prometheus Configuration File: Log into your EC2 instance where Prometheus is running. You'll typically find the
prometheus.yml
configuration file in the directory where you have Prometheus installed, or under/etc/prometheus/
if you used a package manager to install Prometheus.Edit the Configuration File: Open
prometheus.yml
in a text editor. You can use nano, vi, or any editor you're comfortable with. For example:Code Block sudo vi /etc/prometheus/prometheus.yml
Add a New Job to Scrape HiveMQ Metrics: In the
scrape_configs
section of the configuration file, add a new job to scrape metrics from the HiveMQ Prometheus operator. You'll specify the metrics path and the address of the server where HiveMQ is running. For example, we used ec2 EC2 IP and port 9399 for HiveMQ operator:job. Note that the default binding IP address can be0.0.0.0
Code Block scrape_configs: - job_name: 'hivemq' static_configs: - targets: ['<ec2-auto-assigned-ip>:9399'] metrics_path: '/metrics'
Save and Close the File: After adding the new job, save your changes and exit the text editor.
Reload Prometheus Configuration: Prometheus needs to reload its configuration to start scraping metrics from the new endpoint. You can do this by sending a
SIGHUP
signal to the Prometheus process. If you're using systemd, you can reload the Prometheus service using:Code Block sudo systemctl reload prometheus
If you're not using systemd, find the Prometheus process ID and send a
SIGHUP
signal to it:Code Block kill -HUP $(pidof prometheus)
Verify Configuration: After reloading the configuration, you can check that Prometheus is successfully scraping metrics from HiveMQ by accessing the Prometheus UI and navigating to the ‘Targets’ page.(
http://<ec2-auto-assigned-ip>/targets
) You should see your new job listed with a status indicating whether the scrape is successful.Going back to
http://<ec2-auto-assigned-ip>/graph
, you should be able to see HiveMQ metrics scrapped.
This concludes the tutorial. As the next steps, you can connect prometheus Prometheus to Grafana for better visualisation visualization and dashboards