Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Zabbix Network Monitoring Essentials

You're reading from   Zabbix Network Monitoring Essentials Your one-stop solution to efficient network monitoring with Zabbix

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher
ISBN-13 9781784399764
Length 178 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Andrea Dalle Vacche Andrea Dalle Vacche
Author Profile Icon Andrea Dalle Vacche
Andrea Dalle Vacche
Stefano Kewan Lee Stefano Kewan Lee
Author Profile Icon Stefano Kewan Lee
Stefano Kewan Lee
Arrow right icon
View More author details
Toc

Squid metric script


Here, you can find the script we discussed in Chapter 3, Monitoring Your Network Services, and create the script in the usual location, that is, at /home/zabbix/bin/squidcheck.sh.

Create the script with the following content:

cat squidcheck.sh
#!/bin/bash
VERSION="1.0"

function usage()
{
  echo "squidcheck  version: $VERSION"
  echo "usage:"
  echo "  $0 http_requests              - Number of HTTP requests received"
  echo "  $0 clients                    - Number of clients accessing cache"
  echo "  $0 icp_received               - Number of ICP messages received"
  echo "  $0 icp_sent                   - Number of ICP messages sent"
  echo "  $0 icp_queued                 - Number of queued ICP replies"
  echo "  $0 htcp_received              - Number of HTCP messages received"
  echo "  $0 htcp_sent                  - Number of HTCP messages sent"
  echo "  $0 req_fail_ratio             - Request failure ratio"
  echo "  $0 avg_http_req_per_min       - Average HTTP requests per minute since start"
  echo "  $0 avg_icp_msg_per_min        - Average ICP messages per minute since start"
  echo "  $0 request_hit_ratio          - Request Hit Ratios"
  echo "  $0 byte_hit_ratio_5           - Byte Hit Ratio 5 mins"
  echo "  $0 byte_hit_ratio_60          - Byte Hit Ratio 60 mins"
  echo "  $0 request_mem_hit_ratio_5    - Request Memory Hit Ratios 5 mins"
  echo "  $0 request_mem_hit_ratio_60   - Request Memory Hit Ratios 60 mins"
  echo "  $0 request_disk_hit_ratio_5   - Request Disk Hit Ratios 5 mins"
  echo "  $0 request_disk_hit_ratio_60  - Request Disk Hit Ratios 60 mins"
  echo "  $0 servicetime_httpreq        - HTTP Requests (All)"
  echo "  $0 process_mem                - Process Data Segment Size via sbrk"
  echo "  $0 cpu_usage                  - CPU Usage"
  echo "  $0 cache_size_disk            - Storage Swap size"
  echo "  $0 cache_size_mem             - Storage Mem size"
  echo "  $0 mean_obj_size              - Mean Object Size"
  echo "  $0 filedescr_max              - Maximum number of file descriptors"
  echo "  $0 filedescr_avail            - Available number of file descriptors"
}

########
# Main #
########

if [[ $# !=  1 ]];then
        #No Parameter
        usage
        exit 0
fi
case $1 in
"http_requests")
    value="`squidclient mgr:info|grep 'Number of HTTP requests received:'|cut -d':' -f2| tr -d ' \t'`"
        rval=$?;;
"clients")
    value="`squidclient mgr:info|grep 'Number of clients accessing cache:'|cut -d':' -f2| tr -d ' \t'`"
        rval=$?;;
"icp_received")
        value="`squidclient mgr:info|grep 'Number of ICP messages received:'|cut -d':' -f2| tr -d ' \t'`"
        rval=$?;;
"icp_sent")
        value="`squidclient mgr:info|grep 'Number of ICP messages sent:'|cut -d':' -f2| tr -d ' \t'`"
        rval=$?;;
"icp_queued")
        value="`squidclient mgr:info|grep 'Number of queued ICP replies:'|cut -d':' -f2| tr -d ' \t'`"
        rval=$?;;
"htcp_received")
        value="`squidclient mgr:info|grep 'Number of HTCP messages received:'|cut -d':' -f2| tr -d ' \t'`"
        rval=$?;;
"htcp_sent")
        value="`squidclient mgr:info|grep 'Number of HTCP messages sent:'|cut -d':' -f2| tr -d ' \t'`"
        rval=$?;;
"req_fail_ratio")
        value="`squidclient mgr:info|grep 'Request failure ratio:'|cut -d':' -f2| tr -d ' \t'`"
        rval=$?;;
"avg_http_req_per_min")
        value="`squidclient mgr:info|grep 'Average HTTP requests per minute since start:'|cut -d':' -f2| tr -d ' \t'`"
        rval=$?;;
"avg_icp_msg_per_min")
        value="`squidclient mgr:info|grep 'Average ICP messages per minute since start:'|cut -d':' -f2| tr -d ' \t'`"
        rval=$?;;
"request_hit_ratio")
        value="`squidclient mgr:info|grep 'Request Hit Ratios:'|cut -d':' -f3|cut -d',' -f1|tr -d ' %'`"
        rval=$?;;
"byte_hit_ratio_5")
        value="`squidclient mgr:info|grep 'Hits as % of bytes sent:'|  awk -F'[:,% ]' '{print $10}'| tr -d ' \t'`"
        rval=$?;;
"byte_hit_ratio_60")
        value="`squidclient mgr:info|grep 'Hits as % of bytes sent:'|  awk -F'[:,% ]' '{print $15}'| tr -d ' \t'`"
        rval=$?;;
"request_mem_hit_ratio_5")
        value="`squidclient mgr:info|grep 'Hits as % of all requests:' |  awk -F'[:,% ]' '{print $10}'| tr -d ' \t'`"
        rval=$?;;
"request_mem_hit_ratio_60")
        value="`squidclient mgr:info|grep 'Hits as % of all requests:' |  awk -F'[:,% ]' '{print $15}'| tr -d ' \t'`"
        rval=$?;;
"request_disk_hit_ratio_5")
        value="`squidclient mgr:info|grep 'Disk hits as % of hit requests:'|awk -F'[:,% ]' '{print $11}'| tr -d ' \t'`"
        rval=$?;;
"request_disk_hit_ratio_60")
        value="`squidclient mgr:info|grep 'Disk hits as % of hit requests:'|awk -F'[:,% ]' '{print $16}'| tr -d ' \t'`"
        rval=$?;;
"servicetime_httpreq")
        value="`squidclient mgr:info|grep 'HTTP Requests (All):'|cut -d':' -f2|tr -s ' '|awk '{print $1}'`"
        rval=$?;;
"process_mem")
        value="`squidclient mgr:info|grep 'Process Data Segment Size via sbrk'|cut -d':' -f2|awk '{print $1}'`"
        rval=$?;;
"cpu_usage")
        value="`squidclient mgr:info|grep 'CPU Usage:'|cut -d':' -f2|tr -d '%'|tr -d ' \t'`"
        rval=$?;;
"cache_size_disk")
        value="`squidclient mgr:info|grep 'Storage Swap size:'|cut -d':' -f2|awk '{print $1}'`"
        rval=$?;;
"cache_size_mem")
        value="`squidclient mgr:info|grep 'Storage Mem size:'|cut -d':' -f2|awk '{print $1}'`"
        rval=$?;;
"mean_obj_size")
        value="`squidclient mgr:info|grep 'Mean Object Size:'|cut -d':' -f2|awk '{print $1}'`"
        rval=$?;;
"filedescr_max")
        value="`squidclient mgr:info|grep 'Maximum number of file descriptors:'|cut -d':' -f2|awk '{print $1}'`"
        rval=$?;;
"filedescr_avail")
        value="`squidclient mgr:info|grep 'Available number of file descriptors:'|cut -d':' -f2|awk '{print $1}'`"
        rval=$?;;
*)
        usage
        exit 1;;
esac

if [ "$rval" -eq 0 -a -z "$value" ]; then
        rval=1
fi

if [ "$rval" -ne 0 ]; then
        echo "ZBX_NOTSUPPORTED"
fi

echo $value
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images