《loadrunner监控tomcat.doc》由会员分享,可在线阅读,更多相关《loadrunner监控tomcat.doc(15页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、如有侵权,请联系网站删除,仅供学习与交流loadrunner监控tomcat【精品文档】第 15 页通过JConsole监控Tomcat1、打开tomcat5的bin目录中的catalina.bat文件,在头部注释部分的后面加上:set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false2、修改JMX远程访问授权。进入JAVA安装目录的jre
2、6libmanagement目录,把jmxremote.password.template文件改名为jmxremote.password,去掉最后两行的注释(用户名和密码):monitorRoleQEDcontrolRoleR&D确保jmxremote.access文件末尾的访问角色没有被注释掉:monitorRolereadonlycontrolRolereadwrite create javax.management.monitor.*,javax.management.timer.* unregister然后分别选择这两个文件,点右键“属性”-安全,点“高级”,去掉“从父项继承.”,弹出
3、窗口中选“删除”,这样删除了所有访问权限。再选“添加”-高级,“立即查找”,选中你的用户,例administrator,点“确定,“确定。来到权限窗口,勾选完全控制,点确定注:JDK好像需要装在NTFS文件系统下才行3、启动Tomcat4、在命令行输入netstat -an查看端口8999是否已经打开,如果没有,则是前面的配置没配好。5、如果已经配置好,则在命令行输入jconsole,打开jdk自带的JMX客户端,选择远程连接,录入tomcat所在机器的IP,端口例192.168.1.100:8999,帐号、密码在jmxremote.password中,如帐号controlRole,密码R&D
4、(缺省monitorRole只能读,controlRole能读写,jmxremote.access中可配置)。点“连接”。参考:编写JAVA程序收集Tomcat性能数据importjava.lang.management.MemoryUsage;importjava.text.SimpleDateFormat;importjava.util.Date;importjava.util.Formatter;importjava.util.HashMap;importjava.util.Iterator;importjava.util.Map;importjava.util.Set;importja
5、vax.management.MBeanAttributeInfo;importjavax.management.MBeanInfo;importjavax.management.MBeanServerConnection;importjavax.management.ObjectInstance;importjavax.management.ObjectName;importjavax.management.openmbean.CompositeDataSupport;importjavax.management.remote.JMXConnector;importjavax.managem
6、ent.remote.JMXConnectorFactory;importjavax.management.remote.JMXServiceURL;publicclassMonitorTomcat *paramargspublicstaticvoidmain(String args) tryString jmxURL =service:jmx:rmi:/jndi/rmi:/192.168.1.100:8999/jmxrmi;/tomcatjmxurlJMXServiceURL serviceURL =newJMXServiceURL(jmxURL);Mapmap =newHashMap();
7、String credentials =newString monitorRole,QED;map.put(jmx.remote.credentials, credentials);JMXConnector connector = JMXConnectorFactory.connect(serviceURL,map);MBeanServerConnectionmbsc = connector.getMBeanServerConnection();/端口最好是动态取得ObjectName threadObjName =newObjectName(Catalina:type=ThreadPool,
8、name=http-8080);MBeanInfo mbInfo = mbsc.getMBeanInfo(threadObjName);String attrName =currentThreadCount;/tomcat的线程数对应的属性值MBeanAttributeInfombAttributes= mbInfo.getAttributes();System.out.println(currentThreadCount:+mbsc.getAttribute(threadObjName, attrName);/heapfor(intj=0;j mbsc.getDomains().length
9、;j+)System.out.println(#+mbsc.getDomains()j);SetMBeanset = mbsc.queryMBeans(null,null);System.out.println(MBeanset.size() : + MBeanset.size();IteratorMBeansetIterator = MBeanset.iterator();while(MBeansetIterator.hasNext() ObjectInstance objectInstance = (ObjectInstance)MBeansetIterator.next();Object
10、Name objectName = objectInstance.getObjectName();String canonicalName = objectName.getCanonicalName();System.out.println(canonicalName : + canonicalName);if(canonicalName.equals(Catalina:host=localhost,type=Cluster)/ Get details of cluster MBeansSystem.out.println(Cluster MBeans Details:);System.out
11、.println(=);/getMBeansDetails(canonicalName);StringcanonicalKeyPropList= objectName.getCanonicalKeyPropertyListString();/- system -ObjectName runtimeObjName =newObjectName(java.lang:type=Runtime);System.out.println(厂商:+ (String)mbsc.getAttribute(runtimeObjName,VmVendor);System.out.println(程序:+ (Stri
12、ng)mbsc.getAttribute(runtimeObjName,VmName);System.out.println(版本:+ (String)mbsc.getAttribute(runtimeObjName,VmVersion);Date starttime=newDate(Long)mbsc.getAttribute(runtimeObjName,StartTime);SimpleDateFormat df =newSimpleDateFormat(yyyy-MM-dd HH:mm:ss);System.out.println(启动时间:+df.format(starttime);
13、Long timespan=(Long)mbsc.getAttribute(runtimeObjName,Uptime);System.out.println(连续工作时间:+MonitorTomcat.formatTimeSpan(timespan);/- JVM -/堆使用率ObjectName heapObjName =newObjectName(java.lang:type=Memory);MemoryUsage heapMemoryUsage =MemoryUsage.from(CompositeDataSupport)mbsc.getAttribute(heapObjName,He
14、apMemoryUsage);longmaxMemory= heapMemoryUsage.getMax();/堆最大longcommitMemory = heapMemoryUsage.getCommitted();/堆当前分配longusedMemory = heapMemoryUsage.getUsed();System.out.println(heap:+(double)usedMemory*100/commitMemory+%);/堆使用率MemoryUsage nonheapMemoryUsage =MemoryUsage.from(CompositeDataSupport)mbs
15、c.getAttribute(heapObjName,NonHeapMemoryUsage);longnoncommitMemory = nonheapMemoryUsage.getCommitted();longnonusedMemory = heapMemoryUsage.getUsed();System.out.println(nonheap:+(double)nonusedMemory*100/noncommitMemory+%);ObjectName permObjName =newObjectName(java.lang:type=MemoryPool,name=Perm Gen)
16、;MemoryUsage permGenUsage =MemoryUsage.from(CompositeDataSupport)mbsc.getAttribute(permObjName,Usage);longcommitted = permGenUsage.getCommitted();/持久堆大小longused = heapMemoryUsage.getUsed();/System.out.println(perm gen:+(double)used*100/committed+%);/持久堆使用率/- Session -ObjectName managerObjName =newOb
17、jectName(Catalina:type=Manager,*);Set s=mbsc.queryNames(managerObjName,null);for(ObjectName obj:s)System.out.println(应用名:+obj.getKeyProperty(path);ObjectNameobjname=newObjectName(obj.getCanonicalName();System.out.println(最大会话数:+ mbsc.getAttribute(objname,maxActiveSessions);System.out.println(会话数:+ m
18、bsc.getAttribute(objname,activeSessions);System.out.println(活动会话数:+ mbsc.getAttribute(objname,sessionCounter);/- Thread Pool -ObjectName threadpoolObjName =newObjectName(Catalina:type=ThreadPool,*);Set s2=mbsc.queryNames(threadpoolObjName,null);for(ObjectName obj:s2)System.out.println(端口名:+obj.getKe
19、yProperty(name);ObjectName objname=newObjectName(obj.getCanonicalName();System.out.println(最大线程数:+ mbsc.getAttribute( objname,maxThreads);System.out.println(当前线程数:+ mbsc.getAttribute( objname,currentThreadCount);System.out.println(繁忙线程数:+ mbsc.getAttribute( objname,currentThreadsBusy);catch(Exceptio
20、n e) e.printStackTrace();publicstaticString formatTimeSpan(longspan)longminseconds = span % 1000;span = span /1000;longseconds = span % 60;span = span / 60;longmins = span % 60;span = span / 60;longhours = span % 24;span = span / 24;longdays = span;return(newFormatter().format(%1$d天%2$02d:%3$02d:%4$
21、02d.%5$03d, days,hours,mins,seconds,minseconds).toString();记录的数据:currentThreadCount:150#JMImplementation#Users#com.sun.management#Catalina#java.lang#java.util.loggingMBeanset.size() : 383canonicalName : Catalina:name=HttpRequest152,type=RequestProcessor,worker=http-8080canonicalName : Catalina:J2EEA
22、pplication=none,J2EEServer=none,WebModule=/localhost/jsp-examples,j2eeType=Servlet,name=org.apache.jsp.jsp2.el.basic_002dcomparisons_jspcanonicalName : Catalina:port=8009,type=MappercanonicalName : Catalina:J2EEApplication=none,J2EEServer=none,WebModule=/localhost/jsp-examples,j2eeType=Servlet,name=
23、org.apache.jsp.dates.date_jsp厂商:Sun Microsystems Inc.程序:Java HotSpot(TM) Client VM版本:11.3-b02启动时间:2010-02-0911:36:59连续工作时间:0天00:13:55.775heap:62.221410820735%nonheap:84.59782727899399%perm gen:210.93058268229166%应用名:/jsp-examples最大会话数:-1会话数:0活动会话数:0应用名:/最大会话数:-1会话数:0活动会话数:0应用名:/host-manager最大会话数:-1会
24、话数:0活动会话数:0应用名:/tomcat-docs最大会话数:-1会话数:0活动会话数:0应用名:/AltoroJ最大会话数:-1会话数:301活动会话数:301应用名:/webdav最大会话数:-1会话数:0活动会话数:0应用名:/servlets-examples最大会话数:-1会话数:0活动会话数:0应用名:/manager最大会话数:-1会话数:0活动会话数:0应用名:/balancer最大会话数:-1会话数:0活动会话数:0端口名:http-8080最大线程数:150当前线程数:150繁忙线程数:100端口名:jk-8009最大线程数:200当前线程数:4繁忙线程数:1参考:使用
25、LR的lr_user_data_point函数/ This script collects server metrics from the Tomcat Status page (http:/127.0.0.1:8080/manager/status)./ Runtime settings are set to run this script once every 5 seconds.double atof (const char *string); /* Explicit declaration */extern char* strtok(char *token, const char *d
26、elimiter);CollectMetrics()int countP, countS, countF, countR, countK;int numValues;static int loggedVersionInfo = FALSE;lr_save_string(127.0.0.1:8080, ServerName);web_set_max_html_param_len(102480); / 65536 Note: this may need to be increased.web_set_user(admin,123456,ServerName);lr_start_transactio
27、n(monitor tomcat);JVM Free memory: 130.99 MB Total memory: 254.18 MB Max memory: 1016.12 MBweb_reg_save_param(JVMFreeMemory,LB=Free memory: ,RB= MB,Ord=1,LAST);web_reg_save_param(JVMTotalMemory,LB=Total memory: ,RB= MB,Ord=1,LAST);web_reg_save_param(JVMMaxMemory,LB=Max memory: ,RB= MB,Ord=1,LAST);ht
28、tp-8080 Max threads: 150 Min spare threads: 25 Max spare threads: 75 Currentthread count: 25 Current thread busy: 2Max processing time: 78 ms Processing time: 0.124 sRequest count: 11 Error count: 3 Bytes received: 0.00 MB Bytes sent: 0.03 MBweb_reg_save_param(HTTPMaxThreads,LB=Max threads: ,RB= ,Or
29、d=1,LAST);web_reg_save_param(HTTPMinSpareThreads,LB=Min spare threads: ,RB= ,Ord=1,LAST);web_reg_save_param(HTTPMaxSpareThreads,LB=Max spare threads: ,RB= ,Ord=1,LAST);web_reg_save_param(HTTPCurrentSpareThreads,LB=Current thread count: ,RB= ,Ord=1,LAST);web_reg_save_param(HTTPCurrentThreadBusy,LB=Cu
30、rrent thread busy: ,RB= ,Ord=1,LAST);web_reg_save_param(HTTPMaxProcessingTime,LB=Max processing time: ,RB= ,Ord=1,LAST);web_reg_save_param(HTTPRequestCount,LB=Request count: ,RB= ,Ord=1,LAST);web_reg_save_param(HTTPErrorCount,LB=Error count: ,RB= ,Ord=1,LAST);web_reg_save_param(HTTPBytesReceived,LB=
31、Bytes received: ,RB= ,Ord=1,LAST);web_reg_save_param(HTTPBytesSent,LB=Bytes sent: ,RB= ,Ord=1,LAST);jk-8009 Max threads: 200 Min spare threads: 4 Max spare threads: 50 Current thread count: 8 Current thread busy: 6 Max processing time: 8031 ms Processing time: 199.1 s Request count: 11279 Error coun
32、t: 426 Bytes received: 0.00 MB Bytes sent: 100.88 MBweb_reg_save_param(JKMaxThreads,LB=Max threads: ,RB= ,Ord=2,LAST);web_reg_save_param(JKMinSpareThreads,LB=Min spare threads: ,RB= ,Ord=2,LAST);web_reg_save_param(JKMaxSpareThreads,LB=Max spare threads: ,RB= ,Ord=2,LAST);web_reg_save_param(JKCurrent
33、SpareThreads,LB=Current thread count: ,RB= ,Ord=2,LAST);web_reg_save_param(JKCurrentThreadBusy,LB=Current thread busy: ,RB= ,Ord=2,LAST);web_reg_save_param(JKMaxProcessingTime,LB=Max processing time: ,RB= ,Ord=2,LAST);web_reg_save_param(JKRequestCount,LB=Request count: ,RB= ,Ord=2,LAST);web_reg_save_param(JKErrorCount,LB=Error count: ,RB= ,Ord=2,LAST);web_reg_save_param(JKBytesReceived,LB=Bytes received: ,RB= ,Ord=2,LAST);web_reg_save_param(JKBytesSent,LB=Bytes sent: ,RB= ,Ord=2,LAST);/ Version InformationServer InformationTomcat VersionJVM VersionJVM VendorOS Nametd clas
限制150内