Prometheus is able to monitor our infrastructure and applications at multiple levels: on the host itself, on any containers, and on the application. In this hands-on lab, we’re going to address the first two options for monitoring: our virtual machine host and our containers. We’ll first set up monitoring for our virtual machine by using Prometheus’s Node Exporter, and then we’ll set up container monitoring for the provided container using Google’s cAdvisor. By the time we’re done, we’ll be able to view metrics across two levels of our system in Prometheus to track changes and view trends on our systems.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Set up the Node Exporter.
Work on the application server.
Create a system user:
$ sudo useradd –no-create-home –shell /bin/false node_exporter
Download the Node Exporter from Prometheus’s download page:
$ cd /tmp/
$ wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gzExtract its contents:
$ tar -xvf node_exporter-0.17.0.linux-amd64.tar.gz
Move into the newly-created directory:
$ cd node_exporter-0.17.0.linux-amd64/
Move the provided binary:
$ sudo mv node_exporter /usr/local/bin/
Set the ownership:
$ sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
Create a systemd service file:
$ sudo vim /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
After=network.target[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter[Install]
WantedBy=multi-user.targetSave and exit when done.
Start the Node Exporter:
$ sudo systemctl start node_exporter
- Set up cAdvisor.
Work on the application server.
Launch cAdvisor:
$ sudo docker run
–volume=/:/rootfs:ro
–volume=/var/run:/var/run:ro
–volume=/sys:/sys:ro
–volume=/var/lib/docker/:/var/lib/docker:ro
–volume=/dev/disk/:/dev/disk:ro
–publish=8000:8080
–detach=true
–name=cadvisor
google/cadvisor:latestList available containers to confirm it’s working:
$ docker ps
- Add the new endpoints to Prometheus.
Work on the monitoring server.
Open the Prometheus configuration file:
$ sudo vim /etc/prometheus/prometheus.yml
Add the Node Exporter and cAdvisor endpoints:
- job_name: 'node_exporter' static_configs: - targets: ['10.0.1.101:9100'] - job_name: 'cadvisor' static_configs: - targets: ['10.0.1.101:8000']
Save and exit.
Restart Prometheus:
$ sudo systemctl restart prometheus
Check the Targets page on the web UI to ensure the endpoints are working.