Hello Folks,

I am back with yet another article. This article is about how to monitor a Linux host with Prometheus. Prometheus provides an exporter called the Node Exporter. This scrapes various metrics from any linux machine.

Let’s begin in installing and configuring the node exporter.

Installing and Running Prometheus Node Exporter

  1. Download the latest version of Node Exporter from this page.
  2. Extract the tarball
$ tar xzvf node_exporter-0.18.1.linux-amd64.tar.gz
$ ls -l node_exporter-0.18.1.linux-amd64
total 16500
-rw-r--r-- 1 himanshug himanshug    11357 Jun  4 16:50 LICENSE
-rw-r--r-- 1 himanshug himanshug      463 Jun  4 16:50 NOTICE
-rwxr-xr-x 1 himanshug himanshug 16878582 Jun  4 16:41 node_exporter
  1. node_exporter can be seen above. This is a binary that needs to be run as below
$ ./node_exporter
INFO[0000] Starting node_exporter (version=0.18.1, branch=HEAD, revision=3db77732e925c08f675d7404a8c46466b2ece83e)  source="node_exporter.go:156"
INFO[0000] Build context (go=go1.12.5, user=root@b50852a1acba, date=20190604-16:41:18)  source="node_exporter.go:157"
INFO[0000] Enabled collectors:                           source="node_exporter.go:97"
INFO[0000]  - arp                                        source="node_exporter.go:104"
...
INFO[0000] Listening on :9100                            source="node_exporter.go:170"

Node exporter by default runs on port 9100.

  1. A lot of metrics can be seen by using.
$ curl localhost:9100/metrics | less

# HELP node_cpu_seconds_total Seconds the cpus spent in each mode.
# TYPE node_cpu_seconds_total counter
node_cpu_seconds_total{cpu="0",mode="idle"} 1.578921354e+07
node_cpu_seconds_total{cpu="0",mode="iowait"} 2718.47
node_cpu_seconds_total{cpu="0",mode="irq"} 0
node_cpu_seconds_total{cpu="0",mode="nice"} 45.13
node_cpu_seconds_total{cpu="0",mode="softirq"} 90.37
node_cpu_seconds_total{cpu="0",mode="steal"} 962.79
node_cpu_seconds_total{cpu="0",mode="system"} 42962.77
node_cpu_seconds_total{cpu="0",mode="user"} 79988.43

Above you can see the CPU metrics of the machine.

Making Prometheus To Scrape Node Metrics

Now we have installed and ran node exporter. It has exposed several system metrics that Prometheus can scrape. Next steps will define how to tell Prometheus to scrape these new metrics.

  1. Add a new scrape_config in prometheus config
$ vim prometheus.yml


scrape_configs:
  - job_name: 'node'
    static_configs:
    - targets: ['localhost:9100']
  1. Run prometheus
$ ./prometheus
  1. Visualize the system metrics
Showing Free Memory (Bytes) of System using Prometheus Node Exporter

It’s your turn to try this out. Leave your comments below for suggestions or help.

Have a nice day!


Aryan

Hey Friends, Thank you for visiting my blog and spending some time reading it. Myself Aryan who works in computer technologies and keeps on pen down my understanding of various topics. This blog is a write-up of my understanding of various technologies after reading different materials about it. I hope that it helps you in some way.

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *