هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
Prometheus pulls (scrapes) metrics over HTTP from targets — a /metrics page on each server or app. Exporters make that page for things that do not have one (Node Exporter for Linux servers). You ask questions with PromQL.
| Item | Prometheus | Node Exporter |
|---|---|---|
| Files | /usr/local/bin/prometheus, promtool | /usr/local/bin/node_exporter |
| Config | /etc/prometheus/prometheus.yml | flags in the service file |
| Data | /var/lib/prometheus/ | — |
| Port | 9090/tcp (web UI and API) | 9100/tcp (/metrics) |
| Service | prometheus.service (you write it) | node_exporter.service |
| User | prometheus (system user) | node_exporter (system user) |
ملاحظة
Ubuntu has packages (apt install prometheus prometheus-node-exporter) — quick, but often old. The official release files below give the current version on every distribution. In Kubernetes you install the whole stack with the Helm chart kube-prometheus-stack instead.
Install Prometheus (RHEL and Ubuntu)
Choose the version from github.com/prometheus/prometheus/releases (here 3.5.0, a long-term support version). Make a system user and the folders:
useradd --system --no-create-home --shell /sbin/nologin prometheus
mkdir -p /etc/prometheus /var/lib/prometheus
VER=3.5.0
curl -fsSLO https://github.com/prometheus/prometheus/releases/download/v$VER/prometheus-$VER.linux-amd64.tar.gz
tar -xzf prometheus-$VER.linux-amd64.tar.gz
install -m 0755 prometheus-$VER.linux-amd64/prometheus prometheus-$VER.linux-amd64/promtool /usr/local/bin/
chown -R prometheus: /etc/prometheus /var/lib/prometheus
prometheus --versionWrite the service file:
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus \
--storage.tsdb.retention.time=30d \
--web.listen-address=127.0.0.1:9090
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.targetInstall Node Exporter on every server
useradd --system --no-create-home --shell /sbin/nologin node_exporter
NVER=1.9.1
curl -fsSLO https://github.com/prometheus/node_exporter/releases/download/v$NVER/node_exporter-$NVER.linux-amd64.tar.gz
tar -xzf node_exporter-$NVER.linux-amd64.tar.gz
install -m 0755 node_exporter-$NVER.linux-amd64/node_exporter /usr/local/bin/[Unit]
Description=Node Exporter
After=network-online.target
[Service]
User=node_exporter
ExecStart=/usr/local/bin/node_exporter --collector.systemd
Restart=on-failure
[Install]
WantedBy=multi-user.targetsystemctl daemon-reload
systemctl enable --now node_exporter
curl -s http://localhost:9100/metrics | grep ^node_load1
node_load1 0.12Open port 9100 only for the Prometheus server:
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.5/32" port port="9100" protocol="tcp" accept'
firewall-cmd --reload
ufw allow from 10.0.0.5 to any port 9100 proto tcpFirst configuration: targets and alert rules
global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
- /etc/prometheus/rules/*.yml
alerting:
alertmanagers:
- static_configs:
- targets: ["127.0.0.1:9093"]
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ["127.0.0.1:9090"]
- job_name: node
static_configs:
- targets: ["web1:9100", "web2:9100", "db1:9100"]
labels:
env: prodThe first alert rules every team needs — server down, disk almost full, high CPU:
groups:
- name: node
rules:
- alert: InstanceDown
expr: up == 0
for: 2m
labels: { severity: critical }
annotations:
summary: "{{ $labels.instance }} is down"
- alert: DiskAlmostFull
expr: (node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} / node_filesystem_size_bytes) < 0.10
for: 10m
labels: { severity: warning }
annotations:
summary: "Less than 10% disk free on {{ $labels.instance }} {{ $labels.mountpoint }}"
- alert: HighCPU
expr: 100 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100 > 90
for: 15m
labels: { severity: warning }Check, start and open the UI:
mkdir -p /etc/prometheus/rules && chown -R prometheus: /etc/prometheus
promtool check config /etc/prometheus/prometheus.yml
SUCCESS: /etc/prometheus/prometheus.yml is valid prometheus config file syntax
promtool check rules /etc/prometheus/rules/node.yml
systemctl daemon-reload
systemctl enable --now prometheus
systemctl reload prometheus
curl -s http://127.0.0.1:9090/-/readyPrometheus listens only on 127.0.0.1:9090. Look at it through an SSH tunnel (ssh -L 9090:127.0.0.1:9090 mon1) or put Nginx with a login in front. Status → Targets must show every target UP.
Daily use: PromQL and the real uses
Queries you use every day (Graph page or Grafana):
up
up == 0
100 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100
(1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100
node_filesystem_avail_bytes{mountpoint="/"} / 1e9
rate(node_network_receive_bytes_total{device="eth0"}[5m])
predict_linear(node_filesystem_avail_bytes{mountpoint="/"}[6h], 24*3600) < 0
sum by (status) (rate(http_requests_total[5m]))Real uses at work:
- Dashboards in Grafana; alerts to Slack, Teams, email or PagerDuty through Alertmanager.
- Capacity planning:
predict_linearsays when a disk will be full. - App metrics (requests, errors, latency) from client libraries — the base of SLOs.
Make it safe
Security checklist:
- Prometheus and exporters have no login by default: listen on localhost or a private network, firewall the ports.
- For access from outside, use Nginx with TLS and a login, or
--web.config.filewith TLS and basic auth. - Do not put secrets in labels or metric names.
- Keep
--web.enable-admin-apiand--web.enable-lifecycleoff unless you need them. - Watch Prometheus itself: disk usage of
/var/lib/prometheus, theupof all jobs.
Update and remove
Download the new release, stop the service, replace the binary, start it. Check the config first with the new promtool:
systemctl stop prometheus
install -m 0755 prometheus-3.5.1.linux-amd64/prometheus prometheus-3.5.1.linux-amd64/promtool /usr/local/bin/
systemctl start prometheus
systemctl disable --now prometheus node_exporter
rm -rf /usr/local/bin/{prometheus,promtool,node_exporter} /etc/prometheus /var/lib/prometheus /etc/systemd/system/{prometheus,node_exporter}.serviceFix common problems
| Problem | Cause | Fix |
|---|---|---|
Target DOWN: connection refused | Exporter not running or wrong port. | systemctl status node_exporter; curl HOST:9100/metrics. |
Target DOWN: context deadline exceeded | Firewall drops the scrape. | Open 9100 for the Prometheus IP. |
Service does not start: permission denied on /var/lib/prometheus | Wrong owner. | chown -R prometheus: /var/lib/prometheus /etc/prometheus. |
error loading config | YAML indentation or a typo. | promtool check config; fix the line. |
| Alert never fires | Wrong expression, or for: time not reached. | Test the expr on the Graph page; look at Alerts → Pending. |
| Disk fills up | Retention too long or too many series. | Lower retention.time; add --storage.tsdb.retention.size=50GB; remove high-cardinality labels. |
$labels text shows empty in alerts | Wrong quoting in YAML. | Put the summary in double quotes as above. |
Next steps
- Quick how-tos: Monitor a Linux server, Send alerts to Slack or email, Monitor TLS certificates, Define an SLO and an error budget, Monitor a website from outside.
- Command pages: promtool, node_exporter, amtool.
- Show the data: Install and set up Grafana.
- Practise the full stack: Lab: Prometheus, node exporter, Alertmanager and Grafana.
- Prometheus at work: Metrics and alert rules, Prometheus in DevOps.
1Does Prometheus push metrics to a server or pull them from targets?
It pulls (scrapes) them over HTTP from each target's /metrics page.
2Which query shows all targets that are down?
up == 0.