使用Zabbix监控Apache
由于用户参数的获取时间会有所偏差,因此我们进行了更改,采用了zabbix_sender的方式。
前提条件是以下脚本在Zabbix中注册的主机名与通过hostname获取的主机名相匹配。如果不同,请相应地更改hostname部分。
#!/bin/sh
zabbix_server=${Your_zabbix_server_or_proxy_address_here}
my_zabbix_hostname=`hostname`
interval_seconds=60
while :
do
curl -s 'http://127.0.0.1/server-status?auto' | awk '
BEGIN {FS=": "}
$1=="Total Accesses" {
print "'$my_zabbix_hostname'", "apache.total_accesses", $2
}
$1=="Total kBytes" {
print "'$my_zabbix_hostname'", "apache.total_kilobytes", $2
}
$1=="BusyWorkers" {
print "'$my_zabbix_hostname'", "apache.busy_workers", $2
}
$1=="IdleWorkers" {
print "'$my_zabbix_hostname'", "apache.idle_workers", $2
}
' | zabbix_sender -z $zabbix_server -s $my_zabbix_hostname -i -
sleep $interval_seconds
done
start on runlevel [12345]
stop on runlevel [^12345]
respawn
exec /usr/local/sbin/send_apache_stat_to_zabbix.sh
ExtendedStatus On
<VirtualHost *:80>
ServerName localhost
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
</VirtualHost>