{"id":3168,"date":"2019-05-30T14:44:04","date_gmt":"2019-05-30T11:44:04","guid":{"rendered":"https:\/\/kifarunix.com\/?p=3168"},"modified":"2019-05-30T20:05:37","modified_gmt":"2019-05-30T17:05:37","slug":"monitor-linux-system-metrics-with-prometheus-node-exporter","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/monitor-linux-system-metrics-with-prometheus-node-exporter\/","title":{"rendered":"Monitor Linux System Metrics with Prometheus Node Exporter"},"content":{"rendered":"\n
In this tutoria, we are going to learn how to monitor Linux system metrics with Prometheus Node Exporter. Node Exporter<\/a> is a Prometheus exporter for hardware and OS metrics exposed by *NIX kernels such as CPU, disk, memory usage etc with pluggable metrics collectors<\/a>.<\/p>\n\n\n\n Learn how to install Prometheus server on Ubuntu 18.04 by visiting the link below;<\/p>\n\n\n\n Install Prometheus on Ubuntu 18.04<\/a><\/p>\n\n\n\n This guide uses Ubuntu 18.04 as a system to collect system metrics from using the Node Exporter.<\/p>\n\n\n\n To run the Node Exporter safely, you need to create a user for it. Hence, run the commands below to create a non-login node_exporter<\/strong> user.<\/p>\n\n\n\n This will create a node_exporter user with the same group as the username.<\/p>\n\n\n\n Next, navigate to Prometheus downloads page<\/a> and grab the Node Exporter tarball.<\/p>\n\n\n\n Once the download is done, run the command below to extract it.<\/p>\n\n\n\n Copy the Node Exporter binary from the archive folder to \/usr\/local\/bin<\/strong>.<\/p>\n\n\n\n Set the user and group ownership of the node_exporter<\/strong> binary to node_exporter<\/strong> user created above.<\/p>\n\n\n\n To run the Node Exporter as a service, you need to create a Systemd service file for it.<\/p>\n\n\n\n As stated in the Collectors section<\/a>, you can configure Node Exporter to expose specific system metrics. For example, to collect CPU, Disk usage and memory statistics, you would set the ExecStart<\/strong> line as;<\/p>\n\n\n\n After that, reload the systemd manager configuration.<\/p>\n\n\n\n Start and enable Node Exporter to run on system boot.<\/p>\n\n\n\n To check status;<\/p>\n\n\n\n The Node Exporter runs on TCP port 9100. Default Prometheus port allocations description are here<\/a>.<\/p>\n\n\n\n Next, login to Prometheus server and add your Node Exporter target.<\/p>\n\n\n\n Restart Prometheus service<\/p>\n\n\n\n Login to Prometheus web interface and check the status of your Target.<\/p>\n\n\n\n If all is well, your target should be up as shown above.<\/p>\n\n\n\n To verify that your Prometheus server can receive metrics from your node, run the command below;<\/p>\n\n\n\n To check for the system metrics, you can grep for the metrics prefixed with node_<\/strong>. For example;<\/p>\n\n\n\n To view the metrics from Prometheus Web interface, and enter any expression for a specific metric you want to see. For example, to check the target’s available memory, you would just type, node_memory_MemAvailable_bytes<\/strong> and click execute. Ensure that the times in both Prometheus server and target are synchronized.<\/p>\n\n\n\n To see the Graphical view, click on the Graph tab.<\/p>\n\n\n\n You have successfully set up Prometheus node exporter to monitor remote Linux host. In our next guide, we will learn how to integrate the Prometheus with Grafana for better visualization. Enjoy.<\/p>\n\n\n\n You can check our other articles by following the links below;<\/p>\n\n\n\n Install and Configure Prometheus on Fedora 29\/Fedora 28<\/a><\/p>\n\n\n\n Install and Configure Prometheus on Debian 9<\/a><\/p>\n\n\n\n Monitor Squid logs with Grafana and Graylog<\/a><\/p>\n\n\n\n Install and Setup TIG Stack on Fedora 30<\/a><\/p>\n\n\n\n Install Grafana Monitoring Tool on Fedora 29<\/a><\/p>\n\n\n\nMonitor Linux System Metrics with Prometheus Node Exporter<\/h2>\n\n\n\n
Installing Prometheus Node Exporter on Ubuntu 18.04<\/h3>\n\n\n\n
Create Node Exporter System User<\/h4>\n\n\n\n
useradd -M -r -s \/bin\/false node_exporter<\/code><\/pre>\n\n\n\n
id node_exporter\nuid=998(node_exporter) gid=997(node_exporter) groups=997(node_exporter)<\/code><\/pre>\n\n\n\n
Download and Install Node Exporter<\/h4>\n\n\n\n
wget https:\/\/github.com\/prometheus\/node_exporter\/releases\/download\/v0.18.0\/node_exporter-0.18.0.linux-amd64.tar.gz<\/code><\/pre>\n\n\n\n
tar xzf node_exporter-0.18.0.linux-amd64.tar.gz<\/code><\/pre>\n\n\n\n
cp node_exporter-0.18.0.linux-amd64\/node_exporter \/usr\/local\/bin\/<\/code><\/pre>\n\n\n\n
chown node_exporter:node_exporter \/usr\/local\/bin\/node_exporter<\/code><\/pre>\n\n\n\n
Running Node Exporter<\/h4>\n\n\n\n
vim \/etc\/systemd\/system\/node_exporter.service<\/code><\/pre>\n\n\n\n
[Unit]\nDescription=Prometheus Node Exporter\nWants=network-online.target\nAfter=network-online.target\n\n[Service]\nUser=node_exporter\nGroup=node_exporter\nType=simple\nExecStart=\/usr\/local\/bin\/node_exporter\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n
ExecStart=\/usr\/local\/bin\/node_exporter --collector.cpu --collector.meminfo --collector.loadavg --collector.filesystem<\/code><\/pre>\n\n\n\n
systemctl daemon-reload<\/code><\/pre>\n\n\n\n
systemctl start node_exporter.service\nsystemctl enable node_exporter.service<\/code><\/pre>\n\n\n\n
systemctl status node_exporter.service\n\u25cf node_exporter.service - Prometheus Node Exporter\n Loaded: loaded (\/etc\/systemd\/system\/node_exporter.service; disabled; vendor preset: enabled)\n Active: active (running) since Thu 2019-05-30 10:24:51 EAT; 7s ago\n Main PID: 4092 (node_exporter)\n Tasks: 4 (limit: 2337)\n CGroup: \/system.slice\/node_exporter.service\n \u2514\u25004092 \/usr\/local\/bin\/node_exporter<\/code><\/pre>\n\n\n\n
ss -altnp | grep 91\nLISTEN 0 128 *:9100 *:* users:((\"node_exporter\",pid=4162,fd=3))<\/code><\/pre>\n\n\n\n
Add Node Exporter Target to Prometheus<\/h3>\n\n\n\n
vim \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n\n\n\n
...\n# Here it's Prometheus itself.\nscrape_configs:\n # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.\n - job_name: 'prometheus'\n\n # metrics_path defaults to '\/metrics'\n # scheme defaults to 'http'.\n\n static_configs:\n - targets: ['localhost:9090']\n # 10.0.0.27(server01) \n\n - job_name: 'server01_ne'\n scrape_interval: 5s\n static_configs:\n - targets: ['10.0.0.27:9100']\n<\/code><\/pre>\n\n\n\n
systemctl restart prometheus<\/code><\/pre>\n\n\n\n
<\/a><\/figure>\n\n\n\n
curl http:\/\/<target-IP>:9100\/metrics<\/code><\/pre>\n\n\n\n
curl http:\/\/10.0.0.27:9100\/metrics | grep node_ | grep filesystem\n...\n# TYPE node_filesystem_avail_bytes gauge\nnode_filesystem_avail_bytes{device=\"\/dev\/mapper\/ubuntu--vg-root\",fstype=\"ext4\",mountpoint=\"\/\"} 2.0969934848e+10\nnode_filesystem_avail_bytes{device=\"tmpfs\",fstype=\"tmpfs\",mountpoint=\"\/run\"} 2.07343616e+08\nnode_filesystem_avail_bytes{device=\"tmpfs\",fstype=\"tmpfs\",mountpoint=\"\/run\/lock\"} 5.24288e+06\nnode_filesystem_avail_bytes{device=\"tmpfs\",fstype=\"tmpfs\",mountpoint=\"\/run\/user\/0\"} 2.09006592e+08\nnode_filesystem_avail_bytes{device=\"tmpfs\",fstype=\"tmpfs\",mountpoint=\"\/run\/user\/1000\"} 2.08973824e+08\nnode_filesystem_avail_bytes{device=\"tmpfs\",fstype=\"tmpfs\",mountpoint=\"\/run\/user\/121\"} 2.0897792e+08\n# HELP node_filesystem_device_error Whether an error occurred while getting statistics for the given device.\n# TYPE node_filesystem_device_error gauge\n...<\/code><\/pre>\n\n\n\n
<\/a><\/figure>\n\n\n\n
<\/a><\/figure>\n\n\n\n