Server monitoring is a critical aspect of managing a robust infrastructure. In this comprehensive guide, we'll explore how to set up an efficient and versatile monitoring system for Linux servers using Node Exporter, Prometheus, and Grafana. This combination of tools allows you to collect, store, and visualize performance metrics, providing valuable insights into your server's health and performance.
Article By Noble Mutuwa Mulaudzi
Architecture diagram
Prerequisites
Before we dive into the setup, here are the prerequisites you'll need:
An AWS EC2 instance running a Linux distribution (e.g., Ubuntu).
SSH access to the instance.
Basic knowledge of Linux command-line operations.
Step 1: Install Node Exporter
Node Exporter is a tool for collecting system-level metrics. Here's how to install it:
- Download and install Node Exporter:
wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
tar xvfz node_exporter-1.2.2.linux-amd64.tar.gz
sudo mv node_exporter-1.2.2.linux-amd64/node_exporter /usr/local/bin/
- Create a systemd service unit file for Node Exporter:
sudo nano /etc/systemd/system/node_exporter.service
Add the following content to the file:
[Unit]
Description=Node Exporter
After=network.target
[Service]
ExecStart=/usr/local/bin/node_exporter
Restart=always
[Install]
WantedBy=multi-user.target
- Reload systemd and start Node Exporter:
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
Step 2: Install Prometheus
Prometheus is a monitoring and alerting system. Here's how to install it:
- Download and install Prometheus:
wget https://github.com/prometheus/prometheus/releases/download/v2.30.2/prometheus-2.30.2.linux-amd64.tar.gz
tar xvfz prometheus-2.30.2.linux-amd64.tar.gz
sudo mv prometheus-2.30.2.linux-amd64/prometheus /usr/local/bin/
sudo mv prometheus-2.30.2.linux-amd64/promtool /usr/local/bin/
- Create a Prometheus configuration file:
sudo nano /etc/prometheus/prometheus.yml
Add the following basic configuration:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'node_exporter'
static_configs:
- targets: ['your-instance-ip:9100']
- Create a systemd service unit file for Prometheus:
sudo nano /etc/systemd/system/prometheus.service
Add the following content to the file:
[Unit]
Description=Prometheus
After=network.target
[Service]
ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml
Restart=always
[Install]
WantedBy=multi-user.target
- Reload systemd and start Prometheus:
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
Step 3: Install Grafana
Grafana is a visualization and dashboarding tool for monitoring. Here's how to install it:
- Add the Grafana APT repository and install Grafana:
sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
sudo wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install grafana
- Start and enable the Grafana service:
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
Access Grafana:
Grafana's web interface is available at http://your-instance-ip:3000. You can log in with the default username and password: admin/admin. It's recommended to change the password after the initial login.
You can now configure your data source and dashboards to monitor your infrastructure
- Above is our Grafana GUI, with beautiful dashboard showing CPU usage of our target machines
Article By Noble Mutuwa Isaya Mulaudzi
***************Thank you*************
Top comments (0)