Zionetrix::Git
Repositories
Help
Report an Issue
check_apt_cacher_ng
Code
Commits
Branches
Tags
Search
Tree:
27fced7
Branches
Tags
master
check_apt_cacher_ng
check-apt-cacher-ng
Initial commit
Benjamin Renard
commited
27fced7
at 2015-06-30 14:43:45
check-apt-cacher-ng
Blame
History
Raw
#!/bin/bash HOST=127.0.0.1 PORT=3142 DO_PERFDATA=0 DEBUG=0 function usage() { cat << EOF Usage : check_apt_cacher_ng [-H hostaddress] [-p port] [-Pdh] -H hostaddress Specify apt-cacher-ng host address (default=127.0.0.1) -p post Specify apt-cacher-ng TCP port (default=3142) -P Include performance data -d Enable debug mode -h Show this help message EOF } while getopts "H:p:Pdh" OPTION do case $OPTION in H) HOST=$OPTARG ;; p) PORT=$OPTARG ;; P) DO_PERFDATA=1 ;; d) DEBUG=1 ;; h) usage exit 0 ;; \?) echo "Invalid option: -$OPTARG" >&2 usage exit 1 ;; :) echo "Option -$OPTARG requires an argument." >&2 usage exit 1 ;; esac done function debug() { [ $DEBUG -eq 1 ] && echo "[DEBUG] $1" } html2text -version > /dev/null 2>&1 if [ $? -ne 0 ] then echo "UNKNOWN : html2text command not found" exit 3 fi debug "Get apt-cacher-ng stats from $HOST:$PORT" stats=$( wget -q -O - http://$HOST:$PORT/acng-report.html?doCount=Count+Data#top ) if [ $? -ne 0 ] then echo "CRITICAL : Fail to connect to apt-cacher-ng" exit 2 fi stats_line=$( echo -e "$stats"|html2text -width 300|grep '^ *Period' -A 2|tail -n 1 ) if [ -z "$stats_line" ] then echo "WARNING : Fail to parse apt-cacher-ng stats page" exit 1 fi if [ $DO_PERFDATA -eq 1 ] then cache_req_hits_count=$( echo -e "$stats_line"|awk '{print $6}'|sed 's/^[^0-9]*//' ) cache_req_hits_per=$( echo -e "$stats_line"|cut -d '(' -f 2|cut -d')' -f 1|sed 's/^[^0-9]*//' ) cache_req_misses_count=$( echo -e "$stats_line"|awk '{print $8}'|sed 's/^[^0-9]*//' ) cache_req_misses_per=$( echo -e "$stats_line"|cut -d '(' -f 3|cut -d')' -f 1|sed 's/^[^0-9]*//' ) cache_req_total_count=$( echo -e "$stats_line"|awk '{print $10}'|sed 's/^[^0-9]*//' ) cache_data_hits_count=$( echo -e "$stats_line"|awk '{print $11$12}'|sed 's/^[^0-9]*//' ) cache_data_hits_per=$( echo -e "$stats_line"|cut -d '(' -f 4|cut -d')' -f 1|sed 's/^[^0-9]*//' ) cache_data_misses_count=$( echo -e "$stats_line"|awk '{print $14$15}'|sed 's/^[^0-9]*//' ) cache_data_misses_per=$( echo -e "$stats_line"|cut -d '(' -f 4|cut -d')' -f 1|sed 's/^[^0-9]*//' ) cache_data_total_count=$( echo -e "$stats_line"|awk '{print $17$18}'|sed 's/^[^0-9]*//' ) PERF_DATA="|cache_req_hits_count=$cache_req_hits_count" PERF_DATA="$PERF_DATA,cache_req_hits_per=$cache_req_hits_per" PERF_DATA="$PERF_DATA,cache_req_misses_count=$cache_req_misses_count" PERF_DATA="$PERF_DATA,cache_req_misses_per=$cache_req_misses_per" PERF_DATA="$PERF_DATA,cache_req_total_count=$cache_req_total_count" PERF_DATA="$PERF_DATA,cache_data_hits_count=$cache_data_hits_count" PERF_DATA="$PERF_DATA,cache_data_hits_per=$cache_data_hits_per" PERF_DATA="$PERF_DATA,cache_data_misses_count=$cache_data_misses_count" PERF_DATA="$PERF_DATA,cache_data_misses_per=$cache_data_misses_per" PERF_DATA="$PERF_DATA,cache_data_total_count=$cache_data_total_count" else PERF_DATA="" fi echo "OK - Apt-cacher-ng is running$PERF_DATA" exit 0