Prometheus and node_exporter install
Installing Prometheus
useradd --no-create-home --shell /bin/false prometheususeradd --no-create-home --shell /bin/false node_exportermkdir /etc/prometheusmkdir /var/lib/prometheuschown prometheus:prometheus /etc/prometheuschown prometheus:prometheus /var/lib/prometheusDownload Prometheus from https://prometheus.io/download/
Extract the tar ball:
tar xf prometheus-xxx.tar.gzcd prometheus-xxxcp prometheus /usr/local/bincp promtool /usr/local/bin/chown prometheus:prometheus /usr/local/bin/prometheuschown prometheus:prometheus /usr/local/bin/promtoolcp -r consoles /etc/prometheuscp -r console_libraries /etc/prometheuschown -R prometheus:prometheus /etc/prometheus/consoleschown -R prometheus:prometheus /etc/prometheus/console_librariesYou can now rm the tarball and folder created when extracting.
Configuring prometheus:
vi /etc/prometheus/prometheus.yml# ---------- begin /etc/prometheus/prometheus.yml
global: scrape_interval: 15sscrape_configs: - job_name: 'prometheus' scrape_interval: 5s static_configs: - targets: ['localhost:9090']# ---------- end /etc/prometheus/prometheus.yml
chown prometheus:prometheus /etc/prometheus/prometheus.yml# Try to run prometheus
sudo -u prometheus /usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \ --storage.tsdb.path /var/lib/prometheus/ \ --web.console.templates=/etc/prometheus/consoles \ --web.console.libraries=/etc/prometheus/console_librariesEverything went well, right?
Let's create a new systemd file for prometheus:
vi /etc/systemd/system/prometheus.service# ---------- begin /etc/systemd/system/prometheus.service
[Unit]Description=PrometheusWants=network-online.targetAfter=network-online.target[Service]User=prometheusGroup=prometheusType=simpleExecStart=/usr/local/bin/prometheus \ --config.file /etc/prometheus/prometheus.yml \ --storage.tsdb.path /var/lib/prometheus/ \ --web.console.templates=/etc/prometheus/consoles \ --web.console.libraries=/etc/prometheus/console_libraries[Install]WantedBy=multi-user.target# ---------- end /etc/systemd/system/prometheus.service
systemctl daemon-reloadsystemctl start prometheussystemctl status prometheussystemctl enable prometheusInstalling node_exporter
Download node_exporter from https://prometheus.io/download/
Extract it and cd into the newly created folder
tar xf node_exporter-xxx.tar.gzcd node_exporter-xxxCopy the node_exporter binary
cp node_exporter /usr/local/binchown node_exporter:node_exporter /usr/local/bin/node_exporterYou can now delete the remaining node_exporter folder and tarball
Create a new systemd script for node_exporter
vi /etc/systemd/system/node_exporter.service# ---------- begin /etc/systemd/system/node_exporter.service
Description=Node ExporterWants=network-online.targetAfter=network-online.target[Service]User=node_exporterGroup=node_exporterType=simpleExecStart=/usr/local/bin/node_exporter[Install]WantedBy=multi-user.target# ---------- end /etc/systemd/system/node_exporter.service
systemctl daemon-reloadsystemctl start node_exportersystemctl status node_exportersystemctl enable node_exporterSo far so good!
Now we need to tell prometheus about how to reach node_exporter:
Add node_exporter to prometheus-yaml
vi /etc/prometheus/prometheus.yml# ---------- begin /etc/systemd/system/node_exporter.service
global: scrape_interval: 15sscrape_configs: - job_name: 'prometheus' scrape_interval: 5s static_configs: - targets: ['localhost:9090'] - job_name: 'node_exporter' scrape_interval: 5s static_configs: - targets: ['localhost:9100'] # ---------- end /etc/systemd/system/node_exporter.service
Prometheus and node_exporter are installed, configured and working together!
Check prometheus console with your web browser
http://localhost:9090
Click Status, then Target. You should find two targets:
- prometheus itself, which serves status about the prometheus server, and
- node_exporter will serve stats about the host.
Click the endpoint for prometheus. Should be http://localhost:9090/metrics
At the bottom on the page, check the endpoint named
promhttp_metric_handler_requests_total{code="200"}Refresh the page a few time, you should see the metric value increasing.
Copy the endpoint for this metric (promhttp_metric_handler_requests_total).
Go back to prometheus dashboard http://localhost:9090/graph
Paste the endpoint to the Expression form, then press execute. You will see only information about the endpoint you requested.
That's it for now!