Мониторинг WEB-сервера и всего что с ним связано
Добавлено: 07 янв 2017, 19:14
Мониторинг Nginx
... примеры из жизни ...
https://forum.cz6.ru/
Код: Выделить всё
server {
listen 81;
server_name localhost;
location /status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
Код: Выделить всё
#!/bin/sh
##################################################
# AUTHOR: Neo <netkiller@msn.com>
# WEBSITE: http://www.netkiller.cn
# Description:zabbix 通过 status 模块监控 nginx
# Note:Zabbix 3.2
# DateTime: 2016-11-22
##################################################
HOST="localhost"
PORT="81"
stub_status=status
check() {
/bin/ps -ax | grep nginx | wc -l
}
active() {
/usr/local/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
accepts() {
/usr/local/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
handled() {
/usr/local/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
requests() {
/usr/local/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
reading() {
/usr/local/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
writing() {
/usr/local/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
waiting() {
/usr/local/bin/curl -s "http://$HOST:$PORT/${stub_status}/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
case "$1" in
check)
check
;;
active)
active
;;
accepts)
accepts
;;
handled)
handled
;;
requests)
requests
;;
reading)
reading
;;
writing)
writing
;;
waiting)
waiting
;;
*)
echo $"Usage $0 {check|active|accepts|handled|requests|reading|writing|waiting}"
exit
Код: Выделить всё
UserParameter=nginx.status[*],/usr/local/etc/zabbix32/scripts/nginx.sh $1
Код: Выделить всё
pm.status_path = /statusphp
Код: Выделить всё
location ~ ^/(statusphp|ping)$ {
access_log off;
allow 127.0.0.1;
deny all;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
include fastcgi_params;
}
Код: Выделить всё
#!/bin/sh
HOST="localhost"
PORT="81"
status="statusphp"
query() {
/usr/local/bin/curl -s http://${HOST}:${PORT}/${status}?xml | grep "<$1>" | awk -F'>|<' '{ print $3}'
}
if [ $# == 0 ]; then
echo $"Usage $0 {pool|process-manager|start-time|start-since|accepted-conn|listen-queue|max-listen-queue|listen-queue-len|idle-processes|active-processes|total-processes|max-active-processes|max-children-reached|slow-requests}"
exit
else
query "$1"
Код: Выделить всё
UserParameter=php-fpm.status[*],/usr/local/etc/zabbix32/scripts/php-fpm.xml.sh $1