{"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<p>In this tutoria, we are going to learn how to monitor Linux system metrics with Prometheus Node Exporter. <a rel=\"noreferrer noopener\" aria-label=\"Node Exporter (opens in a new tab)\" href=\"https:\/\/github.com\/prometheus\/node_exporter\" target=\"_blank\">Node Exporter<\/a> is a Prometheus exporter for hardware and OS metrics exposed by *NIX kernels such as CPU, disk, memory usage etc with <a rel=\"noreferrer noopener\" aria-label=\"pluggable metrics collectors (opens in a new tab)\" href=\"https:\/\/github.com\/prometheus\/node_exporter#collectors\" target=\"_blank\">pluggable metrics collectors<\/a>.<\/p>\n\n\n\n<p>Learn how to install Prometheus server on Ubuntu 18.04 by visiting the link below;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-prometheus-on-ubuntu-18-04\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install Prometheus on Ubuntu 18.04<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Monitor Linux System Metrics with Prometheus Node Exporter<\/h2>\n\n\n\n<p>This guide uses Ubuntu 18.04 as a system to collect system metrics from using the Node Exporter.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Prometheus Node Exporter on Ubuntu 18.04<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Create Node Exporter System User<\/h4>\n\n\n\n<p>To run the Node Exporter safely, you need to create a user for it. Hence, run the commands below to create a non-login <strong>node_exporter<\/strong> user.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>useradd -M -r -s \/bin\/false node_exporter<\/code><\/pre>\n\n\n\n<p>This will create a node_exporter user with the same group as the username.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>id node_exporter\nuid=998(node_exporter) gid=997(node_exporter) groups=997(node_exporter)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Download and Install Node Exporter<\/h4>\n\n\n\n<p>Next, navigate to Prometheus&nbsp;<a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/prometheus.io\/download#node_exporter\" target=\"_blank\">downloads page<\/a> and grab the Node Exporter tarball.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>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<p>Once the download is done, run the command below to extract it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>tar xzf node_exporter-0.18.0.linux-amd64.tar.gz<\/code><\/pre>\n\n\n\n<p>Copy the Node Exporter binary from the archive folder to <strong>\/usr\/local\/bin<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp node_exporter-0.18.0.linux-amd64\/node_exporter \/usr\/local\/bin\/<\/code><\/pre>\n\n\n\n<p>Set the user and group ownership of the <strong>node_exporter<\/strong> binary to <strong>node_exporter<\/strong> user created above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown node_exporter:node_exporter \/usr\/local\/bin\/node_exporter<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Running Node Exporter<\/h4>\n\n\n\n<p>To run the Node Exporter as a service, you need to create a Systemd service file for it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/systemd\/system\/node_exporter.service<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[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<p>As stated in the <a rel=\"noreferrer noopener\" aria-label=\"Collectors section (opens in a new tab)\" href=\"https:\/\/github.com\/prometheus\/node_exporter#collectors\" target=\"_blank\">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 <strong>ExecStart<\/strong> line as;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ExecStart=\/usr\/local\/bin\/node_exporter --collector.cpu --collector.meminfo --collector.loadavg --collector.filesystem<\/code><\/pre>\n\n\n\n<p>After that, reload the systemd manager configuration.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl daemon-reload<\/code><\/pre>\n\n\n\n<p>Start and enable Node Exporter to run on system boot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl start node_exporter.service\nsystemctl enable node_exporter.service<\/code><\/pre>\n\n\n\n<p>To check status;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>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<p>The Node Exporter runs on TCP port 9100. Default Prometheus port allocations description are <a rel=\"noreferrer noopener\" aria-label=\"here (opens in a new tab)\" href=\"https:\/\/github.com\/prometheus\/prometheus\/wiki\/Default-port-allocations\" target=\"_blank\">here<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ss -altnp | grep 91\nLISTEN   0         128                       *:9100                   *:*        users:((\"node_exporter\",pid=4162,fd=3))<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Add Node Exporter Target to Prometheus<\/h3>\n\n\n\n<p>Next, login to Prometheus server and add your Node Exporter target.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n# Here it's Prometheus itself.\nscrape_configs:\n  # The job name is added as a label `job=&lt;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<p>Restart Prometheus service<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart prometheus<\/code><\/pre>\n\n\n\n<p>Login to Prometheus web interface and check the status of your Target.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/node_exporter.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1113\" height=\"484\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/node_exporter.png\" alt=\"Prometheus Node Exporter\" class=\"wp-image-3179\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/node_exporter.png 1113w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/node_exporter-768x334.png 768w\" sizes=\"(max-width: 1113px) 100vw, 1113px\" \/><\/a><\/figure>\n\n\n\n<p>If all is well, your target should be up as shown above.<\/p>\n\n\n\n<p>To verify that your Prometheus server can receive metrics from your node, run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>curl http:\/\/&lt;target-IP&gt;:9100\/metrics<\/code><\/pre>\n\n\n\n<p>To check for the system metrics, you can grep for the metrics prefixed with <strong>node_<\/strong>. For example;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>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<p>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&#8217;s available memory, you would just type, <strong>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<figure class=\"wp-block-image\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/memory-available.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1364\" height=\"460\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/memory-available.png\" alt=\" monitor Linux system metrics with Prometheus Node Exporter: memory available\" class=\"wp-image-3184\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/memory-available.png 1364w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/memory-available-768x259.png 768w\" sizes=\"(max-width: 1364px) 100vw, 1364px\" \/><\/a><\/figure>\n\n\n\n<p>To see the Graphical view, click on the Graph tab.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/mem-avail-graph.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1336\" height=\"636\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/Prometheus-target-available-memory-graph.png\" alt=\"Prometheus node exporter available memory\" class=\"wp-image-3188\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/Prometheus-target-available-memory-graph.png 1336w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/Prometheus-target-available-memory-graph-768x366.png 768w\" sizes=\"(max-width: 1336px) 100vw, 1336px\" \/><\/a><\/figure>\n\n\n\n<p>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<p>You can check our other articles by following the links below;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-configure-prometheus-on-fedora-29-fedora-28\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install and Configure Prometheus on Fedora 29\/Fedora 28<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-configure-prometheus-on-debian-9\/\" target=\"_blank\">Install and Configure Prometheus on Debian 9<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/monitor-squid-logs-with-grafana-and-graylog\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Monitor Squid logs with Grafana and Graylog<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-setup-tig-stack-on-fedora-30\/\">Install and Setup TIG Stack on Fedora 30<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-grafana-monitoring-tool-on-fedora-29\/\" target=\"_blank\">Install Grafana Monitoring Tool on Fedora 29<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-elastic-stack-7-on-ubuntu-18-04-debian-9-8\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install Elastic Stack 7 on Ubuntu 18.04\/Debian 9.8<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutoria, we are going to learn how to monitor Linux system metrics with Prometheus Node Exporter. Node Exporter is a Prometheus exporter for<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,72,294],"tags":[968,295,67],"class_list":["post-3168","post","type-post","status-publish","format-standard","hentry","category-howtos","category-monitoring","category-prometheus","tag-node-exporter","tag-prometheus","tag-ubuntu-18-04","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/3168"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=3168"}],"version-history":[{"count":14,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/3168\/revisions"}],"predecessor-version":[{"id":3191,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/3168\/revisions\/3191"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=3168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=3168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=3168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}