Last active
March 5, 2020 06:02
-
-
Save amaslenn/82c8b25edeedf9f254fc7f2bca03ab40 to your computer and use it in GitHub Desktop.
Setup a node_exporter systemd service
This file contains hidden or 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/bash -eEl | |
function node_exporter_name() { | |
arch=$(uname -m) | |
if [ "${arch}" = "aarch64" ]; then | |
arch="arm64" | |
elif [ "${arch}" = "x86_64" ]; then | |
arch="amd64" | |
fi | |
echo "node_exporter-0.18.1.linux-${arch}" | |
} | |
function node_exporter_link() { | |
url="https://github.com/prometheus/node_exporter/releases/download" | |
version="v0.18.1" | |
tar="$(node_exporter_name).tar.gz" | |
echo "${url}/${version}/${tar}" | |
} | |
rm -f "$(node_exporter_name)*" | |
echo "Pulling node_exporter tarball..." | |
wget -nv "$(node_exporter_link)" | |
echo "Unpacking..." | |
tar xzf "$(node_exporter_name).tar.gz" | |
echo "Creating and setting up the service..." | |
cd "$(node_exporter_name)" | |
svc_name="node_exporter.service" | |
cat >${svc_name} <<EOF | |
[Unit] | |
Description=Node Exporter | |
Wants=network-online.service | |
After=network-online.service | |
[Service] | |
ExecStart=/usr/sbin/node_exporter --collector.systemd \$OPTIONS | |
User=$USER | |
KillMode=process | |
KillSignal=SIGTERM | |
TimeoutStopSec=5min | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
sudo ln -fs `pwd`/node_exporter /usr/sbin/node_exporter | |
sudo cp ${svc_name} /etc/systemd/system/ | |
sudo systemctl daemon-reload | |
sudo systemctl start ${svc_name} | |
sudo systemctl status ${svc_name} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment