diff --git a/zabbix_conf/squid.conf b/zabbix_conf/squid.conf index 8bd738b..7875cda 100644 --- a/zabbix_conf/squid.conf +++ b/zabbix_conf/squid.conf @@ -1,5 +1,16 @@ # Squid + +# Discover if a squid instance is running and has status handler running on http://127.0.0.1:3128/squid-internal-mgr/info +UserParameter=squid.discovery,/var/lib/zabbix/bin/disco_squid + +# Stats to get +UserParameter=squid.check[*],/var/lib/zabbix/bin/check_squid --uri $1 --what $2 + +################################################ +## LEGACY SQUID ITEMS +################################################ + # Description: Squid Request Hit Ratio # Type: Agent or Agent (active) # Key: squid.request_hit_ratio diff --git a/zabbix_scripts/check_squid b/zabbix_scripts/check_squid new file mode 100644 index 0000000..a71a21a --- /dev/null +++ b/zabbix_scripts/check_squid @@ -0,0 +1,87 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; +use LWP::Simple; +use Getopt::Long; +use JSON; + +my $uri = 'http://127.0.0.1:3128/squid-internal-mgr/info'; +my $what = 'all'; +my $help = 0; +my $pretty = 0; + +GetOptions( + "uri=s" => \$uri, + "what=s" => \$what, + "help" => \$help, + "pretty" => \$pretty +); + +my $res = {}; +my $status = get($uri); + + +unless ($status){ + print 'ZBX_UNSUPPOTED'; + exit 1; +} + +foreach my $line (split(/\n/, $status)){ + if ($line =~ m/^Squid Object Cache: Version (\d+(\.\d+)*)/){ + $res->{version} = $1; + } elsif ($line =~ m/^\s+Number of clients accessing cache:\s+(\d+)/){ + $res->{clients_num} = $1 * 1; + } elsif ($line =~ m/^\s+Number of HTTP requests received:\s+(\d+)/){ + $res->{requests} = $1 * 1; + } elsif ($line =~ m/^\s+Hits as % of all requests:\s+5min:\s+(\d+(\.\d+)?)%,/){ + $res->{hits_req_percent} = $1 * 1; + } elsif ($line =~ m/^\s+Hits as % of bytes sent:\s+5min:\s+(\d+(\.\d+)?)%,/){ + $res->{hits_bytes_percent} = $1 * 1; + } elsif ($line =~ m/^\s+Memory hits as % of hit requests:\s+5min:\s+(\d+(\.\d+)?)%,/){ + $res->{mem_hits_req_percent} = $1 * 1; + } elsif ($line =~ m/^\s+Disk hits as % of hit requests:\s+5min:\s+(\d+(\.\d+)?)%,/){ + $res->{disk_hits_req_percent} = $1 * 1; + } elsif ($line =~ m/^\s+Storage Swap size:\s+(\d+)\sKB/){ + $res->{stor_swap_size} = $1 * 1024; + } elsif ($line =~ m/^\s+Storage Swap capacity:\s+(\d+(\.\d+)?)% used, (\d+(\.\d+)?)% free/){ + ($res->{stor_swap_used_percent}, $res->{stor_swap_free_percent}) = ($1 * 1, $3 * 1); + } elsif ($line =~ m/^\s+Storage Mem size:\s+(\d+)\sKB/){ + $res->{stor_mem_size} = $1 * 1024; + } elsif ($line =~ m/^\s+Storage Mem capacity:\s+(\d+(\.\d+)?)% used, (\d+(\.\d+)?)% free/){ + ($res->{stor_mem_used_percent}, $res->{stor_mem_free_percent}) = ($1 * 1, $3 * 1); + } elsif ($line =~ m/^\s+Mean Object Size:\s+(\d+(\.\d+)?)\sKB/){ + $res->{mean_object_size} = int($1 * 1024); + } elsif ($line =~ m/^\s+CPU Time:\s+(\d+(\.\d+)?)\sseconds/){ + $res->{cpu_time} = $1 * 1; + } elsif ($line =~ m/^\s+CPU Usage:\s+(\d+(\.\d+)?)%/){ + $res->{cpu_usage} = $1 * 1; + } elsif ($line =~ m/^\s+CPU Usage, 5 minute avg:\s+(\d+(\.\d+)?)%/){ + $res->{cpu_usage_avg_5min} = $1 * 1; + } elsif ($line =~ m/^\s+Maximum number of file descriptors:\s+(\d+)/){ + $res->{fd_max} = $1 * 1; + } elsif ($line =~ m/^\s+Number of file desc currently in use:\s+(\d+)/){ + $res->{fd_used} = $1 * 1; + } +} + +if (defined $res->{fd_max} and defined $res->{fd_used}){ + $res->{fd_used_percent} = int($res->{fd_used} * 100/ $res->{fd_max}); +} + +if ($help){ + print "Valid keys are:\n\n"; + print "$_\n" for keys %{$res}; + exit 0; +} + +if ($what eq 'all'){ + print to_json($res, { pretty => $pretty }); +} +elsif (defined $res->{$what}){ + print $res->{$what}; +} +else{ + print 'ZBX_UNSUPPOTED'; +} +exit 0; diff --git a/zabbix_scripts/disco_squid b/zabbix_scripts/disco_squid new file mode 100644 index 0000000..4f668eb --- /dev/null +++ b/zabbix_scripts/disco_squid @@ -0,0 +1,18 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; +use LWP::Simple; +use JSON; + +my $json; +@{$json->{data}} = (); + +my $status = get('http://127.0.0.1:3128/squid-internal-mgr/info'); + +if ($status){ + push @{$json->{data}}, {"{#SQUID_STATUS_URI}" => 'http://127.0.0.1:3128/squid-internal-mgr/info'}; +} + +print to_json($json); +exit(0);