1.Настройка Apache-статуса на Zabbix-агенте Проверка поддержки модуля
1 |
# apache2ctl -M | grep status |
1 |
status_module (shared) |
Если модуль не активирован,то активируем вручную
1 |
# a2enmod status |
Debian/Ubuntu Apache версии 2.4.X
1 |
# nano /etc/apache2/mods-enabled/status.conf |
1 2 3 4 5 6 |
<Location /server-status> SetHandler server-status Require local Require ip <IP _ZABBIX_AGENT> <IP_ZABBIX_SERVER> </Location> ExtendedStatus On |
Аpache версии 2.2.X
1 |
# nano /etc/apache2/mods-enabled/status.conf |
1 2 3 4 5 6 7 |
<Location /server-status> SetHandler server-status Order Deny,Allow Deny from all Allow from <IP _ZABBIX_AGENT> <IP_ZABBIX_SERVER> </Location> ExtendedStatus On |
Проверка синтаксиса и перезапуск Apache-сервера
1 |
# apache2ctl configtest && service apache2 reload |
2.Настройка скрипта на Zabbix-агенте
1 |
# nano /etc/zabbix/scripts/apache-stats.sh |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
#!/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 |
Скрипт предусматривает кеш, что позволяет сократить количество реальных обращений к серверу. Время действия кеша […]