最近在看jmeter服务器监控部分,网上有JMeterPlugins插件可以监控到服务器的CPU/memory、IO、硬盘等信息,就下载安装一下。具体操作步骤如下:
1.下载JMeterPlugins插件:
分两部分: ServerAgent-2.2.1.zip (服务器监听) JMeterPlugins-Standard-1.3.0.zip(本机jmeter插件部分)
2.解压缩到本地目录 E:\apache-jmeter-2.13\lib\ext
解压缩 ServerAgent-2.2.1.zip,到监控服务器目录下
/opt/apache-jmeter-2.9/ServerAgent-2.2.1
运行:sh startAgent.sh
[root@vm-10-154-156-238 ServerAgent-2.2.1]# ls
CMDRunner.jar lib LICENSE ServerAgent.jar startAgent.bat startAgent.sh
[root@vm-10-154-156-238 ServerAgent-2.2.1]# sh startAgent.sh
INFO 2015-08-25 11:36:44.947 [kg.apc.p] (): Binding UDP to 4444
INFO 2015-08-25 11:36:45.953 [kg.apc.p] (): Binding TCP to 4444
INFO 2015-08-25 11:36:45.960 [kg.apc.p] (): JP@GC Agent v2.2.0 started
3.修改jmeter安装路径中:bin/jmeter.properties文件的以下行:(jmeterplugins 和thread有关系所以要修改配置文件)
jmeter.save.saveservice.thread_counts=true
4.启动JMeter就可以看到多了很多jp@gc开头的选项(windows下启动)
5.liunx 无界面启动
在linux下使用non gui模式的命令是:
./jmeter.sh -n -t testplan.jmx -l result.jtl
testplan.jmx就是测试计划文件,result.jtl就是结果文件,如果没有把thread_count这个参数打开是不会记录到线程有关的信息的:
<httpSample t="363" lt="363" ts="1301644667897" s="true" lb="http://localhost/" rc="200" rm="OK" tn="Thread Group 1-138" dt="text" by="7888" ng="200" na="200"/>
ng代表当前线程组中有多少活动线程
na代表整个测试中有多少活动线程
如果没有打开thread_count参数就不会有ng和na的值了。
顺带在说明一下别的参数的意思:
• t表示从请求开始到响应结束的时间
• lt表示整个的空闲时间
• ts表示访问的时刻
• s表示返回的结果true表示成功,false表示失败
• lb表示标题
• rc表示返回的响应码
• rm表示响应信息
• tn表示线程的名字“1-138”表示第1个线程组的第138个线程。
• dt表示响应的文件类型
• by表示请求和响应的字节数
6.在jmeter中添加各种监控图标
添加路径:线程组-》添加-》监控
监控:jp@gc - PerfMon Metrics Collectot(cup/memory/io/硬盘等)
7.在liunx上运行监控插件
生成 LatenciesOverTime 图片
java -jar /app/jmeter02/app/apache-jmeter-2.9/lib/ext/CMDRunner.jar --tool Reporter --input-jtl /app/jmeter02/app/apache-jmeter-2.9/bin/testresult0825.jtl --plugin-type LatenciesOverTime --generate-png report-latency.png
testresult0825.jtl----解析结果文件
生成 TransactionsPerSecond 图片
java -jar /app/jmeter02/app/apache-jmeter-2.9/lib/ext/CMDRunner.jar --tool Reporter --input-jtl /app/jmeter02/app/apache-jmeter-2.9/bin/testresult0825.jtl --plugin-type TransactionsPerSecond --generate-png report-transactionPerSec.png
testresult0825.jtl-----解析结果文件
生成 添加监控 cpu、io、硬盘、memory图片(这个也可以各项分别设置(cpu、io、memory、硬盘))
java -jar /app/jmeter02/app/apache-jmeter-2.9/lib/ext/CMDRunner.jar --tool Reporter --input-jtl /app/jmeter02/app/apache-jmeter-2.9/bin/cpu.jtl --plugin-type PerfMon --generate-png report-cpu.png
cpu.jtl------解析监控文件
********************************************************************************************************************
1440488812595,17455,10.154.156.238 Memory,,,,,true,0,0,0,0
1440488812595,1000,10.154.156.238 CPU,,,,,true,0,0,0,0
1440488812595,21876736000,10.154.156.238 Swap,,,,,true,0,0,0,0
1440488812595,1940000,10.154.156.238 Network I/O,,,,,true,0,0,0,0
1440488813595,17455,10.154.156.238 Memory,,,,,true,0,0,0,0
1440488813595,1500,10.154.156.238 CPU,,,,,true,0,0,0,0
1440488813595,21876736000,10.154.156.238 Swap,,,,,true,0,0,0,0
1440488813595,2432000,10.154.156.238 Network I/O,,,,,true,0,0,0,0
1440488814595,17455,10.154.156.238 Memory,,,,,true,0,0,0,0
1440488814595,497,10.154.156.238 CPU,,,,,true,0,0,0,0
1440488814595,21876736000,10.154.156.238 Swap,,,,,true,0,0,0,0
1440488814595,1364000,10.154.156.238 Network I/O,,,,,true,0,0,0,0
1440488815596,17455,10.154.156.238 Memory,,,,,true,0,0,0,0
1440488815596,505,10.154.156.238 CPU,,,,,true,0,0,0,0
1440488815596,21876736000,10.154.156.238 Swap,,,,,true,0,0,0,0
1440488815596,3520000,10.154.156.238 Network I/O,,,,,true,0,0,0,0
1440488816596,17445,10.154.156.238 Memory,,,,,true,0,0,0,0
1440488816596,2000,10.154.156.238 CPU,,,,,true,0,0,0,0
1440488816596,21876736000,10.154.156.238 Swap,,,,,true,0,0,0,0
1440488816596,3339000,10.154.156.238 Network I/O,,,,,true,0,0,0,0
1440488817596,17467,10.154.156.238 Memory,,,,,true,0,0,0,0
1440488817596,32663,10.154.156.238 CPU,,,,,true,0,0,0,0
1440488817596,21876736000,10.154.156.238 Swap,,,,,true,0,0,0,0
************************************************************************************************************************
8.使用过程中遇到报错信息的解决
在运行java -jar /app/jmeter02/app/apache-jmeter-2.9/lib/ext/CMDRunner.jar --tool Reporter --input-jtl /app/jmeter02/app/apache-jmeter-2.9/bin/testresult0825.jtl --plugin-type LatenciesOverTime --generate-png report-latency.png
报错1:
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: kg.apc.jmeter.vizualizers.LatenciesOverTimeGui
at kg.apc.jmeter.PluginsCMDWorker.getGUIObject(PluginsCMDWorker.java:236)
at kg.apc.jmeter.PluginsCMDWorker.getGUIObject(PluginsCMDWorker.java:233)
at kg.apc.jmeter.PluginsCMDWorker.getGUIObject(PluginsCMDWorker.java:229)
at kg.apc.jmeter.PluginsCMDWorker.setPluginType(PluginsCMDWorker.java:73)
at kg.apc.cmdtools.ReporterTool.processParams(ReporterTool.java:97)
at kg.apc.cmdtools.PluginsCMD.processParams(PluginsCMD.java:63)
at kg.apc.cmdtools.PluginsCMD.processParams(PluginsCMD.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at kg.apc.cmd.UniversalRunner.main(UniversalRunner.java:174)
Caused by: java.lang.ClassNotFoundException: kg.apc.jmeter.vizualizers.LatenciesOverTimeGui
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at kg.apc.jmeter.PluginsCMDWorker.getGUIObject(PluginsCMDWorker.java:226)
... 11 more
未解决。。。。
报错2:在之前windows使用的jmeter运行jmeterplugins 中gui不显示jp@gc,在cmd中运行报错
D:\apache-jmeter-2.9\bin>java -jar E:\apache-jmeter-2.13\lib\ext\CMDRunner.jar -
-tool Reporter --input-jtl E:\apache-jmeter-2.13\bin\testresult.jtl --plugin-typ
e LatenciesOverTime --generate-png report-latency.png
INFO 2015-08-26 23:09:58.332 [kg.apc.j] (): Using JMeterPluginsCMD v. 1.3.0
INFO 2015-08-26 23:09:58.358 [jmeter.u] (): Setting Locale to zh_CN
INFO 2015-08-26 23:09:58.386 [kg.apc.j] (): Loading user properties from: D:\
apache-jmeter-2.9\bin\user.properties
INFO 2015-08-26 23:09:58.425 [kg.apc.j] (): Loading system properties from: D
:\apache-jmeter-2.9\bin\system.properties
ERROR: java.lang.RuntimeException: java.lang.ClassNotFoundException: kg.apc.jmet
er.vizualizers.LatenciesOverTimeGui
*** Problem's technical details go below ***
Home directory was detected as: E:\apache-jmeter-2.13\lib\ext
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundEx
ception: kg.apc.jmeter.vizualizers.LatenciesOverTimeGui
at kg.apc.jmeter.PluginsCMDWorker.getGUIObject(PluginsCMDWorker.java:236
)
at kg.apc.jmeter.PluginsCMDWorker.getGUIObject(PluginsCMDWorker.java:233
)
at kg.apc.jmeter.PluginsCMDWorker.getGUIObject(PluginsCMDWorker.java:229
)
at kg.apc.jmeter.PluginsCMDWorker.setPluginType(PluginsCMDWorker.java:73
)
at kg.apc.cmdtools.ReporterTool.processParams(ReporterTool.java:97)
at kg.apc.cmdtools.PluginsCMD.processParams(PluginsCMD.java:63)
at kg.apc.cmdtools.PluginsCMD.processParams(PluginsCMD.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at kg.apc.cmd.UniversalRunner.main(UniversalRunner.java:174)
Caused by: java.lang.ClassNotFoundException: kg.apc.jmeter.vizualizers.Latencies
OverTimeGui
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at kg.apc.jmeter.PluginsCMDWorker.getGUIObject(PluginsCMDWorker.java:226
)
... 11 more
已经解决:从新在官网上下载一个jmeter2.13版本,能正常使用。
报错3 :在liunx下其中一台加压机报这样的错误
java -jar /app/jmeter02/app/apache-jmeter-2.9/lib/ext/CMDRunner.jar --tool Reporter --input-jtl /app/jmeter02/app/apache-jmeter-2.9/bin/cpu.jtl --plugin-type PerfMon --generate-png report-cpu.png
INFO 2015-08-26 10:10:04.620 [kg.apc.j] (): Using JMeterPluginsCMD v. 1.3.0
INFO 2015-08-26 10:10:04.658 [jmeter.u] (): Setting Locale to en_US
INFO 2015-08-26 10:10:04.682 [kg.apc.j] (): Loading user properties from: /app/jmeter02/app/apache-jmeter-2.9/bin/user.properties
INFO 2015-08-26 10:10:04.683 [kg.apc.j] (): Loading system properties from: /app/jmeter02/app/apache-jmeter-2.9/bin/system.properties
ERROR: java.lang.UnsatisfiedLinkError: /usr/java/jdk1.8.0_45/jre/lib/i386/libfontmanager.so: libgcc_s.so.1: cannot open shared object file: No such file or directory
*** Problem's technical details go below ***
Home directory was detected as: /app/jmeter02/app/apache-jmeter-2.9/lib/ext
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/java/jdk1.8.0_45/jre/lib/i386/libfontmanager.so: libgcc_s.so.1: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1937)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1843)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at sun.font.FontManagerNativeLibrary$1.run(FontManagerNativeLibrary.java:61)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.FontManagerNativeLibrary.<clinit>(FontManagerNativeLibrary.java:32)
at sun.font.SunFontManager$1.run(SunFontManager.java:339)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.SunFontManager.<clinit>(SunFontManager.java:335)
at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:264)
at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1113)
at javax.swing.JComponent.getFontMetrics(JComponent.java:1626)
at javax.swing.text.PlainView.calculateLongestLine(PlainView.java:639)
at javax.swing.text.PlainView.updateMetrics(PlainView.java:209)
at javax.swing.text.PlainView.updateDamage(PlainView.java:527)
at javax.swing.text.PlainView.insertUpdate(PlainView.java:451)
at javax.swing.text.FieldView.insertUpdate(FieldView.java:293)
at javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(BasicTextUI.java:1610)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1869)
at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:201)
at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:748)
at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:707)
at javax.swing.text.PlainDocument.insertString(PlainDocument.java:130)
at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:669)
at javax.swing.text.JTextComponent.setText(JTextComponent.java:1669)
at org.apache.jmeter.gui.NamePanel.setName(NamePanel.java:85)
at org.apache.jmeter.gui.NamePanel.<init>(NamePanel.java:45)
at org.apache.jmeter.gui.AbstractJMeterGuiComponent.<init>(AbstractJMeterGuiComponent.java:78)
at org.apache.jmeter.visualizers.gui.AbstractListenerGui.<init>(AbstractListenerGui.java:32)
at org.apache.jmeter.visualizers.gui.AbstractVisualizer.<init>(AbstractVisualizer.java:127)
at kg.apc.jmeter.graphs.AbstractGraphPanelVisualizer.<init>(AbstractGraphPanelVisualizer.java:116)
at kg.apc.jmeter.graphs.AbstractOverTimeVisualizer.<init>(AbstractOverTimeVisualizer.java:13)
at kg.apc.jmeter.vizualizers.PerfMonGui.<init>(PerfMonGui.java:69)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at kg.apc.jmeter.PluginsCMDWorker.getGUIObject(PluginsCMDWorker.java:240)
at kg.apc.jmeter.PluginsCMDWorker.getGUIObject(PluginsCMDWorker.java:233)
at kg.apc.jmeter.PluginsCMDWorker.getGUIObject(PluginsCMDWorker.java:229)
at kg.apc.jmeter.PluginsCMDWorker.setPluginType(PluginsCMDWorker.java:73)
at kg.apc.cmdtools.ReporterTool.processParams(ReporterTool.java:97)
at kg.apc.cmdtools.PluginsCMD.processParams(PluginsCMD.java:63)
at kg.apc.cmdtools.PluginsCMD.processParams(PluginsCMD.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at kg.apc.cmd.UniversalRunner.main(UniversalRunner.java:174)
解决方法:
yum install glibc.i686 yum install glibc-devel yum install libstdc++.i686
9.另外一个监控cpu的工具(连接远程进程,没有测试通过。。。本地连接可以用)
监控内存及CPU等(jconsole)
最近逛论坛的时候,发现了一个比较好的监控内存CPU等的小工具,本着开源小工具多多益善的原则,记录一下。
打开这个小工具的步骤很简单,如果你已经配置好了Jmeter运行的环境,那么你也就不用去做其他的配置,直接 点击:开始——》运行——》输入cmd——》然后在出现的命令行界面输入“jconsole”即可弹出一个【java监视和管理控制台】,
将会弹出如下界面:
这里我们选择本地进程,并点击一下sun.tools.jconsole.JConsole这一行,然后点击连接,就可以查看我们的内存和CPU的使用情况了。
当然,我们要得到服务器的内存使用等信息,也可以选择 本地进程下面的远程进程,在文本框中输入我们需要测试的服务器的IP地址:端口,然后在下面输入用户名和密码,点击连接,看看会出现什么情况。
JMeter Properties 没有找到在那配置
- jmeterPlugin.perfmon.interval - metrics collection interval in milliseconds ---------- 指标收集时间间隔,单位是毫秒
- jmeterPlugin.perfmon.useUDP - true/false, enabling UDP connection try after failed TCP connection attempt--------值为 true 或 false,在 TCP 连接失败后是否尝试 UDP 连接
- jmeterPlugin.perfmon.label.useHostname - true/false, enable using "short" hostnames, default pattern is ([\w\-]+)\..*
- jmeterPlugin.perfmon.label.useHostname.pattern - string (escaped), regular expression to extract hostname (first group is matched)
- e.g. Default pattern would be: jmeterPlugin.perfmon.label.useHostname.pattern=([\w\-]+)\..*
- e.g. Pattern for EC2 us-east/west subdomain matching: jmeterPlugin.perfmon.label.useHostname.pattern=([\w\-]+\.us-(east|west)-[0-9]).*
- forcePerfmonFile - true/false, enabling it makes JMeter to write JTL file with perfmon metrics in the current directory
欢迎关注技术公众号:架构师成长营