欢迎使用CSDN-markdown编辑器
2015-07-02 15:30
435 查看
Zabbix 监控Tomcat
IT辰逸 2014-12-01 75 阅读
CentOS
监控图如下:
zabbix-jmap
zabbix-jmap
代码如下,通过执行jmap heap处理堆信息生成一个Dict,实现的比较妖孽 需要依赖crontab 定时执行….(模板文末下载)
import re
import os
def runCommand(cmd,stdinstr = ”):
p=subprocess.Popen(cmd, shell=True, universal_newlines=True, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdoutdata, stderrdata = p.communicate(stdinstr)
return p.returncode, stdoutdata, stderrdata
def FormatValue():
Dict = {‘PSOldGeneration’:{‘percent’:”},’PSPermGeneration’:{‘percent’:”}}
_Output = runCommand(“”“jmap -heap
_NewOpt = [x for x in _Output if x]
for i in _NewOpt[-10:-7]:
Dict[‘PSOldGeneration’][i.split(‘=’)[0]] = re.findall(‘\d+’,i.split(‘=’)[1])[0]
if name == ‘main‘:
FormatValue()
生成的Dict.py
Dict = {‘PSOldGeneration’: {‘capacity’: ‘602406912’, ‘used’: ‘101426704’, ‘percent’: ‘16.8369090691974’, ‘free’: ‘500980208’}, ‘PSPermGeneration’: {‘capacity’: ‘268435456’, ‘used’: ‘71036880’, ‘percent’: ‘26.463299989700317’, ‘free’: ‘197398576’}}
if name == ‘main‘:
import sys
print Dict[sys.argv[1]][sys.argv[2]]
相关Key如下:
UserParameter=Tomcat.PSOldGeneration.capacity[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSOldGeneration capacity
UserParameter=Tomcat.PSOldGeneration.free[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSOldGeneration free
UserParameter=Tomcat.PSOldGeneration.used[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSOldGeneration used
UserParameter=Tomcat.PSOldGeneration.percent[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSOldGeneration percent
UserParameter=Tomcat.PSPermGeneration.capacity[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSPermGeneration capacity
UserParameter=Tomcat.PSPermGeneration.free[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSPermGeneration free
UserParameter=Tomcat.PSPermGeneration.used[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSPermGeneration used
UserParameter=Tomcat.PSPermGeneration.percent[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSPermGeneration percent
Zabbix-tomcat模板下载地址
百度云盘
腾讯云盘
文件信息:zbx_export_templates.xml
更新时间:2014-12-1 18:43
IT辰逸 2014-12-01 75 阅读
CentOS
使用Zabbix监控Tomcat 我早期使用了Zabbix的内置模板,因为得到的数据没太多用,后改用去调jmap的输出,现在每三分钟执行一次脚本,每30秒取一次值,PSPermGeneration和PSOldGeneration做为报警标准.
监控图如下:
zabbix-jmap
zabbix-jmap
代码如下,通过执行jmap heap处理堆信息生成一个Dict,实现的比较妖孽 需要依赖crontab 定时执行….(模板文末下载)
!/usr/bin/python
-conding:utf-8–
——————————————————————————-
Name: Jmap.py
#Author: LiuSha
#Created: 9/29/2014
Copyright: (c) WDZJ-SA 2014
——————————————————————————-
import subprocessimport re
import os
def runCommand(cmd,stdinstr = ”):
p=subprocess.Popen(cmd, shell=True, universal_newlines=True, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdoutdata, stderrdata = p.communicate(stdinstr)
return p.returncode, stdoutdata, stderrdata
def FormatValue():
Dict = {‘PSOldGeneration’:{‘percent’:”},’PSPermGeneration’:{‘percent’:”}}
_Output = runCommand(“”“jmap -heap
ps aux | grep "/home/tomcat/tomcat/apache-tomcat-7.0.53/conf/logging.properties" | awk '!/grep/{print $2}'“”“)[1].replace(’ ‘,”).split(‘\n’)
_NewOpt = [x for x in _Output if x]
for i in _NewOpt[-10:-7]:
Dict[‘PSOldGeneration’][i.split(‘=’)[0]] = re.findall(‘\d+’,i.split(‘=’)[1])[0]
Dict['PSOldGeneration']['percent'] = re.findall('\d+\D+\d+',_NewOpt[-7])[0] for i in _NewOpt[-5:-2]: Dict['PSPermGeneration'][i.split('=')[0]] = re.findall('\d+',i.split('=')[1])[0] Dict['PSPermGeneration']['percent'] = re.findall('\d+\D+\d+',_NewOpt[-2])[0] file = open('%s/Dict.py'%os.path.dirname(__file__),'w') file.write("""Dict = %s\n\nif __name__ == '__main__': import sys print Dict[sys.argv[1]][sys.argv[2]]"""%repr(Dict)) file.close()
if name == ‘main‘:
FormatValue()
生成的Dict.py
Dict = {‘PSOldGeneration’: {‘capacity’: ‘602406912’, ‘used’: ‘101426704’, ‘percent’: ‘16.8369090691974’, ‘free’: ‘500980208’}, ‘PSPermGeneration’: {‘capacity’: ‘268435456’, ‘used’: ‘71036880’, ‘percent’: ‘26.463299989700317’, ‘free’: ‘197398576’}}
if name == ‘main‘:
import sys
print Dict[sys.argv[1]][sys.argv[2]]
相关Key如下:
UserParameter=Tomcat.PSOldGeneration.capacity[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSOldGeneration capacity
UserParameter=Tomcat.PSOldGeneration.free[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSOldGeneration free
UserParameter=Tomcat.PSOldGeneration.used[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSOldGeneration used
UserParameter=Tomcat.PSOldGeneration.percent[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSOldGeneration percent
UserParameter=Tomcat.PSPermGeneration.capacity[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSPermGeneration capacity
UserParameter=Tomcat.PSPermGeneration.free[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSPermGeneration free
UserParameter=Tomcat.PSPermGeneration.used[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSPermGeneration used
UserParameter=Tomcat.PSPermGeneration.percent[*],/usr/bin/python /software/zabbix/scripts/Dict.py PSPermGeneration percent
Zabbix-tomcat模板下载地址
百度云盘
腾讯云盘
文件信息:zbx_export_templates.xml
更新时间:2014-12-1 18:43
» 转载保留版权:IT辰逸 » 《Zabbix 监控Tomcat》 » 本文链接地址:http://www.ipython.me/centos/zabbix-monitor-tomcat.html
相关文章推荐
- shu_1241 邮局位置问题
- C#增删改查
- 且行且珍惜,我的极客导航
- 【PHP】session失效时间
- memcached安装
- JSP 页面中用绝对路径显示图片
- android GPS度分秒与double之间的相互转化
- Java 递归解决 "只能两数相乘的计算器计算x^y" 问题
- mongo导出导入
- 润乾填报表的时间参数设置
- android 动画资源
- 无法打开文件“atlsd.lib”
- ArduinoYun教程之Arduino环境与Linux环境的桥梁Bridge
- UVALive 6665 Dragon’s Cruller (BFS + 优先队列+hash)
- web开发学习笔记
- Git详解之四 服务器上的Git
- 被谷歌控制的 Android 不是好 Android?
- iOS获取图片并上传
- JSP中javaBean一些问题
- Trapping Rain Water 左右指针寻找最大容量的水