Created
February 19, 2023 12:14
-
-
Save mnl/eefe866639be8d67ffa8d8ed2b574fb6 to your computer and use it in GitHub Desktop.
Install/update Node Exporter on OpenWRT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Install, start and enable Prometheus Node Exporter | |
# on a OpenWRT system. Does not check for space! | |
# Overwrites any existing versions. Changing release before running should | |
# be enough to update node_exporter version. | |
set -e | |
# node_exporter release version | |
release="1.5.0" | |
# get harware architecture | |
#arch=$(uname -m) | |
arch=armv7 # uname reports armv7l | |
# get node_exporter binary | |
url="https://github.com/prometheus/node_exporter/releases/download/v${release}/node_exporter-${release}.linux-${arch}.tar.gz" | |
wget -O node_exporter.tar.gz --continue $url | |
# check for space | |
required=$(tar -zvtf node_exporter.tar.gz node_exporter-${release}.linux-armv7/node_exporter | \ | |
awk '{print $3/1024}') | |
available=$(df -Pk / | awk '/\/$/{print $4}') | |
if [ $available -lt $required ] | |
then | |
echo "insufficient space for node_exporter $release" | |
exit 1 | |
fi | |
# extract archive | |
mkdir -p staging | |
tar zxf node_exporter.tar.gz -C staging | |
chmod 755 staging/node_exporter-${release}.linux-${arch}/node_exporter | |
# place it in /usr/bin/node_exporter | |
mv staging/node_exporter-${release}.linux-${arch}/node_exporter /usr/bin/ | |
# cleanup | |
rm -r *.gz staging | |
# set up init.d config | |
# Adapted from https://github.com/prometheus/node_exporter/blob/master/examples/openwrt-init.d/node_exporter | |
cat <<'EOF' > /etc/init.d/node_exporter | |
#!/bin/sh /etc/rc.common | |
START=99 | |
USE_PROCD=1 | |
PROG="/usr/bin/node_exporter" | |
OPTIONS="--no-collector.bonding \ | |
--no-collector.fibrechannel \ | |
--no-collector.infiniband \ | |
--no-collector.ipvs \ | |
--no-collector.mdadm \ | |
--no-collector.nfs \ | |
--no-collector.nfsd \ | |
--no-collector.nvme \ | |
--no-collector.pressure \ | |
--no-collector.rapl \ | |
--no-collector.schedstat \ | |
--no-collector.tapestats \ | |
--no-collector.zfs \ | |
--web.listen-address=:9100" | |
start_service() { | |
procd_open_instance | |
procd_set_param command "$PROG" ${OPTIONS} | |
procd_close_instance | |
} | |
EOF | |
chmod 755 /etc/init.d/node_exporter | |
# ensure service is started | |
if [ "$(/etc/init.d/node_exporter status)" != "running" ] | |
then | |
/etc/init.d/node_exporter start | |
else | |
/etc/init.d/node_exporter restart | |
fi | |
# enable service on boot | |
/etc/init.d/node_exporter enable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment