# Due to shell scaping, to pass backslashes for regexes, you need to double
# them (\\d for \d). If running under systemd, you need to double them again
# (\\\\d to mean \d), and escape newlines too.
-ARGS="--web.listen-address=${listen_address}:9100"
+
+# sometime before 1.5 systemd was a default collector
+ARGS="--web.listen-address=${listen_address}:9100 --collector.textfile.directory=/var/lib/prometheus/node-exporter --collector.systemd"
# to see all possible args, run with --help
EOF
if [[ -d /etc/systemd/system ]]; then # we are using systemd
- if [[ -e /lib/systemd/system/prometheus-node-exporter.service ]]; then
- i /etc/systemd/system/prometheus.service.d/override.conf <<'EOF'
-[Unit]
-# needed to continually restart
-StartLimitIntervalSec=0
-[Service]
-Restart=always
-# time to sleep before restarting a service
-RestartSec=600
+ # this is just fixing a screwed up state we shouldnt get into normally.
+ if [[ -e /etc/init.d/prometheus-node-exporter ]]; then
+ sysd_reload=true
+ rm -f /etc/init.d/prometheus-node-exporter
+ fi
-# empty signifies to replace the existing value
-ExecStart=
-ExecStart=/usr/local/bin/prometheus $ARGS
-EOF
- else # we dont have the distro package installed
- i /etc/systemd/system/prometheus.service <<'EOF'
+
+ # I used to have logic to handle having the distro package installed, which would then just override it's service file in some ways. The only differences of the
+ # packaged version in t11 is that it creates /var/log/prometheus and a
+ # logrotate, but nothing is logged there. And it depends on
+ # prometheus-node-exporter-collectors, which is useful, but
+ # depends on prometheus-node-exporter. We would have no
+ # reason to install prometheus-node-exporter except that
+ # dependency. But since the collectors package is just a few
+ # small scripts we don't even currently use, and of course are not
+ # there on old versions, lets not try to use that package, and
+ # just manually install the files we want from upstream.
+ # https://github.com/prometheus-community/node-exporter-textfile-collector-scripts
+
+ if [[ -e /lib/systemd/system/prometheus-node-exporter.service ]]; then
+ apt -y remove --purge prometheus-node-exporter
+ rm -fv /lib/systemd/system/prometheus-node-exporter.service
+ fi
+
+ i /etc/systemd/system/prometheus-node-exporter.service <<'EOF'
[Unit]
Description=Prometheus exporter for machine metrics
Documentation=https://github.com/prometheus/node_exporter
[Install]
WantedBy=multi-user.target
EOF
- fi
if $sysd_reload; then
systemctl daemon-reload
fi