中間件數據採集,解決jmx隨機端口問題[Linux]

注意:查看java環境變量,若java環境變量未設置,請填寫java的絕對路徑
一、配置jmx,開啓12345端口,另外一筆記有存檔 java

二、配置key或者上傳jmx.conf
中間件數據採集,解決jmx隨機端口問題[Linux]python

三、上傳cmdline-jmxclient-0.10.3.jar到/usr/local/zabbix/bin目錄
中間件數據採集,解決jmx隨機端口問題[Linux]shell


四、上傳gc_info.py和mpool_info.py到/usr/local/zabbix/scripts目錄(目前能夠優化,else條件 未使用) 腳本具體內容以下:

[root@tomcat scripts]# cat gc_info.py
#!/usr/bin/pythonjson

import os,subprocess,json
import argparsetomcat

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])app

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)ide

[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]rest

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)

五、重啓zabbix_agent
[root@tomcat scripts]# systemctl restart zabbix_agentd

六、導入模板,建立主機監控便可

七、附件以下:
中間件數據採集,解決jmx隨機端口問題[Linux]

相關文章
相關標籤/搜索