{"id":4630,"date":"2019-11-14T22:40:43","date_gmt":"2019-11-14T19:40:43","guid":{"rendered":"https:\/\/kifarunix.com\/?p=4630"},"modified":"2024-03-12T23:16:16","modified_gmt":"2024-03-12T20:16:16","slug":"install-prometheus-node-exporter-on-centos-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-prometheus-node-exporter-on-centos-8\/","title":{"rendered":"Install Prometheus Node Exporter on CentOS 8"},"content":{"rendered":"\n<p>In this guide, you will learn how to install Prometheus Node Exporter on CentOS 8. Prometheus Node Exporter is used to expose the system hardware and OS metrics such as CPU, disk, memory usage etc with&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/prometheus\/node_exporter#collectors\" target=\"_blank\">pluggable metrics collectors<\/a> so that they can be scraped by Prometheus for monitoring.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Prometheus Node Exporter on CentOS 8<\/h2>\n\n\n\n<p>Before you can install the Prometheus node exporter, ensure that you have Prometheus up and running. Follow the link below to install Prometheus on CentOS 8.<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\"Install and Configure Prometheus on CentOS 8 (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-configure-prometheus-on-centos-8\/\" target=\"_blank\">Install and Configure Prometheus on CentOS 8<\/a><\/p>\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&nbsp;<strong>node_exporter<\/strong>&nbsp;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<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>uid=994(node_exporter) gid=991(node_exporter) groups=991(node_exporter)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Download and Install Node Exporter on CentOS 8<\/h4>\n\n\n\n<p>Next, navigate to Prometheus&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/prometheus.io\/download#node_exporter\" target=\"_blank\">downloads page<\/a>&nbsp;and grab the latest version of Node Exporter tarball (v0.18.1 as of this writing). <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>wget https:\/\/github.com\/prometheus\/node_exporter\/releases\/download\/v0.18.1\/node_exporter-0.18.1.linux-amd64.tar.gz -P \/tmp<\/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>cd \/tmp<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>tar xzf node_exporter-0.18.1.linux-amd64.tar.gz<\/code><\/pre>\n\n\n\n<p>To install the Node Exporter, you just have to copy the <strong><code>node_exporter<\/code><\/strong> binary from the archive folder to&nbsp;<strong>\/usr\/local\/bin<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp node_exporter-0.18.1.linux-amd64\/node_exporter \/usr\/local\/bin\/<\/code><\/pre>\n\n\n\n<p>Set the user and group ownership of the&nbsp;<strong>node_exporter<\/strong>&nbsp;binary to&nbsp;<strong>node_exporter<\/strong>&nbsp;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<h4 class=\"wp-block-heading\">Create Node Exporter SystemD Service<\/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>&#91;Unit]\nDescription=Prometheus Node Exporter\nWants=network-online.target\nAfter=network-online.target\n\n&#91;Service]\nUser=node_exporter\nGroup=node_exporter\nType=simple\nExecStart=\/usr\/local\/bin\/node_exporter\n\n&#91;Install]\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n<p>As stated in the&nbsp;<a rel=\"noreferrer noopener\" 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&nbsp;<strong>ExecStart<\/strong>&nbsp;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 enable --now node_exporter.service<\/code><\/pre>\n\n\n\n<p>Check the status;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status node_exporter<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\u25cf node_exporter.service - Prometheus Node Exporter\n   Loaded: loaded (\/etc\/systemd\/system\/node_exporter.service; enabled; vendor preset: disabled)\n   Active: active (running) since Thu 2019-11-14 21:21:37 EAT; 1min 19s ago\n Main PID: 5130 (node_exporter)\n    Tasks: 3 (limit: 5073)\n   Memory: 4.4M\n   CGroup: \/system.slice\/node_exporter.service\n           \u2514\u25005130 \/usr\/local\/bin\/node_exporter\n\nNov 14 21:21:37 ceph-osd-02.kifarunix-demo.com node_exporter&#91;5130]: time=\"2019-11-14T21:21:37+03:00\" level=info msg=\" - sockstat\" source=\"node_exporter.go:104\"<\/code><\/pre>\n\n\n\n<p>The Node Exporter runs on TCP port 9100.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ss -altnp | grep 91<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>LISTEN   0         128                       *:9100                   *:*        users:((\"node_exporter\",pid=5130,fd=3))<\/code><\/pre>\n\n\n\n<p>For more information on default Prometheus port allocations, check the <a rel=\"noreferrer noopener\" aria-label=\"Default port allocations (opens in a new tab)\" href=\"https:\/\/github.com\/prometheus\/prometheus\/wiki\/Default-port-allocations\" target=\"_blank\">Default port allocations<\/a> page.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Open Port 9100 on FirewallD<\/h3>\n\n\n\n<p>To allow remote connection to Node Exporter from Prometheus server only, you can use Firewalld rich rules as follows;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>firewall-cmd --add-rich-rule 'rule family=\"ipv4\" source address=\"192.168.43.250\/32\" port port=9100 protocol=tcp accept' --permanent<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>firewall-cmd --reload<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Add Node Exporter Target to Prometheus<\/h3>\n\n\n\n<p>Once the Node Exporter is installed, you can now add the target to Prometheus server so it can be scraped.<\/p>\n\n\n\n<p>Therefore, on Prometheus server, open the <code>\/etc\/prometheus\/prometheus.yml<\/code> and add the node as shown below;<\/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-preformatted\"><code>...\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<strong>  ## Add Node Exporter\n  - job_name: 'node01'\n    scrape_interval: 5s\n    static_configs:\n    - targets: ['192.168.43.147:9100']<\/strong>\n<\/job_name><\/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>Ensure that you can connect to the remote Node Exporter port.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>telnet 192.168.43.147 9100<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Trying 192.168.43.147...\nConnected to 192.168.43.147.\nEscape character is '^]'.<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Check Target Status<\/h3>\n\n\n\n<p>Login to Prometheus web interface and check status of the Nodes by navigating to <strong>Status &gt; Targets<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/node-exporter-status.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1121\" height=\"471\" data-id=\"4631\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/node-exporter-status.png\" alt=\"\" class=\"wp-image-4631\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/node-exporter-status.png?v=1573759418 1121w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/node-exporter-status-768x323.png?v=1573759418 768w\" sizes=\"(max-width: 1121px) 100vw, 1121px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Query Node exporter target metrics. Take for example the free disk space. Simply click Graph tab and select <strong><code>node_filesystem_files_free<\/code><\/strong> as the query to execute.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/node-exporter-metrics.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1357\" height=\"532\" data-id=\"4632\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/node-exporter-metrics.png\" alt=\"\" class=\"wp-image-4632\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/node-exporter-metrics.png?v=1573759811 1357w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/node-exporter-metrics-768x301.png?v=1573759811 768w\" sizes=\"(max-width: 1357px) 100vw, 1357px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>You can as well check metrics from command line using curl command. For example to check storage metrics, simply execute the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>curl http:\/\/192.168.43.147:9100\/metrics | grep node_ | grep filesystem<\/code><\/pre>\n\n\n\n<p>Related Tutorials<\/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-centos-8\/\" target=\"_blank\">Install and Configure Prometheus on CentOS 8<\/a><\/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\">Install and Configure Prometheus on Fedora 29\/Fedora 28<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" 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\">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","protected":false},"excerpt":{"rendered":"<p>In this guide, you will learn how to install Prometheus Node Exporter on CentOS 8. Prometheus Node Exporter is used to expose the system hardware<\/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":[72,294],"tags":[1142,968,295],"class_list":["post-4630","post","type-post","status-publish","format-standard","hentry","category-monitoring","category-prometheus","tag-centos-8","tag-node-exporter","tag-prometheus","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4630"}],"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=4630"}],"version-history":[{"count":2,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4630\/revisions"}],"predecessor-version":[{"id":21260,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4630\/revisions\/21260"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=4630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=4630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=4630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}