注意:查看java环境变量,若java环境变量未设置,请填写java的绝对路径
1、配置jmx,开启12345端口,另一笔记有存档
2、配置key或者上传jmx.conf
3、上传cmdline-jmxclient-0.10.3.jar到/usr/local/zabbix/bin目录
4、上传gc_info.py和mpool_info.py到/usr/local/zabbix/scripts目录(目前可以优化,else条件 未使用) 脚本具体内容如下:
[root@tomcat scripts]# cat gc_info.py
#!/usr/bin/python
import os,subprocess,json
import argparse
def gc_info(name_info, ip, port):
data = {}
disk_lists = []
info_list = []
if name_info == None:
p = subprocess.Popen("java -jar /usr/local/zabbix/bin/cmdline-jmxclient0.10.3.jar - " + ip +":" + port + "|grep type=GarbageCollector", shell=True, stdout=subprocess.PIPE) disk_infos = p.stdout.readlines()
for disk_info in disk_infos:
line = disk_info.split(",")
line = line[0]
line = line.split("=")
#line=line.strip()
disk_lists.append(line)
for disk_list in disk_lists:
disk_dict = {}
disk_dict['{#GC}'] = disk_list[1]
info_list.append(disk_dict)
data['data'] = info_list
jsonStr = json.dumps(data, sort_keys=True, indent=4)
print (jsonStr)
else:
p = subprocess.Popen("java -jar /usr/local/zabbix/bin/cmdline-jmxclient0.10.3.jar - 127.0.0.1:12345 |grep GarbageCollector", shell=True, stdout=subprocess.PIPE) disk_infos = p.stdout.readlines()
for disk_info in disk_infos:
line = disk_info.split(",")
disk_lists.append(line)
#print disk_infos
for disk_list in disk_lists:
if name_info == disk_list[0]:
print (disk_list[1])
if name == "main":
parser = argparse.ArgumentParser()
parser.add_argument('--name',type=str, default = None)
parser.add_argument('--ip',type=str, default = None)
parser.add_argument('--port',type=str, default = None)
args = parser.parse_args()
gc_info(args.name, args.ip, args.port)
[root@tomcat scripts]# cat mpool_info.py
import os,subprocess,json
import argparse
def memorypool_info(name_info, ip, port):
data = {}
disk_lists = []
info_list = []
if name_info == None:
p = subprocess.Popen("java -jar /usr/local/zabbix/bin/cmdline-jmxclient0.10.3.jar - " + ip +":" + port + "|grep MemoryPool", shell=True, stdout=subprocess.PIPE) disk_infos = p.stdout.readlines()
for disk_info in disk_infos:
line = disk_info.split(",")
line = line[0]
line = line.split("=")
#line=line.strip()
disk_lists.append(line)
#print (disk_lists)
for disk_list in disk_lists:
disk_dict = {}
disk_dict['{#MPOOL}'] = disk_list[1]
info_list.append(disk_dict)
data['data'] = info_list
jsonStr = json.dumps(data, sort_keys=True, indent=4)
print (jsonStr)
else:
p = subprocess.Popen("java -jar /usr/local/java/cmdline-jmxclient0.10.3.jar - 127.0.0.1:12345 |grep MemoryPool", shell=True, stdout=subprocess.PIPE)
disk_infos = p.stdout.readlines()
for disk_info in disk_infos:
line = disk_info.split(",")
disk_lists.append(line)
#print disk_infos
for disk_list in disk_lists:
if name_info == disk_list[0]:
print (disk_list[1])
if name == "main":
parser = argparse.ArgumentParser()
parser.add_argument('--name',type=str, default = None)
parser.add_argument('--ip',type=str, default = None)
parser.add_argument('--port',type=str, default = None)
args = parser.parse_args()
memorypool_info(args.name, args.ip, args.port)
5、重启zabbix_agent
[root@tomcat scripts]# systemctl restart zabbix_agentd
6、导入模板,创建主机监控即可
7、附件如下: