Мониторинг Apache в ZABBIX

Apache в ZABBIX
http://www.zabbix.com/

Apache является чуть ли не самым распространенным веб-сервером в мире, а потому мониторинг его производительности дело достаточно актуальное. Благо для Zabbix есть масса шаблонов в сети, позволяющих отслеживать производительность web-сервера Apache. Настройкой одного из них я и займусь в этой статье.

Отслеживать Apache будем на самом же сервере Zabbix. Все остальные настройки будут упомянуты в процессе.


Вводная статья по шаблонам мониторинга ZABBIX — Шаблоны ZABBIX.

Если вам интересна тематика ZABBIX, рекомендую обратиться к основной статье — Система мониторинга ZABBIX, в ней вы найдете дополнительную информацию.


Скрипт мониторинга Apache в ZABBIX

Создадим каталог для скриптов zabbix-агента с предустановленными правами. У меня он уже был, но я на всякий случай напишу команды, которые я использовал для его создания:
root@debian7:~# mkdir -m 750 /usr/local/etc/zabbix_agent_scripts
Меняем владельца каталога:
root@debian7:~# chown root:zabbix /usr/local/etc/zabbix_agent_scripts
Создадим файл со скриптом:
root@debian7:~# nano /usr/local/etc/zabbix_agent_scripts/apache-stats.sh

С содержанием:

#!/bin/bash
if [[ -z «$1» || -z «$2» || -z «$3″ ]]; then
exit 1
fi
##### PARAMETERS #####
RESERVED=»$1″
METRIC=»$2″
URL=»$3″
STATSURL=»${URL}?auto»
#
CACHE_TTL=»55″
CACHE_FILE=»/tmp/zabbix.apache2.echo ${URL} | md5sum | cut -d" " -f1.cache»
EXEC_TIMEOUT=»2″
NOW_TIME=date '+%s'
##### RUN #####
if [ -s «${CACHE_FILE}» ]; then
CACHE_TIME=stat -c"%Y" "${CACHE_FILE}"
else
CACHE_TIME=0
fi
DELTA_TIME=$((${NOW_TIME} — ${CACHE_TIME}))
#
if [ ${DELTA_TIME} -lt ${EXEC_TIMEOUT} ]; then
sleep $((${EXEC_TIMEOUT} — ${DELTA_TIME}))
elif [ ${DELTA_TIME} -gt ${CACHE_TTL} ]; then
echo «» >> «${CACHE_FILE}» # !!!
DATACACHE=curl -sS --insecure --max-time ${EXEC_TIMEOUT} "${STATSURL}" 2>&1
echo «${DATACACHE}» > «${CACHE_FILE}» # !!!
echo «URL=${URL}» >> «${CACHE_FILE}» # !!!
chmod 640 «${CACHE_FILE}»
fi
#
if [ «${METRIC}» = «accesses» ]; then
cat «${CACHE_FILE}» | grep -i «accesses» | cut -d’:’ -f2 | head -n1
fi
if [ «${METRIC}» = «kbytes» ]; then
cat «${CACHE_FILE}» | grep -i «kbytes» | cut -d’:’ -f2 | head -n1
fi
if [ «${METRIC}» = «cpuload» ]; then
cat «${CACHE_FILE}» | grep -i «cpuload» | cut -d’:’ -f2 | head -n1
fi
if [ «${METRIC}» = «uptime» ]; then
cat «${CACHE_FILE}» | grep -i «uptime» | cut -d’:’ -f2 | head -n1
fi
if [ «${METRIC}» = «avgreq» ]; then
cat «${CACHE_FILE}» | grep -i «ReqPerSec» | cut -d’:’ -f2 | head -n1
fi
if [ «${METRIC}» = «avgreqbytes» ]; then
cat «${CACHE_FILE}» | grep -i «BytesPerReq» | cut -d’:’ -f2 | head -n1
fi
if [ «${METRIC}» = «avgbytes» ]; then
cat «${CACHE_FILE}» | grep -i «BytesPerSec» | cut -d’:’ -f2 | head -n1
fi
if [ «${METRIC}» = «busyworkers» ]; then
cat «${CACHE_FILE}» | grep -i «BusyWorkers» | cut -d’:’ -f2 | head -n1
fi
if [ «${METRIC}» = «idleworkers» ]; then
cat «${CACHE_FILE}» | grep -i «idleworkers» | cut -d’:’ -f2 | head -n1
fi
if [ «${METRIC}» = «totalslots» ]; then
cat «${CACHE_FILE}» | grep -i «Scoreboard» | cut -d’:’ -f2 | sed -e ‘s/ //g’ | wc -c | awk ‘{print $1-1}’
fi
#
exit 0

Изменим владельца скрипта:
root@debian7:~# chown root:zabbix /usr/local/etc/zabbix_agent_scripts/apache-stats.sh
Установим права:
root@debian7:~# chmod 550 /usr/local/etc/zabbix_agent_scripts/apache-stats.sh

Настройка Apache

Подгружаем модуль, необходимый для мониторинга:
root@debian7:~# a2enmod info
To activate the new configuration, you need to run:
service apache2 restart

Раз просят перезапуститься, так и делаем:
root@debian7:~# service apache2 restart
[ ok ] Restarting web server: apache2 … waiting …

Отредактируем конфигурационный файл apache:
root@debian7:~# nano /etc/apache2/apache2.conf
В самый конец файла добавим:
ExtendedStatus on

<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from .your_domain.com
</Location>

Где «.your_domain.com» — адрес zabbix-сервера.

Перезагрузим сервер:
root@debian7:~# /etc/init.d/apache2 force-reload
[ ok ] Reloading web server config: apache2.

Для проверки работы зайдем по следующей ссылке: http://your-domain-or-ip/server-status
В первый раз у меня выдало сообщение:
zabbix apache monitoring 01

Как видно, ошибка с правами доступа, ведь проверял я это не с локального сервера. Исправим:
root@debian7:~# nano /etc/apache2/apache2.conf
В самом конце, где мы дописывали ряд строк, изменяем:
Allow from .your_domain.com additional-ip-or-domain
Вместо «additional-ip-or-domain» вставьте один или несколько необходимых адресов через пробел.

Перезапускаем apache и снова переходим по ссылке (см. выше):
zabbix apache monitoring 02

Установим curl:
root@debian7:~# apt-get install curl

Проверим отдаются ли данные с самого сервера:
root@debian7:~# curl http://your-server-ip/server-status
Не должно приходить никаких ошибок.
Настройка zabbix-агента

Создаем файл с пользовательскими параметрами:
root@debian7:~# nano /usr/local/etc/zabbix_agent_configs/apache2.conf
В конце файла вставляем следующий текст:
UserParameter=apache2[*],/usr/local/etc/zabbix_agent_scripts/apache-stats.sh «none» «$1» «$2»
В файле конфигурации агента zabbix должны быть произведены следующие настройки:
root@debian7:~# nano /usr/local/etc/zabbix_agentd.conf
Нам нужен параметр «Include«, задаем ему следующее значение:
Include=/usr/local/etc/zabbix_agent_configs

Перезапускаем агента:
root@debian7:~# service zabbix-agent restart

Проверяем:
root@debian7:~# zabbix_get -s 127.0.0.1 -k «apache2[accesses,http://your-server-ip/server-status]»
10885

Загружаем готовый шаблон:
Шаблон для мониторинга Apache2 (Agent)
Дальше необходимо добавить шаблон мониторинга на наш zabbix-сервер через web-интерфейс. Для этого проходим в Настройка>Шаблоны, нажимаем справа вверху «Импорт» и добавляем шаблон. Подцепляем шаблон к нужным узлам мониторинга — Узлы сети > выбираем нужный узел > вкладка «Шаблоны» > соединяем с новым шаблоном > нажимаем «Добавить» > нажимаем «Обновить».

Помимо загрузки необходимо добавить макрос, чтобы в каждый элемент данных этот макрос подставлял необходимую адресную строку. Определить работу макроса можно в рамках шаблона или или узла сети. В нашем случае подойдет второй вариант. Нажимаем на нужный узел сети, переходим на вкладку «Макросы» и устанавливаем следующие настройки:
zabbix apache monitoring 03Нажимаем кнопку «Добавить» и «Обновить».

Через некоторое время проверим прием данных:
zabbix apache monitoring 04

Настройка завершена.


Использованные источники:

Enabling and using apache’s mod_status on Debian

Monitoring Apache with mod_status

Мониторинг параметров Apache2 в Zabbix

Шаблоны Zabbix

1 Пользовательские макросы

comments powered by HyperComments
writing a dissertation literature review
2022-07-05 16:10:22
<strong>phd dissertation example https://professionaldissertationwriting.org/</strong>
best dissertation writing service
2022-07-05 17:02:40
<strong>bestdissertation https://professionaldissertationwriting.com/</strong>
thesis dissertation writing
2022-07-05 19:44:46
<strong>research writing help https://helpwithdissertationwritinglondon.com/</strong>
dissertation help free
2022-07-05 23:40:04
<strong>writing dissertation proposal https://dissertationwritingcenter.com/</strong>
how to cite a dissertation
2022-07-06 01:45:57
<strong>dissertation writing support https://dissertationhelpexpert.com/</strong>
dissertation research
2022-07-06 03:51:16
<strong>writing service https://accountingdissertationhelp.com/</strong>
phd dissertation example
2022-07-06 08:51:15
<strong>doctoral dissertation help history https://writing-a-dissertation.net/</strong>
whats a dissertation
2022-07-06 11:54:51
<strong>writing your dissertation in https://bestdissertationwritingservice.net/</strong>
writing your dissertation in
2022-07-06 14:15:03
<strong>dissertation proposal help https://businessdissertationhelp.com/</strong>
dissertation acknowledgement sample
2022-07-06 16:48:11
<strong>order a dissertation https://customdissertationwritinghelp.com/</strong>
dissertation help uk
2022-07-06 22:18:32
<strong>buy dissertations online https://writingadissertationproposal.com/</strong>
dissertation editing
2022-07-06 23:55:19
<strong>writing acknowledgement dissertation https://dissertationhelpspecialist.com/</strong>
buy dissertation writing services
2022-07-07 02:15:24
<strong>dissertation statistics help https://dissertationhelperhub.com/</strong>
dissertation help articles
2022-07-07 06:46:54
<strong>how to write a dissertation proposal https://customthesiswritingservices.com/</strong>
online casino usa legal
2022-07-25 20:21:51
<strong>zone online casino msn games https://download-casino-slots.com/</strong>
caesars online casino app
2022-07-25 22:25:06
<strong>newest pa online casino https://firstonlinecasino.org/</strong>
online free casino games
2022-07-26 01:06:48
<strong>riversweeps 777 online casino app https://onlinecasinofortunes.com/</strong>
online casino bonus codes
2022-07-26 02:09:57
<strong>online casino usa accepted https://newlasvegascasinos.com/</strong>
online casino ny real money no deposit
2022-07-26 04:43:26
<strong>mobile online casino https://trust-online-casino.com/</strong>
lucky casino online
2022-07-26 07:53:35
<strong>free online casino games real money no deposit https://onlinecasinosdirectory.org/</strong>
orion stars online casino
2022-07-26 10:29:52
<strong>online casino real money usa https://9lineslotscasino.com/</strong>
slots casino online
2022-07-26 13:31:22
<strong>bovegas online casino https://free-online-casinos.net/</strong>
san manuel online casino
2022-07-26 16:16:43
<strong>ocean resort casino online https://internet-casinos-online.net/</strong>
betrivers online casino
2022-07-26 17:41:49
<strong>online casino paypal https://cybertimeonlinecasino.com/</strong>
atlantis casino online
2022-07-26 21:04:26
<strong>river sweep online casino https://1freeslotscasino.com/</strong>
online casino review
2022-07-26 23:17:31
<strong>real casino games online https://vrgamescasino.com/</strong>
caesar online casino
2022-07-27 02:50:36
<strong>borgata online casino app https://casino-online-roulette.com/</strong>
online casino usa
2022-07-27 04:36:53
<strong>no deposit bonus online casino https://casino-online-jackpot.com/</strong>
casino royale full movie online free
2022-07-27 06:30:56
<strong>casino online slots https://onlineplayerscasino.com/</strong>
las atlantis online casino reviews
2022-07-27 15:41:03
<strong>miami club casino online https://casino8online.com/</strong>
top rated vpn services
2022-08-07 15:56:31
<strong>best free vpn for mac https://freevpnconnection.com/</strong>
best vpn for kodi
2022-08-07 19:46:23
<strong>best mobile vpn https://freehostingvpn.com/</strong>
best vpn provider
2022-08-08 00:41:00
<strong>buy vpn for china https://imfreevpn.net/</strong>
vpn router
2022-08-08 03:54:35
<strong>best vpn trial https://superfreevpn.net/</strong>
best antivirus with vpn
2022-08-08 04:54:13
<strong>kim komando best vpn https://free-vpn-proxy.com/</strong>
fastest free vpn
2022-08-08 07:08:11
<strong>best private vpn https://rsvpnorthvalley.com/</strong>
international gay dating website
2022-08-23 15:28:04
<strong>hunter biden gay boyfriend dating https://gay-singles-dating.com/</strong>
adam for adam gay online dating hookups
2022-08-23 16:09:57
<strong>gay dating service out personal custormer service https://gayedating.com/</strong>
gay hairy men dating sites
2022-08-23 19:05:59
<strong>michael dinsmore gay dating https://datinggayservices.com/</strong>
single dating sites
2022-08-24 12:29:48
<strong>casual dating sites https://freephotodating.com/</strong>
japanese chubby
2022-08-24 15:54:38
<strong>village ladies totally free https://onlinedatingbabes.com/</strong>
free chatting online dating sites
2022-08-24 17:29:00
<strong>top internet dating sites https://adult-singles-online-dating.com/</strong>
ourtime dating site
2022-08-24 19:38:49
<strong>dating services contact germany https://adult-classifieds-online-dating.com/</strong>
popular now o
2022-08-24 22:36:10
<strong>free sex chat sites https://online-internet-dating.net/</strong>
mature dating sites free no credit card fees
2022-08-25 00:06:33
<strong>free online go https://speedatingwebsites.com/</strong>
dateing websites
2022-08-25 01:54:36
<strong>online dating site https://datingpersonalsonline.com/</strong>
dating games
2022-08-25 05:06:23
<strong>adult date site https://wowdatingsites.com/</strong>
best dating online site
2022-08-25 06:49:31
<strong>12 single dating site https://lavaonlinedating.com/</strong>
match dating website
2022-08-25 08:52:13
<strong>best dating websites https://freeadultdatingpasses.com/</strong>
dating sites for singles
2022-08-25 14:52:48
<strong>best free online dating websites https://zonlinedating.com/</strong>
online datings
2022-08-25 15:40:05
<strong>online-dating-ukraine https://onlinedatingservicesecrets.com/</strong>
raging bull casino online
2022-08-30 11:02:33
<strong>viva slots vegas™ free slot casino games online https://onlinecasinos4me.com/</strong>
online casino ideal
2022-08-30 12:18:00
<strong>betmgm online casino michigan https://online2casino.com/</strong>
online casino betting
2022-08-30 18:58:16
<strong>hollywood online casino pa https://casinosonlinex.com/</strong>
gay male chat site
2022-09-03 01:34:23
<strong>free live gay web cam chat rooms https://newgaychat.com/</strong>
free gay chat rooms in new york state
2022-09-03 03:47:42
<strong>gay incet chat https://gaychatcams.net/</strong>
gay chat cams free
2022-09-03 11:13:33
<strong>gay hot chat https://gaychatspots.com/</strong>
gay teen chat
2022-09-03 17:40:49
<strong>all free gay chat rooms https://gay-live-chat.net/</strong>
gay chat randon
2022-09-03 20:25:28
<strong>chat with senior gay' https://chatcongays.com/</strong>
gay cam chat webcam
2022-09-04 01:54:11
<strong>chat avenue gay https://gayphillychat.com/</strong>
shemale/gay online chat sites
2022-09-04 07:14:40
<strong>gay ruleete chat https://gaychatnorules.com/</strong>
gay webcam chat zoom
2022-09-04 12:52:59
<strong>gay chat rooms ring central https://gaymusclechatrooms.com/</strong>
gay phone chat lines
2022-09-04 16:09:25
<strong>gay chat line https://free-gay-sex-chat.com/</strong>
gay sissie video chat
2022-09-04 23:41:22
<strong>gay chat sex https://gayinteracialchat.com/</strong>
amature gay video chat
2022-10-20 17:10:04
<strong>gay chat random alternative https://gaymanchatrooms.com/</strong>
college paper writers
2022-10-20 20:00:42
<strong>help write my paper https://sociologypapershelp.com/</strong>
pay to do my paper
2022-10-20 20:45:07
<strong>websites that write papers for you https://uktermpaperwriters.com/</strong>
websites that write papers for you
2022-10-20 22:27:23
<strong>can you write my paper https://paperwritinghq.com/</strong>
order a paper online
2022-10-21 03:32:17
<strong>buy school papers online https://top100custompapernapkins.com/</strong>
paper writer services
2022-10-21 05:45:01
<strong>help writing a paper for college https://researchpaperswriting.org/</strong>
order paper online
2022-10-21 06:32:00
<strong>buy literature review paper https://cheapcustompaper.org/</strong>
find someone to write my college paper
2022-10-21 08:08:00
<strong>help with paper https://writingpaperservice.net/</strong>
pay someone to write paper
2022-10-21 08:50:37
<strong>where can i find someone to write my paper https://buyessaypaperz.com/</strong>
paper writing website
2022-10-21 12:14:52
<strong>help with writing a paper for college https://writemypaperquick.com/</strong>
white paper writing services
2022-10-21 12:50:33
<strong>buying papers https://essaybuypaper.com/</strong>
buy school papers online
2022-10-21 14:16:47
<strong>best college paper writing service https://papercranewritingservices.com/</strong>
pay someone to write a paper for me
2022-10-21 17:01:51
<strong>write my biology paper https://ypaywallpapers.com/</strong>
write my thesis paper
2022-10-21 18:07:59
<strong>pay for a paper https://studentpaperhelp.com/</strong>
2unconcern
2023-01-25 23:16:35
<strong>2vaporous</strong>
coursework writer uk
2023-02-05 14:21:07
<strong>coursework marking https://brainycoursework.com/</strong>
coursework master
2023-02-05 16:11:15
<strong>differential equations coursework https://courseworkninja.com/</strong>
creative writing coursework ideas
2023-02-05 17:07:04
<strong>coursework online https://writingacoursework.com/</strong>
coursework help
2023-02-05 18:36:29
<strong>coursework project https://mycourseworkhelp.net/</strong>
coursework writing
2023-02-05 20:32:42
<strong>coursework writing service uk https://courseworkdownloads.com/</strong>
coursework research
2023-02-05 21:44:35
<strong>help with coursework https://courseworkinfotest.com/</strong>
help with coursework
2023-02-05 22:53:59
<strong>coursework online https://coursework-expert.com/</strong>
coursework paper
2023-02-05 23:50:01
<strong>coursework plagiarism checker https://teachingcoursework.com/</strong>
coursework help uk
2023-02-06 01:17:50
<strong>cpa coursework https://buycoursework.org/</strong>
coursework questions
2023-02-06 02:59:19
<strong>coursework writer https://courseworkdomau.com/</strong>
dating sites free for men
2023-02-08 12:43:30
<strong>dating services contact germany https://freewebdating.net/</strong>
free local dates
2023-02-08 15:27:50
<strong>date free website https://jewish-dating-online.net/</strong>
dating seiten
2023-02-08 17:53:06
<strong>100% free dating sites no fees https://sexanddatingonline.com/</strong>
totally free dating sites no fees ever
2023-02-08 20:05:09
<strong>free date web sites https://onlinedatingsuccessguide.com/</strong>
find international singles dating
2023-02-08 21:24:05
<strong>find single women https://onlinedatinghunks.com/</strong>
sexy dating
2023-02-08 23:12:10
<strong>online dating services https://datingwebsiteshopper.com/</strong>
absolutely free dating site
2023-02-09 00:00:01
<strong>best dating online site https://allaboutdatingsites.com/</strong>
deting
2023-02-09 02:59:09
<strong>meet singles for free https://freewebdating.net/</strong>
Яндекс.Метрика