root / plugins / squid / squid_efficiency @ 17f78427
Historique | Voir | Annoter | Télécharger (4,28 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# |
| 3 |
# Copyright (C) 2006-2009 Benjamin Schweizer. All rights reserved. |
| 4 |
# |
| 5 |
# Permission to use, copy, modify, and/or distribute this software for any |
| 6 |
# purpose with or without fee is hereby granted, provided that the above |
| 7 |
# copyright notice and this permission notice appear in all copies. |
| 8 |
# |
| 9 |
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 |
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 |
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 |
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 |
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 |
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 |
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 |
# |
| 17 |
# |
| 18 |
# Abstract |
| 19 |
# ~~~~~~~~ |
| 20 |
# This is a plugin for the munin monitoring system. It graphs the cache |
| 21 |
# efficiency of your squid proxy servers and shows nice graphs for average |
| 22 |
# byte and request hits. |
| 23 |
# |
| 24 |
# Authors |
| 25 |
# ~~~~~~~ |
| 26 |
# Benjamin Schweizer, http://benjamin-schweizer.de/contact |
| 27 |
# |
| 28 |
# Changes |
| 29 |
# ~~~~~~~ |
| 30 |
# 2010-10-11: paulm: uses squidclient instead of netcat; some beautification. |
| 31 |
# 2010-01-20, homyakov: added disk and memory stats |
| 32 |
# 2009-11-25, volker: added config options and docs |
| 33 |
# 2009-11-19, benjamin: fixed squid3 compatibility, minor rewrite |
| 34 |
# 2006-11-16, benjamin: removed 5 minutes stats, fixed 5% bug |
| 35 |
# 2006-10-26, benjamin: excluded negative values from result |
| 36 |
# 2006-10-11, benjamin: initial release. |
| 37 |
# |
| 38 |
# Todo |
| 39 |
# ~~~~ |
| 40 |
# - we'll see |
| 41 |
# |
| 42 |
# Munin: |
| 43 |
#%# family=auto |
| 44 |
#%# capabilities=autoconf |
| 45 |
# |
| 46 |
# Config |
| 47 |
# ~~~~~~ |
| 48 |
# This plugin supports munin-autoconf, but you might need to change the host |
| 49 |
# and port according to your actual setup. You can overwrite the defaults |
| 50 |
# in your node config (/etc/munin/plugin-conf.d/) like this: |
| 51 |
# |
| 52 |
# [squid_efficiency] |
| 53 |
# env.squidhost yourhost.example.com |
| 54 |
# env.squidport 8080 |
| 55 |
# |
| 56 |
|
| 57 |
host=${squidhost:-localhost}
|
| 58 |
port=${squidport:-3128}
|
| 59 |
|
| 60 |
test "$1" = "config" && {
|
| 61 |
echo 'graph_title Squid Efficiency' |
| 62 |
echo 'graph_info This graph shows the proxy efficiency over the last five mins.' |
| 63 |
echo 'graph_category loadbalancer' |
| 64 |
echo "graph_args --lower-limit 0 --upper-limit 100" |
| 65 |
echo 'graph_vlabel %' |
| 66 |
echo 'request.label request hits' |
| 67 |
echo 'byte.label byte hits' |
| 68 |
echo 'memory.label memory request hits' |
| 69 |
echo 'disk.label disk request hits' |
| 70 |
exit 0 |
| 71 |
} |
| 72 |
|
| 73 |
# squid2 |
| 74 |
# Request Hit Ratios: 5min: 0.0%, 60min: 17.4% |
| 75 |
# Byte Hit Ratios: 5min: 75.0%, 60min: 12.0% |
| 76 |
# squid3 |
| 77 |
# Hits as % of all requests: 5min: 0.0%, 60min: 0.0% |
| 78 |
# Hits as % of bytes sent: 5min: 100.0%, 60min: 100.0% |
| 79 |
|
| 80 |
DUMP=`squidclient -p $port -l $host cache_object://$host/info` |
| 81 |
|
| 82 |
# Request efficiency |
| 83 |
SQUID_LINE=`echo "$DUMP" | grep -E "Request Hit Ratios|Hits as % of all requests"` |
| 84 |
if [ $? -eq 0 ] ; then |
| 85 |
# for the last hour: |
| 86 |
#REQUEST_HITS=`echo $SQUID_LINE | cut -d ":" -f4 | cut -d "." -f1` |
| 87 |
# for the last five mins: |
| 88 |
REQUEST_HITS=`echo $SQUID_LINE | cut -d ":" -f3 | cut -d "." -f1` |
| 89 |
test "$REQUEST_HITS" -gt 0 || REQUEST_HITS=0 |
| 90 |
echo "request.value ${REQUEST_HITS}"
|
| 91 |
fi |
| 92 |
|
| 93 |
# Byte efficiency |
| 94 |
SQUID_LINE=`echo "$DUMP" | grep -E "Byte Hit Ratios|Hits as % of bytes sent"` |
| 95 |
if [ $? -eq 0 ] ; then |
| 96 |
# for the last hour: |
| 97 |
#BYTE_HITS=`echo $SQUID_LINE | cut -d ":" -f4 | cut -d "." -f1` |
| 98 |
# for the last five mins: |
| 99 |
BYTE_HITS=`echo $SQUID_LINE | cut -d ":" -f3 | cut -d "." -f1` |
| 100 |
test "$BYTE_HITS" -gt 0 || BYTE_HITS=0 |
| 101 |
echo "byte.value ${BYTE_HITS}"
|
| 102 |
fi |
| 103 |
|
| 104 |
# Memory |
| 105 |
SQUID_LINE=`echo "$DUMP" | grep -E "Request Memory Hit Ratios|Memory hits as % of hit requests"` |
| 106 |
if [ $? -eq 0 ] ; then |
| 107 |
# for the last hour: |
| 108 |
#MEM_REQUEST_HITS=`echo "$SQUID_LINE" | cut -d ":" -f4 | cut -d "." -f1 | xargs echo` |
| 109 |
# for the last five mins: |
| 110 |
MEM_REQUEST_HITS=`echo "$SQUID_LINE" | cut -d ":" -f3 | cut -d "." -f1 | xargs echo` |
| 111 |
test $MEM_REQUEST_HITS -gt 0 || MEM_REQUEST_HITS=0 |
| 112 |
echo "memory.value ${MEM_REQUEST_HITS}"
|
| 113 |
fi |
| 114 |
|
| 115 |
# Disk |
| 116 |
SQUID_LINE=`echo "$DUMP" | grep -E "Request Disk Hit Ratios|Disk hits as % of hit requests"` |
| 117 |
if [ $? -eq 0 ] ; then |
| 118 |
# for the last hour: |
| 119 |
#DISK_REQUEST_HITS=`echo "$SQUID_LINE" | cut -d ":" -f4 | cut -d "." -f1 | xargs echo` |
| 120 |
# for the last five mins: |
| 121 |
DISK_REQUEST_HITS=`echo "$SQUID_LINE" | cut -d ":" -f3 | cut -d "." -f1 | xargs echo` |
| 122 |
test $DISK_REQUEST_HITS -gt 0 || DISK_REQUEST_HITS=0 |
| 123 |
echo "disk.value ${DISK_REQUEST_HITS}"
|
| 124 |
fi |
| 125 |
|
| 126 |
|
| 127 |
# eof. |
