2017-10-03 23:34:30 -07:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Description: Expose metrics from apt updates.
|
|
|
|
#
|
|
|
|
# Author: Ben Kochie <superq@gmail.com>
|
|
|
|
|
|
|
|
upgrades="$(/usr/bin/apt-get --just-print upgrade \
|
2017-12-12 01:45:59 -08:00
|
|
|
| /usr/bin/awk -F'[()]' \
|
|
|
|
'/^Inst/ { sub("^[^ ]+ ", "", $2); sub("\\[", " ", $2);
|
2018-02-05 11:43:25 -08:00
|
|
|
sub(" ", "", $2); sub("\\]", "", $2); print $2 }' \
|
2017-10-03 23:34:30 -07:00
|
|
|
| /usr/bin/sort \
|
|
|
|
| /usr/bin/uniq -c \
|
|
|
|
| awk '{ gsub(/\\\\/, "\\\\", $2); gsub(/\"/, "\\\"", $2);
|
|
|
|
gsub(/\[/, "", $3); gsub(/\]/, "", $3);
|
|
|
|
print "apt_upgrades_pending{origin=\"" $2 "\",arch=\"" $3 "\"} " $1}'
|
|
|
|
)"
|
|
|
|
|
|
|
|
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 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
|