Caching Server Status Metrics

New Contributor

My management team have challenged our groups with identifying some Key Points of Interest that we can collect metrics and report on. AS a part of this. I have been looking for a way to get better reporting as to how much data we have server from cache on our Apple Caching server. The built-in 'Bytes Served' graph in the Stats sections is pretty but I was looking for some specific numbers that i could report on. I created the following script and set it to run once a week agains my Caching server. The script collects the data from the serveradmin status command, converts the number to GB integer and emails me the report. I verified that these numbers are cleared on a server (or just service) restart. So the script also uses the last reboot date as a time reference for the metric period. You'll want to configure a reboot as part of the policy to execute the script. You will also want to be familiar with the mail command and how that will work in your environment. I am certain there are some inefficiencies in my script so feel free to recommend changes!


Apple Software Update Server Cache Metrics report created by Michael Barrett 08.14.15

Set Variables

uptime=$(last reboot | head -1 | cut -c 37-53)

host=$(hostname | awk '{print$1}')

Origin=$(serveradmin fullstatus caching | grep -A 0 'TotalBytesFromOrigin' | awk '{print$3}')

Total=$(serveradmin fullstatus caching | grep -A 0 'TotalBytesReturned' | awk '{print$3}')

cachefreeraw=$(serveradmin fullstatus caching | grep -A 0 'CacheFree' | awk '{print$3}')

Perform Calculations

Cachedraw=$(expr $Total - $Origin)

echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))

cached=$(round $Cachedraw.000000001 2);
origintotal=$(round $Origin
.000000001 2);
cachefree=$(round $cachefreeraw*.000000001 2);

Email the Metrics

echo A total of $origintotal GB of data have been downloaded, and $cached GB of cached data have been served since $uptime on server $host. There is $cachefree GB remaining before least used cached data is erased. | mail -s $host Metrics