Created
July 27, 2020 09:50
-
-
Save zoni/8fc2c9c4b978cc174a2cc5fd6c733ce8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
: ${TEXT_COLLECTOR_DIR:="/var/tmp/node_exporter"} | |
OUTPUT_FILE=${TEXT_COLLECTOR_DIR}/apt.prom | |
TEMP_OUTPUT_FILE=${OUTPUT_FILE}.tmp | |
upgrades=$(/usr/lib/update-notifier/apt-check 2>&1) | |
# output format for apt-check is $upgrades;$security_upgrades | |
( | |
echo '# HELP apt_packages_available_for_upgrade_count Apt upgrades pending.' | |
echo '# TYPE apt_packages_available_for_upgrade_count gauge' | |
echo 'apt_packages_available_for_upgrade_count' $(echo $upgrades|cut -d';' -f1) | |
echo '# HELP apt_security_packages_available_for_upgrade_count Apt security upgrades pending.' | |
echo '# TYPE apt_security_packages_available_for_upgrade_count gauge' | |
echo 'apt_security_packages_available_for_upgrade_count' $(echo $upgrades|cut -d';' -f2) | |
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 | |
# note that this gets updated even if apt fails (partially) so if this timestamp is | |
# fresh that is no guarantee all of the package list is | |
apt_update_stamp=$(date +%s -r /var/lib/apt/periodic/update-success-stamp 2>/dev/null || echo 0) | |
echo '# HELP apt_update_timestamp Timestamp apt sources were last updated successfully' | |
echo '# TYPE apt_update_timestamp gauge' | |
echo 'apt_update_timestamp' $apt_update_stamp | |
) >${TEMP_OUTPUT_FILE} | |
mv ${TEMP_OUTPUT_FILE} ${OUTPUT_FILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment