I consider myself a technology enthusiast, when I see gadgets or computers that could simplify my work – I rush to get a hold of them. I collected a couple of computers throughout the years and they come in different sizes from portable to a normal computer. I pretend that I use them all to justify to my wife that I need more.
Now, it’s really hard to monitor multiple computers at once so I wanted to use a centralized monitoring system to keep track of their performances. Throughout the years as a developer and somewhat a part-time system administrator, I have come across a lot of different software to implement this but for this specific project, I will use an open-source solution, specifically Promethes and Grafana.
Before we go to the step by step here are the alternatives software you could use:
In this setup, I will try to make it as simple as possible – make it easier for the new guys to follow. We are going to use pre-built docker images from docker hub, it should shorten the setup time since we don’t have to build the packages piece by piece.
- WMI Exporter – The windows_exporter will expose all metrics from enabled collectors by default. The Windows exporter is recommended for Windows users. LINK
- Node Exporter – The node_exporter is the same as windows_exporter but for linux. LINK
- Prometheus – is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. LINK
- Grafana – Grafana allows you to query, visualize, alert on and understand your metrics. Create, explore, and share beautiful dashboards. LINK
- Client computer: Computer(s) we are going to retrieve the metrics from.
- Monitoring computer: A machine capable of installing docker (On my end I use an old raspi2). At the time of this writing, Windows 10 Home is not compatible with docker yet.
- Docker on monitoring computer, we will not go through docker installation steps but here is a reference link.
Step by steps:
Please refer to my repository for source scripts.
- Install exporter for both Windows and Linux machines.
- Install exporter on windows machines:
- WMI Exporter
- Download and install – LINK
- Once installed, validate using “http://localhost:9182/metrics”, you should see something like below:
- WMI Exporter
- Install exporter on Linux machines:
- Node Exporter
- Go to Node Exporter repo: LINK
- For Pi3 use the armv6 and for Pi4 use the armv7
- Execute the command below:
- Node Exporter
No extract the tar file
tar -xvzf node_exporter-0.18.1.linux-armv7.tar.gz
This will extract directories below
node_exporter-0.18.1.linux-armv7/ node_exporter-0.18.1.linux-armv7/node_exporter node_exporter-0.18.1.linux-armv7/NOTICE node_exporter-0.18.1.linux-armv7/LICENSE
Move/Copy the directory to /usr/local/bin then create a node_exporter service.
# Copy node exporter to /usr/local/bin sudo cp node_exporter-0.18.1.linux-armv6/node_exporter /usr/local/bin # Make node_exporter executable chmod +x /usr/local/bin/node_exporter # Add node_exporter user to your system sudo useradd -m -s /bin/bash node_exporter # Create a directory sudo mkdir /var/lib/node_exporter # Change the permissions for the node exporter binary chown -R node_exporter:node_exporter /var/lib/node_exporter # Go to etc->systemd->system directory cd /etc/systemd/system/ # Create a node_exporter.service file and edit it sudo nano node_exporter.service
Insert code below to the node_exporter.service file
[Unit] Description=Node Exporter [Service] # Provide a text file location for https://github.com/fahlke/raspberrypi_exporter data with the # --collector.textfile.directory parameter. ExecStart=/usr/local/bin/node_exporter --collector.textfile.directory /var/lib/node_exporter/textfile_collector [Install] WantedBy=multi-user.target
Now lets reload the daemon then enable and start the node_exporter service
sudo systemctl daemon-reload sudo systemctl enable node_exporter.service sudo systemctl start node_exporter.service
To validate, same as what you did to WMI exporter visit “http://localhost:9100/metrics”
2. Pull docker images for Prometheus and Grafana
Image sources in docker Hub
- Prometheus: https://hub.docker.com/r/prom/prometheus/
- Grafana: https://hub.docker.com/r/grafana/grafana
To pull these images execute the commands below:
docker pull prom/prometheus docker pull grafana/grafana
3. Configure and run Prometheus
Download the source code of Prometheus and extract the prometheus.yml file
wget https://github.com/prometheus/prometheus/releases/download/v2.11.2/prometheus-2.11.2.linux-amd64.tar.gz tar xvzf prometheus-2.11.2.linux-amd64.tar.gz
On the extracted file locate prometheus.yml and update it with the client computers IP (I separated below my WMI and Node exporter):
- job_name: 'wmiexporter' scrape_interval: 5s scrape_timeout: 5s static_configs: - targets: ['192.168.1.2:9182','192.168.1.3:9182'] - job_name: 'nodeexporter' scrape_interval: 5s scrape_timeout: 5s static_configs: - targets: ['192.168.1.4:9100']
Now you can run the Prometheus docker with this command:
docker run -d -p 9090:9090 -v /home/pi/prometheus.yml:/etc/prometheus/prometheus.yml <IMAGE_ID>
To validate Prometheus access your monitoring computer’s IP: ‘http://YOUR_MONITORING_PC_IP:9090/’ or ‘http://localhost:9090/’
Then go to status->targets and check if your client’s computer(s) are listed.
4. Configure and run Grafana
Run the Grafana docker using the command below:
docker run -d -p 3000:3000 grafana/grafana
Open Grafana at `http://localhost:3000` or whatever IP your monitoring PC is located.
Configure Grafana to connect to Prometheus, go to Configuration-> Data sources -> Prometheus and fill in the required parameters
Configure Grafana Dashboard
For Windows dashboard, select add dashboard (the + icon) -> Import then type in ‘2129’. On the next page name your dashboard and select Prometheus. Once done you should be able to see similar dashboard below:
For Linux dashboard do the same but instead of ‘2129’ type ‘1860’.
(Optional Step) Auto start Prometheus & Grafana on boot
If you want your docker images/containers autoload on reboot, execute the commands below:
`docker run -d --restart unless-stopped <IMAGE_ID>` OR `docker update --restart unless-stopped <CONTAINER_ID>`
Check out my setup using Raspi2 with a 7.5 inch display: