Add orphans apt packages metric

certbot_on_virtu
Alexandre Iooss 2020-01-19 18:56:23 +01:00
parent 3c2f218a2f
commit e55bef009a
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
1 changed files with 11 additions and 0 deletions

View File

@ -19,6 +19,13 @@ autoremove="$(/usr/bin/apt-get --just-print autoremove \
| /usr/bin/awk '/^Remv/{a++}END{printf "apt_autoremove_pending %d", a}' | /usr/bin/awk '/^Remv/{a++}END{printf "apt_autoremove_pending %d", a}'
)" )"
orphans="$(comm -23 \
<(dpkg-query -W -f '${db:Status-Abbrev}\t${Package}\n' \
| grep '^.[^nc]' | cut -f2 | sort) \
<(apt-cache dumpavail | sed -rn 's/^Package: (.*)/\1/p' | sort -u) \
| awk 'END{printf "apt_orphans %d", NR}'
)"
echo '# HELP apt_upgrades_pending Apt package pending updates by origin.' echo '# HELP apt_upgrades_pending Apt package pending updates by origin.'
echo '# TYPE apt_upgrades_pending gauge' echo '# TYPE apt_upgrades_pending gauge'
if [[ -n "${upgrades}" ]] ; then if [[ -n "${upgrades}" ]] ; then
@ -31,6 +38,10 @@ echo '# HELP apt_autoremove_pending Apt package pending autoremove.'
echo '# TYPE apt_autoremove_pending gauge' echo '# TYPE apt_autoremove_pending gauge'
echo "${autoremove}" echo "${autoremove}"
echo '# HELP apt_orphans Orphan apt package.'
echo '# TYPE apt_orphans gauge'
echo "${orphans}"
echo '# HELP node_reboot_required Node reboot is required for software updates.' echo '# HELP node_reboot_required Node reboot is required for software updates.'
echo '# TYPE node_reboot_required gauge' echo '# TYPE node_reboot_required gauge'
if [[ -f '/run/reboot-required' ]] ; then if [[ -f '/run/reboot-required' ]] ; then