Wrapping in Python
The problem with jmxterm si that its startup time is really long - even several seconds. Also connecting to process can take second or two. The reponsivness is good so if you need it for periodic monitoring, you would like to start it and connect and then fire requests when you need the data. After trying some approaches I settled on Python pexpect for this (script reduced to minimum):
import time import pexpect connection = "localhost:3993" connection_timeout = 2 jmxterm = pexpect.spawn("java -jar jmxterm-1.0-alpha-4-uber.jar") jmxterm.expect_exact("$>") # got prompt, we can continue jmxterm.sendline("open " + connection) jmxterm.expect_exact("#Connection to "+connection+" is opened", connection_timeout) jmxterm.sendline("get -d Catalina -b name=http-80,type=ThreadPool currentThreadCount") response_lines = [] response_lines.append(jmxterm.readline()) response_lines.append(jmxterm.readline()) response_lines.append(jmxterm.readline()) response_lines.append(jmxterm.readline()) result = response_lines[3].replace(";"," ").strip().split(" ") del result[1] name,value = result print "["+time.ctime()+"]", name, "=", value jmxterm.sendline("quit")
Read full article from rostislav.matl: Monitoring Tomcat with Jmxterm and Python
No comments:
Post a Comment