Monitoring your server can sometimes be difficult, but it's essential for you to monitor your server to know which apps are actually using the most of your ressources, is your machine running out of memory ? is it time to upgrade or attach a new volume ?
This article will help you scaffold your Monitoring using Prometheus & Grafana to get a working monitoring solution and in less than 10 minutes, bonus you don't need to use Grafana in your machine since Grafana Cloud offers a free tier.
You'll be able to monitor your Linux Machine in the end of this article and be able to understand how does it work
version: "3.8" services: node_exporter: image: quay.io/prometheus/node-exporter:latest container_name: node_exporter command: - "--path.rootfs=/host" network_mode: host # port 9100 is exposed by default pid: host restart: unless-stopped volumes: - "/:/host:ro,rslave" prometheus: image: quay.io/prometheus/prometheus:latest container_name: prometheus network_mode: host volumes: - "./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml"
But what is an exporter ?
An exporter is software that you installs in your machine, it collect data metrics from something and export it - or make it available for another service to use it for monitoring or analytics purposes in this case Grafana dashboards
What is Prometheus ?
Prometheus is a time series database used for collecting metrics you would export using an exporter, you can think of it as big monitoring software block that collect multiple sources of metrics from anywhere and then store it time-based and provides you a way to query on these metrics, the goal at the end is to link your big prometheus " monitoring tower " to your Grafana instance
What is Node exporter ?
It is one of the "exporters" that Prometheus provide you with, The Node one is used to collect system data, like :
global: scrape_interval: 15s # By default, scrape targets every 15 seconds. # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). external_labels: monitor: "codelab-monitor" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: "prometheus" # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s static_configs: - targets: ["127.0.0.1:9090"] # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: "node-exporter" # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s static_configs: - targets: ["127.0.0.1:9100"]
You probably noticed that I used the network mode host, that's because Node exporter need to access the host system, you can find more informations about that here
docker-compose up -d
Grafana offers a free tier of their Hosted instances, just grab one at Grafana.com,
When using grafana you can either choose to make your own panels/dashboards OR use Dashboard templates, we'll use a pretty useful Grafana dashboard that I found complete : this one
Congratulations 🥳 , you know have a complete dashboard that monitor your linux machine and it should looks like this :