|
本帖最后由 枫狐狸 于 2018-1-16 17:06 编辑
此监控是参考原来的zabifx改的,不需要启用snmp,直接脚本提取。
20170607的更新如下,所有文件全部用脚本生成,无需上传,图片未更新,最新3.X版模版已上传。[Shell] 纯文本查看 复制代码
************************************
************************************
*** ***
*** informix 安装方法 ***
*** ***
************************************
************************************
cd /home/zabbix/
mkdir zabifx
####################informix 数据库##########
cat >> /etc/zabbix/zabbix_agentd.conf <<END
UserParameter=ifx.tab.discovery,/home/zabbix/zabifx/ifx_discovery.sh
UserParameter=tablespace ,/home/zabbix/zabifx/ifx_check.sh \$1 \$2
UserParameter=ifx.status.discovery,/home/zabbix/zabifx/ifx_status_discovery.sh
UserParameter=status ,/home/zabbix/zabifx/ifx_status_check.sh \$1 \$2
UserParameter=get.ontape.info,/home/zabbix/zabifx/ifx_ontape.sh 2>/dev/null
END
cat > /home/zabbix/zabifx/ifx_check.sh <<END
#!/bin/bash
EQ_DATA="\$2"
ZBX_REQ_DATA_TAB="\$1"
SOURCE_DATA=/tmp/informix_tablespace.log
case \$2 in
maxmb) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$3}';;
free) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$4}';;
autopercent) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$5}';;
*) echo \$ERROR_WRONG_PARAM; exit 1;;
esac
exit 0
END
cat > /home/zabbix/zabifx/ifx_discovery.sh <<END
#!/bin/bash
TABLESPACE=\`cat /tmp/informix_tablespace.log |awk '{print\$2}'|awk ' {print}'\`
COUNT=\`echo "\$TABLESPACE" |wc -l\`
INDEX=0
echo '{"data":['
echo "\$TABLESPACE" | while read LINE; do
echo -n '{"{#TABLENAME}":"'\$LINE'"}'
INDEX=\`expr \$INDEX + 1\`
if [ \$INDEX -lt \$COUNT ]; then
echo ','
fi
done
echo ']}'
END
cat > /home/zabbix/zabifx/ifx_status_discovery.sh <<END
#!/bin/bash
pshell=\`su - informix -c "echo \$SHELL"\`
if [ \$pshell == "/bin/bash" ];then
file='.bash_profile'
else
file='.profile'
fi
INFORMIXDIR=/home/informix
INFORMIXSERVER=\`cat /home/informix/\$file|grep -v '^#'|grep INFORMIXSERVER=|awk -F "=" '{printf \$2}'\`
/home/zabbix/zabifx/zabifx.sh all \$INFORMIXSERVER>/tmp/ifx_status
sed -i 's/|/ /g' /tmp/ifx_status
stat01=\`cat /tmp/ifx_status|grep serverstatus |awk '{print\$2}'|awk ' {print}'\`
stat02=\`cat /tmp/ifx_status|grep sessionnum |awk '{print\$2}'|awk ' {print}'\`
stat03=\`cat /tmp/ifx_status|grep activesessioncount |awk '{print\$2}'|awk ' {print}'\`
stat04=\`cat /tmp/ifx_status|grep topsessioncount |awk '{print\$2}'|awk ' {print}'\`
stat05=\`cat /tmp/ifx_status|grep llogcurrent |awk '{print\$2}'|awk ' {print}'\`
stat06=\`cat /tmp/ifx_status|grep llogwithoutbkpnum |awk '{print\$2}'|awk ' {print}'\`
stat07=\`cat /tmp/ifx_status|grep llogwithoutbkpperc |awk '{print\$2}'|awk ' {print}'\`
stat08=\`cat /tmp/ifx_status|grep rssservers |awk '{print\$2}'|awk ' {print}'\`
stat09=\`cat /tmp/ifx_status|grep rssbacklog |awk '{print\$2}'|awk ' {print}'\`
stat10=\`cat /tmp/ifx_status|grep rssconnactive |awk '{print\$2}'|awk ' {print}'\`
stat11=\`cat /tmp/ifx_status|grep uptime |awk '{print\$2}'|awk ' {print}'\`
stat12=\`cat /tmp/ifx_status|grep threadread |awk '{print\$2}'|awk ' {print}'\`
stat13=\`cat /tmp/ifx_status|grep version |awk '{print\$7}'|awk ' {print}'\`
if [ -z \$stat01 ];then
stat01=0
fi
if [ -z \$stat02 ];then
stat02=0
fi
if [ -z \$stat03 ];then
stat03=0
fi
if [ -z \$stat04 ];then
stat04=0
fi
if [ -z \$stat05 ];then
stat05=0
fi
if [ -z \$stat06 ];then
stat06=0
fi
if [ -z \$stat07 ];then
stat07=0
fi
if [ -z \$stat08 ];then
stat08=0
fi
if [ -z \$stat09 ];then
stat09=0
fi
if [ -z \$stat10 ];then
stat10=0
fi
if [ -z \$stat11 ];then
stat11=0
fi
if [ -z \$stat12 ];then
stat12=0
fi
if [ -z \$stat13 ];then
stat13=0
fi
echo "ifxstat" \$stat01 \$stat02 \$stat03 \$stat04 \$stat05 \$stat06 \$stat07 \$stat08 \$stat09 \$stat10 \$stat11 \$stat12 \$stat13 >/tmp/ifx_status
STATUS=\`cat /tmp/ifx_status |awk '{print\$1}'|awk ' {print}'\`
COUNT=\`echo "\$STATUS" |wc -l\`
INDEX=0
echo '{"data":['
echo "\$STATUS" | while read LINE; do
echo -n '{"{#STATUSNAME}":"'\$LINE'"}'
INDEX=\`expr \$INDEX + 1\`
if [ \$INDEX -lt \$COUNT ]; then
echo ','
fi
done
echo ']}'
END
cat > /home/zabbix/zabifx/ifx_status_check.sh <<END
#!/bin/bash
EQ_DATA="\$2"
ZBX_REQ_DATA_TAB="\$1"
SOURCE_DATA=/tmp/ifx_status
case \$2 in
serverstatus) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$2}';;
sessionnum) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$3}';;
activesessioncount) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$4}';;
topsessioncount) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$5}';;
llogcurrent) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$6}';;
llogwithoutbkpnum) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$7}';;
llogwithoutbkpperc) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$8}';;
rssservers) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$9}';;
rssbacklog) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$10}';;
rssconnactive) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$11}';;
uptime) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$12}';;
threadread) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$13}';;
version) grep -E "\<\$ZBX_REQ_DATA_TAB\>" \$SOURCE_DATA |awk '{print \$14}';;
*) echo \$ERROR_WRONG_PARAM; exit 1;;
esac
exit 0
END
cat > /home/zabbix/zabifx/ifx_ontape.sh <<END
#!/bin/bash
tape=\`ps -ef|grep ontape|egrep -v grep\`
if [ -n "\$tape" ] ;then
echo "0"
else
echo "1"
fi
END
cat > /home/zabbix/zabifx/zabifx.sh <<END
#! /usr/bin/ksh
# SVN-ID \$Id: zabifx 89197 2013-08-05 18:36:13Z cinacio \$
#
# 23/April/2013
# by Cesar Inacio Martins - [url=mailto:cesar.inacio.martins@gmail.com]cesar.inacio.martins@gmail.com[/url]
#
# Script to help collect information from Informix database
# to Zabbix Server 2.0
#
# The reason to use this script is because the Zabbix Server 2.0 doesn't
# support SNMP keys with multiple values (not allow discovery sessions inside
# of discovery instance).
# At Zabbix 2.2 this should be supported , so, further this information maybe
# can be collected with SNMP.
# (aggregating the User Sessions IODs, Logical logs IODs)
#
# This script was prepared to be used with Zabbix Agent , just include into
# /etc/zabbix/zabbix-agentd.conf the line :
# UserParameter=zabifx ,/etc/zabbix/zabifx \$1 \$2
# Then at Zabbix server, configure a zabbix item with keys :
# | serverstatus sessionnum activesessioncount topsessioncount llogcurrent
# | logwithoutbkp llogwithoutbkpperc rssservers rssbacklog rssconnactive
# | version uptime
# Eg.: zabifx[serverstatus,{#SNMPVALUE}]
#
# Observation: The {#SNMPVALUE} is a zabbix macro where is replaced by instance
# name discovered and is useful only inside of the template
# 'Template - Informix' working with informix SNMP service.
# The template is available on
# [url=http://www..../]www....[/url]
# Set your Informix variables here
pshell=\`su - informix -c "echo \$SHELL"\`
if [ \$pshell == "/bin/bash" ];then
file='.bash_profile'
else
file='.profile'
fi
INFORMIXDIR=/home/informix
PATH=\$PATH:\$INFORMIXDIR/bin
export INFORMIXDIR PATH
INFORMIXSERVER=\`cat /home/informix/\$file|grep -v '^#'|grep INFORMIXSERVER=|awk -F "=" '{printf \$2}'\`
INFORMIXSERVER=\`echo \$INFORMIXSERVER|sed 's/^ //;s/ \$//'\`
ONCONFIG=\`cat /home/informix/\$file|grep -v '^#'|grep ONCONFIG=|awk -F "=" '{printf \$2}'\`
ONCONFIG=\`echo \$ONCONFIG|sed 's/^ //;s/ \$//'\`
export INFORMIXSERVER ONCONFIG
export PS1='\$INFORMIXSERVER:\$PWD>'
export DBDATE=Y4MD0
export COLLCHAR=1
export LANG=en_US.iso88591
export DB_LOCALE=zh_CN.GB18030-2000
export CLIENT_LOCALE=zh_CN.GB18030-2000
export SERVER_LOCALE=zh_CN.GB18030-2000
export LD_LIBRARY_PATH=\$INFORMIXDIR/lib:\$LD_LIBRARY_PATH:\$INFORMIXDIR/lib/esql
ONSTAT=\$INFORMIXDIR/bin/onstat
GREP=grep
export POSIXLY_CORRECT=1 # to AWK parse equal on all OS the regular expressions... (on Linux this can be disabled)
AWK=awk
SED=sed
TR=tr
CUT=cut
DATE=date
# This is for AIX, where it is part of the RPM coreutils installed manually.
[ -x /usr/linux/bin/date ] && DATE=/usr/linux/bin/date
# Use a temporary file (just in case resquested all parameters together, run only once each onstat)
vTmp=/tmp/zabifx.\$\$
vTmp1=\$vTmp.1
# Remove the temporary file when the script finish, with or without success.
trap "rm -f \$vTmp.* >/dev/null 2>&1 ; exit " 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Expected receive 2 parameters
# Example : zabifx sessionnum ifxonline
# Example, just for test if the scripts is working: zabifx all <instance_name>
if [ \$# -ne 2 ] ; then
echo "ZBX_NOTSUPPORTED"
exit 1
fi
export vOption=\$1
export INFORMIXSERVER=\$2
# Check if onstat is accessible
if [ ! -x \$ONSTAT ] ; then
echo "ZBX_NOTSUPPORTED"
exit 1
fi
##############################################
###
export vOnstatStatus=""
\$ONSTAT - > \$vTmp1.onstat-
vOnstatStatus=\$? # 5 = online
##############################################
###
# function to capture the onstat outputs
# (useful only when used the "all" cmdline parameter, avoiding run multiple times the same onstat )
_onstat(){
if [ \$vOnstatStatus -eq 5 ] ; then
vParam=\$(echo "\$*" | \$TR -d " " )
[ ! -f \$vTmp1.onstat.\$vParam ] && \$ONSTAT \$* > \$vTmp1.onstat.\$vParam 2>/dev/null
cat \$vTmp1.onstat.\$vParam
fi
}
##############################################
###
_param() {
[ "\$1" != "serverstatus" -a "\$vOnstatStatus" != 5 ] && echo "\$1|ZBX_NOTSUPPORTED" && return
case \$1 in
# Return Server Status , # 0 Initialization mode
# 1 Quiescent mode
# 2 Recovery mode
# 3 Backup mode
# 4 Shutdown mode
# 5 Online mode
# 6 Abort mode
# 7 User mode
# 255 Off-Line mode
serverstatus) echo "\$1|\$vOnstatStatus" ;;
# Return # of users sessions connected
sessionnum) printf "\$1|" ;
_onstat "-g ntu" | \$AWK '/#netscb/ { vNext=1 ; next } vNext == 1 { match(\$1,".*/"); x=substr(\$1,RSTART, RLENGTH-1); print x; exit} '
;;
# Return # max of users sessions connected since the database started (or last onstat -z)
topsessioncount) printf "\$1|" ;
_onstat "-g ntu" | \$AWK '/#netscb/ { vNext=1 ; next } vNext == 1 { match(\$1,"/.*"); x=substr(\$1,RSTART+1, RLENGTH); print x; exit} '
;;
# Return # read threads, waiting CPU to run
threadread) printf "\$1|" ;
_onstat "-g rea" | \$GREP -c "ready"
;;
# Return # active user threads , running on CPU
activesessioncount) printf "\$1|" ;
_onstat "-g act" | \$GREP -cE "aio|sqlexec"
;;
# Return # user sessions waiting for something what isn't Yield, Lock (mutex or any other condition)
userwaiting) printf "\$1|" ;
_onstat "-u" | \$AWK '\$2 ~ /^[A-Z-]{7}\$/ {print \$2}' | \$GREP -c "^[^YL-]"
;;
# Return # user sessions waiting for lock
userlockwaiting) printf "\$1|" ;
_onstat "-u" | \$AWK '\$2 ~ /^[A-Z-]{7}\$/ {print \$2}' | \$GREP -c "^L"
;;
# Return current logical logs
llogcurrent) printf "\$1|" ;
_onstat "-l" | \$AWK '\$3 ~ /^[A-Z-]{7}\$/ && /C/ {print \$4}'
;;
# Return # logical logs without backup
llogwithoutbkpnum) printf "\$1|" ;
_onstat "-l" | \$AWK '\$3 ~ /^[A-Z-]{7}\$/ {print \$3}' | \$GREP -c '^U.-'
;;
# Return % logical logs without backup
llogwithoutbkpperc) printf "\$1|" ;
logstotal=\$(_onstat "-l" | \$AWK '/[0-9]+ active/ { print \$1}')
logswb=\$(_onstat "-l" | \$AWK '\$3 ~ /^[A-Z-]{7}\$/ {print \$3}' | \$GREP -c '^U.-')
echo \$logswb \$logstotal | \$AWK ' {x= \$1 * 100 / \$2 ; print x} '
;;
# Return the # of RSS servers configured
rssservers) printf "\$1|" ;
_onstat "-g rss verbose" | \$AWK '/Number of RSS servers/ { print \$NF } '
;;
# Return the # of active connection of all RSS servers configured
rssconnactive) printf "\$1|" ;
_onstat "-g rss verbose" | \$AWK -F: 'BEGIN {x=0} /Log transmission status/ { if (\$NF ~ "Active") x=x+1 } END { print x } '
;;
# Return the total of backlog (~ delay) of all RSS servers configured
rssbacklog) printf "\$1|" ;
_onstat "-g rss verbose" | \$AWK -F: 'BEGIN {x=0} /Approximate.*Backlog/ { x=x+\$NF } END { print x}'
;;
# Return text with version of the database
version) printf "\$1|" ;
_onstat "-" | \$GREP "Version" | \$AWK -F"--" '{print \$1}'
;;
# Return # seconds the database is UP.
# Requires the GNU date command , where support the @0 parameter
uptime) printf "\$1|" ;
vUPstr=\$(_onstat "-" | \$GREP " Up " | \$AWK -F"--" '{print \$3}' )
vUPhour=\$(echo "\$vUPstr" | \$SED -e 's/ *Up *//g' -e 's/.*days *//g') # return HH:MM:SS
vUPhour=\$(echo "\$vUPhour" | \$AWK -F: '{ printf " %s hour + %s minutes ",\$1,\$2} ')
vUPdays=""
if echo "\$vUPstr" | \$GREP -q "days" ; then
vUPdays=" + \$(echo "\$vUPstr" | \$SED -e 's/ *Up *//g' -e 's/ *days .*//g') days " # return DD
fi
vTimeStamp=\$(\$DATE -d "1970-01-01 UTC \$vUPdays + \$vUPhour " +%s 2>&1 )
if [ \$? -eq 0 ] ; then
echo "\$vTimeStamp"
else
echo "ZBX_NOTSUPPORTED"
break
fi
;;
*) echo "ZBX_NOTSUPPORTED"
;;
esac
} ##### _param
###
##############################################
if [ "\$vOption" = "all" ] ; then
for x in serverstatus sessionnum activesessioncount topsessioncount llogcurrent llogwithoutbkpnum llogwithoutbkpperc rssservers rssbacklog rssconnactive uptime threadread version
do
_param \$x
done
else
_param \$vOption | \$CUT -f2 -d"|"
fi
END
chmod +x /home/zabbix/zabifx/*.sh
service zabbix_agentd restart
20170607版使用的模版
zbx_informix_template_3.X版.rar
(3.08 KB, 下载次数: 39)
担心网页上复制脚本因符号出错的可以下载文本文件
zabbix_informix.rar
(4.1 KB, 下载次数: 16)
#######################################
zabifx.rar
(4.03 KB, 下载次数: 32)
chkdbs.rar
(771 Bytes, 下载次数: 25)
Template_informix.rar
(2.73 KB, 下载次数: 31)
zabifx脚本说明:
第35行~51行为定义informix的环境变量,此处需注意你安装informix时使用的是ksh还是bash,本脚本中以ksh为例,因此调用的是.profile文件,如果是用bash的,则此处为.bash_profile.
INFORMIXSERVER=`cat /home/informix/.profile|grep -v '^#'|grep INFORMIXSERVER=|awk -F "=" '{printf $2}'`
INFORMIXSERVER=`echo $INFORMIXSERVER|sed 's/^ //;s/ $//'`
ONCONFIG=`cat /home/informix/.profile|grep -v '^#'|grep ONCONFIG=|awk -F "=" '{printf $2}'`
ifx_status_discovery.sh脚本调整:
添加了取值判断,对与取到的空值,替换为“0”,以免zabbix中取值错位。
ifx_status_check.sh脚本调整:
llogcurrent) grep -E "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $6)';;
改为
llogcurrent) grep -E "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $6}';;
原脚本中的错误的地方已修改,请用以下脚本替换同名文件
zabifx.rar
(4.69 KB, 下载次数: 47)
更新3.4.X模版
zbx_informix_templates3.4.X.rar
(412 Bytes, 下载次数: 35)
|
评分
-
查看全部评分
|
|