summaryrefslogtreecommitdiff
path: root/files/munin/squid_efficiency
blob: 16b003eed5df542857cbaeecc865b437e127aa85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
#
# Copyright (C) 2006 Benjamin Schweizer. All rights reserved.
#
#
# Abstract
# ~~~~~~~~
# munin plugin that logs the cache efficiency
#
# Authors
# ~~~~~~~
# Benjamin Schweizer <code at benjamin-schweizer dot de>
# duritong <peter.meier at immerda.ch>
#
# Changes
# ~~~~~~~
# 2008-07-24, duritong: added netcat lookup
# 2006-11-16, schweizer: removed 5 minutes stats, fixed 5% bug
# 2006-10-26, schweizer: excluded negative values from result
# 2006-10-11, schweizer: initial release.
#
# Todo
# ~~~~
# - we'll see
#
#%# family=auto
#%# capabilities=autoconf

NETCAT='/bin/netcat'
if [ ! -e $NETCAT ]; then
    NETCAT='/usr/bin/nc'
fi

if [ "$1" = "autoconf" ]; then
	SQUID_STATS=`printf "GET cache_object://localhost/info HTTP/1.0\n\n" | ${NETCAT} localhost 3128`
	if [ -n "${SQUID_STATS}" ]; then
		echo yes 
		exit 0
	else
		echo "no (HTTP GET failed)"
		exit 1
	fi
fi

if [ "$1" = "config" ]; then
	echo 'graph_title Squid Efficiency'
	echo 'graph_info This graph shows the proxy efficiency.'
	echo 'graph_category squid'
	echo "graph_args --lower-limit 0 --upper-limit 100"
	echo 'graph_vlabel %'

	echo 'request.label request hit'

	echo 'byte.label byte hit'

	exit 0
fi

SQUID_STATS=`printf "GET cache_object://localhost/info HTTP/1.0\n\n" | ${NETCAT} localhost 3128`
#        Request Hit Ratios:     5min: 0.0%, 60min: 17.4%
#        Byte Hit Ratios:        5min: 75.0%, 60min: 12.0%

SQUID_REQUEST_HIT=`echo "$SQUID_STATS" | grep "Request Hit Ratios" | cut -d ":" -f4 | cut -d "." -f1 | xargs echo`
if [ ${SQUID_REQUEST_HIT} -lt 1 ]; then SQUID_REQUEST_HIT=0; fi
SQUID_BYTE_HIT=`echo "$SQUID_STATS" | grep "Byte Hit Ratios" | cut -d ":" -f4 | cut -d "." -f1 | xargs echo`
if [ ${SQUID_BYTE_HIT} -lt 1 ]; then SQUID_BYTE_HIT=0; fi

echo "request.value ${SQUID_REQUEST_HIT}"
echo "byte.value ${SQUID_BYTE_HIT}"

# eof.