Running node exporter as a service

Creating node-exporter service file

  1. First of we need to create Prometheus user and group both.

     sudo groupadd --system prometheus
     sudo useradd -s /sbin/nologin --system -g prometheus prometheus
    
  2. Create this directory /var/lib/node and move the extracted node binary to this directory mv node_exporter /var/lib/node/

  3. Now, We have to create a service file for node-exporter into sudo vi /etc/systemd/system/node-exporter.service and paste the following content/

     [Unit]
     Description=Prometheus Node Exporter
     Documentation=https://prometheus.io/docs/introduction/overview/
     Wants=network-online.target
     After=network-online.target
    
     [Service]
     Type=simple
     User=prometheus
     Group=prometheus
     ExecReload=/bin/kill -HUP $MAINPID
     ExecStart=/var/lib/node/node_exporter
    
     SyslogIdentifier=prometheus_node_exporter
     Restart=always
    
     [Install]
     WantedBy=multi-user.target
    
  4. Change ownership and grant read access as below to the files.

     sudo chown -R prometheus:prometheus /var/lib/node
     sudo chown -R prometheus:prometheus /var/lib/node/*
     sudo chmod -R 775 /var/lib/node
     sudo chmod -R 775 /var/lib/node/*
    
  5. Restart the daemon, enable node service and start it.

     sudo systemctl daemon-reload
     sudo systemctl enable
     sudo systemctl start
     sudo systemctl status
    

Note: To troubleshoot any issue use journalctl -n 100 command. To start the start the service you should mention the service name you added in the 3rd step.

Access with Prometheus end points