steamos-prometheus/install.sh

43 lines
1.2 KiB
Bash
Raw Normal View History

2022-10-23 12:17:39 +00:00
#!/usr/bin/env bash
set -euo pipefail
dir="$(mktemp -d)"
pushd .
cd "${dir}"
BINARY=$(curl https://api.github.com/repos/prometheus/node_exporter/releases/latest | jq -r '.assets[] | select(.name | contains("linux-amd64")) | .browser_download_url')
curl -L $BINARY -o node-exporter.tgz
mkdir -p prometheus/usr/{bin,lib/{systemd/system,extension-release.d}}
tar xzf node-exporter.tgz
cp -vrf node_exporter-*/node_exporter prometheus/usr/bin/node_exporter
2022-10-23 17:53:01 +00:00
cat > /etc/systemd/system/prometheus-node-exporter.service <<- EOM
2022-10-23 12:17:39 +00:00
[Unit]
Description=Prometheus exporter for machine metrics
Requires=network-online.target
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/usr/bin/node_exporter
ExecReload=/bin/kill -HUP \$MAINPID
NoNewPrivileges=true
ProtectHome=read-only
ProtectSystem=strict
[Install]
WantedBy=multi-user.target
EOM
source /etc/os-release
echo -e "SYSEXT_LEVEL=1.0\nID=steamos\nVERSION_ID=${VERSION_ID}" >> prometheus/usr/lib/extension-release.d/extension-release.prometheus-node-exporter
mkdir -p /var/lib/extensions
rm -rf /var/lib/extensions/prometheus-node-exporter
cp -vrf prometheus /var/lib/extensions/prometheus-node-exporter
popd
rm -rf "${dir}"