Zabbix JMX Item Regexp 解析器
Zabbix JMX Item Regexp parser
下午好
我在 Zabbix JMX 中有一个项目:
jmx["MONITOR:type=Hybrid",混合信息]
此项 returns 后续字符串
POOL: HYBRID-CHARGE.I8
Active: true
Carrier: TIM
Start Producer: true
Start Consumer: true
Configurations: null
CONSUMER
Consumer Threads: 23
Scheduled Tasks: 50
PRODUCER
Objects: 50000
Pagination Table: temporary.hybrid_engine_4
Pagination Interval: 60
Last Database Query: Fri May 12 14:23:32 UTC 2017
Last Result Size: 923526
Last Row Read: 923526
Seconds since Last Execution: 3
我想在
之类的项目中获得自上次执行以来的秒数:3
jmx["MONITOR:type=Hybrid","HybridInfo"].regexp[(Seconds since Last
Execution:).([0-9]*),,])
或者它会在 JMX 查询中,例如:
jmx["MONITOR:type=Hybrid","HybridInfo."Seconds since Last Execution:"]
上面是JMX项目的测试代码。
#!/usr/bin/env bash
# Original source: https://www.zabbix.org/wiki/Docs/howto/zabbix_get_jmx
# Requires 'nc' app
ZBXGET="/usr/bin/zabbix_get"
if [ $# != 5 ] && [ $# != 7 ]; then
echo "Usage: [=11=] <JAVA_GATEWAY_HOST> <JAVA_GATEWAY_PORT> <JMX_SERVER> <JMX_PORT> <KEY> [<JMX_USER> <JMX_PASS>]"
exit;
fi
# Escape backslashes and double-quotes
KEYS=$(echo | sed -e 's/\/\\\\/g' -e 's/"/\\"/g')
if [ $# = 5 ]; then
QUERY="{\"request\": \"java gateway jmx\",\"conn\": \"\",\"port\": ,\"keys\": [\"${KEYS}\"]}"
else
JMX_USER=""
JMX_PASS=""
QUERY="{\"request\": \"java gateway jmx\",\"conn\": \"\",\"port\": ,\"keys\": [\"${KEYS}\"],\"username\": \"${JMX_USER}\",\"password\": \"${JMX_PASS}\"}"
fi
# Prefix with binary header and length
QUERY_INTERPRETED=$(echo -en "${QUERY}")
QUERY_LEN=${#QUERY_INTERPRETED}
QUERY_LEN_BIN=$(printf "%.16x" ${QUERY_LEN} | sed "s/\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)/\\x\\x\\x\\x\\x\\x\\x\\x/")
QUERY_BIN="ZBXD\x01${QUERY_LEN_BIN}${QUERY}"
# Could not get zabbix_get 3.2.3 to work due to ZBX-11528 changes
# $ZBXGET -s -p -k "$QUERY"
echo -en "${QUERY_BIN}" | nc
我想要这样的东西:web.page.regexp[localhost,"/vi/health-check/api1",3345,(HTTP /1.1).([0-9]*),\2 ]
不确定那里有什么测试代码,或者 shell 脚本是如何关联的,但尚不支持 Zabbix 中的项目值解析,它将用于 Zabbix 3.4:https://support.zabbix.com/browse/ZBXNEXT-1443 .
下午好
我在 Zabbix JMX 中有一个项目:
jmx["MONITOR:type=Hybrid",混合信息]
此项 returns 后续字符串
POOL: HYBRID-CHARGE.I8
Active: true
Carrier: TIM
Start Producer: true
Start Consumer: true
Configurations: null
CONSUMER
Consumer Threads: 23
Scheduled Tasks: 50
PRODUCER
Objects: 50000
Pagination Table: temporary.hybrid_engine_4
Pagination Interval: 60
Last Database Query: Fri May 12 14:23:32 UTC 2017
Last Result Size: 923526
Last Row Read: 923526
Seconds since Last Execution: 3
我想在
之类的项目中获得自上次执行以来的秒数:3jmx["MONITOR:type=Hybrid","HybridInfo"].regexp[(Seconds since Last Execution:).([0-9]*),,])
或者它会在 JMX 查询中,例如:
jmx["MONITOR:type=Hybrid","HybridInfo."Seconds since Last Execution:"]
上面是JMX项目的测试代码。
#!/usr/bin/env bash
# Original source: https://www.zabbix.org/wiki/Docs/howto/zabbix_get_jmx
# Requires 'nc' app
ZBXGET="/usr/bin/zabbix_get"
if [ $# != 5 ] && [ $# != 7 ]; then
echo "Usage: [=11=] <JAVA_GATEWAY_HOST> <JAVA_GATEWAY_PORT> <JMX_SERVER> <JMX_PORT> <KEY> [<JMX_USER> <JMX_PASS>]"
exit;
fi
# Escape backslashes and double-quotes
KEYS=$(echo | sed -e 's/\/\\\\/g' -e 's/"/\\"/g')
if [ $# = 5 ]; then
QUERY="{\"request\": \"java gateway jmx\",\"conn\": \"\",\"port\": ,\"keys\": [\"${KEYS}\"]}"
else
JMX_USER=""
JMX_PASS=""
QUERY="{\"request\": \"java gateway jmx\",\"conn\": \"\",\"port\": ,\"keys\": [\"${KEYS}\"],\"username\": \"${JMX_USER}\",\"password\": \"${JMX_PASS}\"}"
fi
# Prefix with binary header and length
QUERY_INTERPRETED=$(echo -en "${QUERY}")
QUERY_LEN=${#QUERY_INTERPRETED}
QUERY_LEN_BIN=$(printf "%.16x" ${QUERY_LEN} | sed "s/\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)/\\x\\x\\x\\x\\x\\x\\x\\x/")
QUERY_BIN="ZBXD\x01${QUERY_LEN_BIN}${QUERY}"
# Could not get zabbix_get 3.2.3 to work due to ZBX-11528 changes
# $ZBXGET -s -p -k "$QUERY"
echo -en "${QUERY_BIN}" | nc
我想要这样的东西:web.page.regexp[localhost,"/vi/health-check/api1",3345,(HTTP /1.1).([0-9]*),\2 ]
不确定那里有什么测试代码,或者 shell 脚本是如何关联的,但尚不支持 Zabbix 中的项目值解析,它将用于 Zabbix 3.4:https://support.zabbix.com/browse/ZBXNEXT-1443 .