Thought leadership from the most innovative tech companies, all in one place.

How to Change the Node Exporter Port if It is Already in Use

The Node Exporter is a service from Prometheus that allows for the extraction of node information via an Application Program Interface (API). If you are reading this then you probably are well aware…

image

Photo by Arstin Chen on Unsplash

The Node Exporter is a service from Prometheus that allows for the extraction of node information via an Application Program Interface (API).

If you are reading this then you probably are well aware of this. If you are installing the node exporter then you can read my article here. This will give more information on how I am installing it. If you know my article then you know how I like to make things short and sweet. I hate complex articles. So let's first understand why do I need to change the Node Exporter port. Well in my case I have a Weblogic Server that already utilizes port 9100 for services and well I probably need to allow that to run. So for that case, I need to change the Node Exporter port. There are two main changes to make this work:

  • Change the Service Itself on the Host
  • Change the Prometheus Configuration File So let's begin!
Step 1. Changing the Service Itself on the Host

I currently have my service located at:

/etc/systemd/system/node_exporter.service

So I will be using vi and editing the service like so:

sudo vi /etc/systemd/system/node_exporter.service

Now add the following:

ExecStart=/usr/local/bin/node_exporter --web.listen-address=:7676

Notice that I added the following to the ExecStart:

--web.listen-address=:[custom port]

I did this to make sure that the web.listen-address for the Node_Exporter is on 7676. Of course, you can make this any more you like. Now save and quick the page. If you are new to vi then you just type in escape, add :wq! (which stands for Write and the Quit). Of course, we change the service so now run the following to reload the configuration change:

sudo systemctl daemon-reload

Now restart the node_exporter by running:

sudo systemctl restart node_exporter

Check the status of the service by running:

sudo systemctl status node_exporter

Now check that the service is running on the new port by running:

curl http://localhost:<new port>/metrics

If everything works ok then you will see the metrics being gathered from the API.

Step 2. Change the Prometheus Configuration File

Now we need to tell Prometheus where to grab the configuration from for the server. Go to the configuration file and edit it. Mine will look like this:

sudo vi /etc/prometheus/prometheus.yml

Modify the port with the endpoint with something like the following:

- job_name: 'node_exporter'
    static_configs:
            - targets: ['10.0.1.234:7676','10.0.1.230:9100','10.0.1.232:9100','10.0.1.228:9100','10.0.1.215:9100','10.0.1.50:9100','10.0.1.21:9100','10.0.1.229:9100','10.0.1.226:9100']

Yes, there are several nodes on the setup that I have, but in particular, you can see the 7676 port. Once you have made the change then restart the service by running:

sudo systemctl restart prometheus

That's it. You should be able to navigate to your Prometheus targets and see the active target. Note: Remember if you are running in Azure or AWS that you will need to open up firewalls as well. Well, I hope this helped many out with finding information about quickly changing the node exporter port. If you like then subscribe to stay posted on new topics that are in the now. Thanks!




Continue Learning