Скрипты и файлы конфигурации для мониторинга состояния nginx.
Шаблон для
zabbix 2.2:
2.0
2015-11-07T18:31:03Z
Templates
Template App nginx
Template App nginx
Templates
App nginx
-
Nginx accepts per second
2
1
nginx.accepts
0
90
365
0
0
r/s
1
0
0
0
1
0
0
0
App nginx
-
Nginx active connections
2
0
nginx.connections.active
0
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
-
Nginx handled per second
2
1
nginx.handled
0
90
365
0
0
r/s
1
0
0
0
1
0
0
0
App nginx
-
Nginx latency
0
0
nginx.ping[{HOST.HOST}]
2
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
-
Nginx memory allocated
0
0
proc.mem[nginx,nginx]
60
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
-
Nginx process count
0
0
proc.num[nginx]
60
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
-
Nginx reading state connection count
2
0
nginx.connections.reading
0
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
-
Nginx requests per second
2
0
nginx.requests
0
90
365
0
0
r/s
1
0
0
0
1
0
0
0
App nginx
-
Nginx waiting state connection count
2
0
nginx.connections.waiting
0
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
-
Nginx writing state connection count
2
0
nginx.connections.writing
0
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
{Template App nginx:proc.num[nginx].last(0)}=0
Nginx is down on {HOST.NAME}
0
4
0
{Template App nginx:nginx.ping[{HOST.HOST}].min(#10)}>0.01
Nginx is slow to respond on {HOST.NAME}
0
2
0
{Template App nginx:nginx.ping[{HOST.HOST}].last()}<0
Nginx response is invalid on {HOST.NAME}
0
3
Nginx is not available via configured url
0
Nginx ping
900
200
0.0000
100.0000
1
1
0
1
0
0.0000
0.0000
1
0
0
0
0
2
009900
0
2
0
-
Template App nginx
nginx.ping[{HOST.HOST}]
Nginx status
900
200
0.0000
100.0000
0
0
0
1
0
0.0000
0.0000
0
0
0
0
1
0
FF3333
0
2
0
-
Template App nginx
nginx.connections.writing
0
0
009900
0
2
0
-
Template App nginx
nginx.connections.active
3
0
0000FF
0
2
0
-
Template App nginx
nginx.connections.reading
2
0
FF33FF
0
2
0
-
Template App nginx
nginx.connections.waiting
Nginx workload
900
200
0.0000
100.0000
1
1
0
1
0
0.0000
0.0000
0
0
0
0
2
0
009900
0
2
0
-
Template App nginx
nginx.accepts
0
0
C80000
0
2
0
-
Template App nginx
nginx.requests
1
0
3333FF
0
2
0
-
Template App nginx
nginx.handled
Шаблон для
zabbix 2.4:
2.0
2015-05-31T06:58:40Z
Templates
Template APP nginx
Template APP nginx
Templates
App nginx
-
Nginx accepts per second
2
1
nginx.accepts
0
90
365
0
0
r/s
1
0
0
0
1
0
0
0
App nginx
-
Nginx active connections
2
0
nginx.connections.active
0
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
-
Nginx handled per second
2
1
nginx.handled
0
90
365
0
0
r/s
1
0
0
0
1
0
0
0
App nginx
-
Nginx latency
0
0
nginx.ping[{HOST.HOST}]
60
90
365
0
0
s
0
0
0
0
1
0
0
0
App nginx
-
Nginx memory allocated
0
0
proc.mem[nginx,nginx]
60
90
365
0
3
B
0
0
0
0
1
0
0
0
App nginx
-
Nginx process count
0
0
proc.num[nginx]
30
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
-
Nginx reading state connection count
2
0
nginx.connections.reading
0
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
-
Nginx requests per second
2
1
nginx.requests
0
90
365
0
0
r/s
1
0
0
0
1
0
0
0
App nginx
-
Nginx waiting state connection count
2
0
nginx.connections.waiting
0
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
-
Nginx writing state connection count
2
0
nginx.connections.writing
0
90
365
0
3
0
0
0
0
1
0
0
0
App nginx
{Template APP nginx:proc.num[nginx].last(0)}=0
Nginx is down on {HOST.NAME}
0
4
0
{Template APP nginx:nginx.ping[{HOST.HOST}].min(#10)}>0.01
Nginx is slow to respond on {HOST.NAME}
0
2
0
{Template APP nginx:nginx.ping[{HOST.HOST}].last()}<0
Nginx responce is invalid on {HOST.NAME}
0
3
Nginx is not available via configured url
0
Nginx ping
900
200
0.0000
100.0000
1
1
0
1
0
0.0000
0.0000
1
0
0
0
0
2
009900
0
2
0
-
Template APP nginx
nginx.ping[{HOST.HOST}]
Nginx status
900
200
0.0000
100.0000
0
0
0
1
0
0.0000
0.0000
0
0
0
0
1
0
FF3333
0
2
0
-
Template APP nginx
nginx.connections.writing
0
2
009900
0
2
0
-
Template APP nginx
nginx.connections.active
2
0
FF33FF
0
2
0
-
Template APP nginx
nginx.connections.waiting
3
0
0000FF
0
2
0
-
Template APP nginx
nginx.connections.reading
Nginx workload
900
200
0.0000
100.0000
1
1
0
1
0
0.0000
0.0000
0
0
0
0
2
0
009900
0
2
0
-
Template APP nginx
nginx.accepts
1
0
3333FF
0
2
0
-
Template APP nginx
nginx.handled
0
0
FF0000
0
2
0
-
Template APP nginx
nginx.requests
Для удобства установки различных нестандартных метрик для мониторинга я использую директиву
Include=/etc/zabbix/zabbix_agentd.conf.d/ после чего можно добавлять отдельные файлы, в которых будут все опции, необходимые для работы необходимой метрики, в данном случае:
/etc/zabbix/zabbix_agentd.conf.d/nginx_status.conf:
UserParameter=nginx.ping,sh /etc/zabbix/scripts/nginx_status.sh
Конфигурация для
nginx файл
nginx_status_http.conf:
server {
listen 127.0.0.1:80;
server_name localhost;
keepalive_timeout 0;
location = /nginx_status {
stub_status on;
# access_log off;
allow 127.0.0.1;
deny all;
}
access_log /var/log/nginx/nginx_status_http.access.log;
error_log /var/log/nginx/nginx_status_http.error.log;
}
Нужно положить этот конфигурационный файл nginx в
/etc/nginx/sites-available/nginx_status_http.conf:
ln -s /etc/nginx/sites-available/nginx_status_http.conf /etc/nginx/sites-enabled/nginx_status_http.conf
service nginx reload
Затем необходимо создать скрипт, который осуществляет доставку данных в
zabbix -
/etc/zabbix/scripts/nginx_status.sh:
#!/bin/sh
URL='http://localhost/nginx_status'
TMP='/tmp/nginx-ping.tmp'
ZABBIX_SENDER='/usr/bin/env zabbix_sender'
CONFIG='/etc/zabbix/zabbix_agentd.conf'
# WARNING: Correctly setup 'Hostname=' in config is REQUIRED!
# REQUIRED binaries: GNU time, wget, awk, zabbix_sender.
(/usr/bin/env time -f %e /usr/bin/env wget --no-http-keep-alive --quiet --timeout 9 -O - $URL) 2>$TMP | \
awk '/Active connections/ {active=int($NF)}
/ ([0-9]+) ([0-9]+) ([0-9]+)/ {accepts=int($1); handled=int($2); requests=int($3)}
/Reading:/ {reading=int($2); writing=int($4); waiting=int($6)}
END {
print "- nginx.connections.active", active;
print "- nginx.connections.reading", reading;
print "- nginx.connections.writing", writing;
print "- nginx.connections.waiting", waiting;
print "- nginx.accepts", accepts;
print "- nginx.handled", handled;
print "- nginx.requests", requests;
}' | $ZABBIX_SENDER \
--config $CONFIG \
--input-file - >/dev/null 2>&1
[ -f $TMP ] && cat $TMP && rm $TMP
exit 1
И сразу выставляем правильные права на скрипт:
chmod 600 /etc/zabbix/scripts/nginx_status.sh
chown zabbix:zabbix /etc/zabbix/scripts/nginx_status.sh
Если каталога
/etc/zabbix/scripts у вас еще нет, то его нужно создать:
mkdir /etc/zabbix/scripts
chmod 700 /etc/zabbix/scripts
chown zabbix:zabbix /etc/zabbix/scripts
Для корректной работы необходимо вызывать напрямую бинарный файл
/usr/bin/time, не путать со встроенной
bash функцией
time, в Linux есть с этим большая, на мой взгляд, проблема, т.к.
bash time работает некорректно, в отличие от
/usr/bin/time, к тому же и формат ответа разный, установить можно:
Для Ubuntu, debian:
apt-get install time
Для CentoOS и подобных:
yum install time
Все почти готово, теперь можно зайти в панель
zabbix и добавить нужному хосту новый шаблон
Template APP nginx.
1.
Github repo:zabbix_nginx