My home router is a Ubiquiti EdgeMAX router running EdgeOS 2.0.6. I chose it because wanted a router that could run sflow for testing purposes. I recently came across someone successfully installing Prometheus node_exporter on EdgeOS, so I gave it a try. Since I’d already ansible-automated the install of node_exporter on a switch running Cumulus Linux, I wrote a new playbook with only minor modifications for EdgeOS and it worked perfectly.
Example code used here can be found on Gitlab
This is the content of my ansible
hosts file. Note you will need to set the router login name to something other than
admin if your setup differs.
You will also need to replace
router01.domain.com with your correct router hostname, and possibly specify it’s IP address if it doesn’t have a DNS entry. Refer to Ansible’s docs on how to build your inventory.
Below is the content of my ansible playbook called
setup.yml, with comments inline:
- hosts: router01
- name: "Copy SSH public key to router"
The above task isn’t needed, but something helpful to allow ansible to ssh to your router without needing a password.
The current version of Prometheus node_exporter as of the time of this blog post is
1.0.1. You may want to update this to a newer release.
- name: add node_exporter user
I chose to run node_exporter as a different user on the router, so that logging and security could be easily separated out.
- name: download and unzip node_exporter
Note that this task both downloads and unzips the node_exporter release. In addition, it’s downloading the mips64 binary, since that’s the correct CPU architecture for the Ubituiti EdgeMAX router I have. Finally, it will only re-download the tgz file if it’s not already been downloaded, saving time if you want this part of a larger ansible playbook that’s run regularly. This is accomplished by using the
creates: option to check if a specific file exists. If the file is present, it won’t try and re-download the tgz file and unzip it again.
- name: copy node_exporter to bin directory
- name: change node_exporter ownership
- name: create node_exporter service
ExecStart=/usr/bin/node_exporter --collector.systemd --collector.logind --no-collector.bonding --no-collector.hwmon --no-collector.infiniband --no-collector.ipvs --no-collector.mdadm --no-collector.nfs --no-collector.nfsd --no-collector.powersupplyclass --no-collector.zfs --no-collector.xfs --no-collector.thermal_zone --no-collector.schedstat --no-collector.rapl --no-collector.btrfs --no-collector.bcache --no-collector.cpufreq --no-collector.edac
- name: systemctl daemon-reload
shell: systemctl daemon-reload
- name: start node_exporter
At this point, you should be able to pull up a browser to http://192.168.1.1:9100 and get a page loaded if the installation was successful:
Note that you must configure your Prometheus server to periodically poll
node_exporter running on your Ubiquiti router in order to gather the stats. Here is an example of the relevant part of my
/etc/prometheus/prometheus.yml configuration in the
- job_name: router
- targets: ['192.168.1.1:9100']