Building a Linux Host Monitoring System with Prometheus, Grafana, and Node Exporter
This guide walks through installing and configuring Prometheus, Grafana, and Node Exporter on a Linux server using Docker, shows how to set up monitoring dashboards, customize PromQL queries, and verify the monitoring system, providing complete steps and code snippets for a functional host monitoring solution.
Hello everyone, I am Chen (not very talented)~
This article uses Prometheus + Grafana + Node Exporter to build a Linux host monitoring system.
Prometheus is a monitoring system that collects and stores metric data from various targets, supporting multiple data sources including Node Exporter.
Grafana is a visualization tool that can display the metrics collected by Prometheus, offering various dashboards and chart types.
Node Exporter is a process that gathers a wide range of Linux host metrics and exposes them via an HTTP endpoint for Prometheus to scrape.
Installation
Environment preparation
The required environment includes:
A Linux server (preferably CentOS or Ubuntu)
Docker
Prometheus and Grafana
Node Exporter
1. Install Prometheus
You can obtain the latest version from GitHub:
https://github.com/prometheus/prometheus
vim prometheus.yml
# my global config
global:
scrape_interval: 15s # collection interval
evaluation_interval: 15s # evaluation interval
# alerting configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# rule files
rule_files:
# - "first_rules.yml"
# scrape configuration for Prometheus itself
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
docker run -d -p 9090:9090 \
--name prometheus \
--restart on-failure \
-v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheusAfter the container starts, access the UI at xx.xx.xx.xx:9090 to verify the installation.
2. Install Grafana
docker run -d --name=grafana -p 3000:3000 grafana/grafanaOnce the image is downloaded and the container runs, open xx.xx.xx.xx:3000 with the default credentials admin/admin .
3. Install Node Exporter
cd /usr/local/src/
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz
tar -xvf node_exporter-1.6.1.linux-amd64.tar.gz
mv /usr/local/src/node_exporter-1.6.1.linux-amd64/node_exporter /usr/local/bin
vim /usr/lib/systemd/system/node_exporter.serviceContents of node_exporter.service :
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable node_exporter
systemctl restart node_exporterAfter starting, open xx.xx.xx.xx:9100/ to see the exporter metrics.
4. Configure Prometheus
# After starting, edit prometheus.yml
vim /data/prometheus/prometheus.yml
scrape_configs:
# The job name is added as a label `job=
`
- job_name: 'prometheus'
static_configs:
- targets: ['xx.xx.xx.xx:9090']
# Collect metrics from node_exporter
- job_name: "Linux-Metrics"
static_configs:
- targets: ['xx.xx.xx.xx:9100']
# Restart Prometheus
systemctl restart prometheusUsage
Access Grafana at xx.xx.xx.xx:3000 (default user/password: admin/admin).
Select "Add your first data source", choose Prometheus, and fill in the connection details.
Import a dashboard template (e.g., ID 9276) from the Grafana marketplace to visualize the collected metrics.
After importing, the Linux host monitoring dashboard is ready.
Supplement
1. Dashboard Templates
If you are unsure which template to use, you can browse the Grafana dashboard repository at https://grafana.com/grafana/dashboards , search by keywords, and select a suitable one.
2. Data Comparison
Some metrics match the output of top , while others differ due to different calculation methods. You can click a graph title to view details and understand the formulas.
3. Custom Templates
By editing a dashboard's JSON, you can modify expressions, filters, or aggregation rules. The expressions used in Grafana are written in PromQL, Prometheus's query language.
PromQL basics:
[metric_name] [operator] [value]Examples:
cpu_usage # query CPU usage metric
cpu_usage < 100 # filter values below 100
avg(cpu_usage) # calculate average
by(host) cpu_usage # aggregate by hostPromQL offers rich functionality for various monitoring needs.
Final Note (Support Request)
If this article helped you, please like, view, share, or bookmark it. Your support motivates me to keep writing.
My knowledge community is also open for a fee of 199 CNY, offering advanced projects and series such as Spring, massive data sharding, DDD micro‑services, and more. Details are in the linked article.
Follow the public account "Code Monkey Technical Column" for additional resources and join the discussion group via the provided contact.
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.