added apt.sh

This commit is contained in:
Samuel Philipp 2021-06-12 03:00:17 +02:00
parent a1bb84ab0e
commit c4572898d5
Signed by: samuel-p
GPG key ID: 2AD495D17760CB4E
2 changed files with 42 additions and 1 deletions

View file

@ -19,7 +19,7 @@ __node_exporter__
|---|---| |---|---|
|[active-sessions.sh](node_exporter/active-sessions.sh)|Script to export all active sessions to prometheus| |[active-sessions.sh](node_exporter/active-sessions.sh)|Script to export all active sessions to prometheus|
|[directory-size.sh](node_exporter/directory-size.sh)|Script to export directory sizes to prometheus| |[directory-size.sh](node_exporter/directory-size.sh)|Script to export directory sizes to prometheus|
|[apt.sh](node_exporter/apt.sh)|Script to export pending apt updates to prometheus|
## Setup ## Setup

41
node_exporter/apt.sh Normal file
View file

@ -0,0 +1,41 @@
#!/bin/bash
#
# adapted from https://github.com/prometheus-community/node-exporter-textfile-collector-scripts/blob/master/apt.sh
#
/usr/bin/apt-get update > /dev/null 2>&1
upgrades="$(/usr/bin/apt-get --just-print dist-upgrade \
| /usr/bin/awk -F'[()]' \
'/^Inst/ { sub("^[^ ]+ ", "", $2); gsub(" ","",$2);
sub("\\[", " ", $2); sub("\\]", "", $2); print $2 }' \
| /usr/bin/sort \
| /usr/bin/uniq -c \
| awk '{ gsub(/\\\\/, "\\\\", $2); gsub(/"/, "\\\"", $2);
gsub(/\[/, "", $3); gsub(/\]/, "", $3);
print "apt_upgrades_pending{origin=\"" $2 "\",arch=\"" $NF "\"} " $1}'
)"
autoremove="$(/usr/bin/apt-get --just-print autoremove \
| /usr/bin/awk '/^Remv/{a++}END{printf "apt_autoremove_pending %d", a}'
)"
echo '# HELP apt_upgrades_pending Apt package pending updates by origin.'
echo '# TYPE apt_upgrades_pending gauge'
if [[ -n "${upgrades}" ]] ; then
echo "${upgrades}"
else
echo 'apt_upgrades_pending{origin="",arch=""} 0'
fi
echo '# HELP apt_autoremove_pending Apt package pending autoremove.'
echo '# TYPE apt_autoremove_pending gauge'
echo "${autoremove}"
echo '# HELP node_reboot_required Node reboot is required for software updates.'
echo '# TYPE node_reboot_required gauge'
if [[ -f '/run/reboot-required' ]] ; then
echo 'node_reboot_required 1'
else
echo 'node_reboot_required 0'
fi