jmeter --- 監控器 Plugins (&jconsole)
Jmeter本身沒有監控服務器資源的功能,需要添加額外插件
一、監控原理圖
二、Jmeter-Plugs下載和安裝
- 官網上下載JMeterPlugins: http://www.jmeter-plugins.org/
- 解壓之後放到安裝目錄下(如我的安裝路徑如下:D:\apache-jmeter-2.13\lib\ext)
- 運行Jmeter打開監視器的菜單,超多個監視器映入眼簾
三、PerfMonAgent的下載和安裝
PerfMonAgent下載網址http://www.jmeter-plugins.org/downloads/all/
安裝文檔見http://www.jmeter-plugins.org/wiki/PerfMonAgent/
PerfMon Server Agent
Installation
You do not need any root/admin privilege. You can just unzip the the ServerAgent-X.X.X.zip somewhere on the server. Then launch the agent using startAgent.shscript on Unix, or startAgent.bat script on Windows.
The agent is written in Java, so you will need JRE 1.4+ to run it. Note you can create yourself the agent package which includes its own JRE so you don‘t have to install java on the server (We tested it on windows platform). To do this, just create a JRE folder in the agent folder and copy one installed JRE inside. Change the java command inside the .bat file to the path to the java executable and it will work.
Once the agent is running, you can use the PerfMon Metrics Collector Listener to connect to the agents. You can add multiple servers to monitor, one graph can display several kinds of metrics (cpu, memory, etc...), auto-zooming rows for best view.
Usage
To start the agent, simply run startAgent bat/sh file. It will open UDP/TCP server ports where JMeter will connect and query the metrics. Some information will be printed to standard output, informing you on problems gathering metrics (logging verbosity regulated with --loglevel parameter
You can specify the listening ports as arguments (0 disables listening), default is 4444:
$ ./startAgent.sh --udp-port 0 --tcp-port 3450 INFO 2011-11-25 19:02:14.315 [kg.apc.p] (): Binding TCP to 3450
You can use the --auto-shutdown option when starting the agent to automatically stop it once the test is finished. It is recommended to use this feature only with TCP connections:
$ undera@undera-HP:/tmp/serverAgent$ ./startAgent.sh --udp-port 0 --auto-shutdown INFO 2011-11-25 19:48:59.321 [kg.apc.p] (): Agent will shutdown when all clients disconnected INFO 2011-11-25 19:48:59.424 [kg.apc.p] (): Binding TCP to 4444
You can use the --sysinfo option to view available system objects:
$ ./startAgent.sh --sysinfo INFO 2011-11-25 19:51:25.517 [kg.apc.p] (): *** Logging available processes *** INFO 2011-11-25 19:51:25.542 [kg.apc.p] (): Process: pid=24244 name=bash args=-bash INFO 2011-11-25 19:51:25.543 [kg.apc.p] (): Process: pid=25086 name=dash args=/bin/sh ./startAgent.sh --sysinfo INFO 2011-11-25 19:51:25.543 [kg.apc.p] (): Process: pid=25088 name=java args=java -jar ./CMDRunner.jar --tool PerfMonAgent --sysinfo INFO 2011-11-25 19:51:25.549 [kg.apc.p] (): *** Logging available filesystems *** INFO 2011-11-25 19:51:25.551 [kg.apc.p] (): Filesystem: fs=/dev type=devtmpfs INFO 2011-11-25 19:51:25.551 [kg.apc.p] (): Filesystem: fs=/ type=ext4 INFO 2011-11-25 19:51:25.551 [kg.apc.p] (): Filesystem: fs=/var/run type=tmpfs INFO 2011-11-25 19:51:25.551 [kg.apc.p] (): Filesystem: fs=/home type=ext4 INFO 2011-11-25 19:51:25.552 [kg.apc.p] (): Filesystem: fs=/var/lock type=tmpfs INFO 2011-11-25 19:51:25.552 [kg.apc.p] (): Filesystem: fs=/proc type=proc INFO 2011-11-25 19:51:25.553 [kg.apc.p] (): *** Logging available network interfaces *** INFO 2011-11-25 19:51:25.554 [kg.apc.p] (): Network interface: iface=lo addr=127.0.0.1 type=Local Loopback INFO 2011-11-25 19:51:25.554 [kg.apc.p] (): Network interface: iface=eth0 addr=192.168.0.1 type=Ethernet INFO 2011-11-25 19:51:25.555 [kg.apc.p] (): *** Done logging sysinfo *** INFO 2011-11-25 19:51:25.555 [kg.apc.p] (): Binding UDP to 4444 INFO 2011-11-25 19:51:26.560 [kg.apc.p] (): Binding TCP to 4444
The --interval <seconds> argument can be used to change metrics collection frequency.
Using Server Agent With Other Applications
Server Agent uses simple plain-text protocol, anyone can use agent‘s capabilities implementing client, based on kg.apc.perfmon.client.Transport interface. If anyone‘s interested, start the topic on the support forums and I‘ll describe how to connect third-party client app to agent.
ServerAgent has simple text protocol and can work on UDP and TCP transports. Most of cases will use TCP.
To have your first talk with the agent, start it locally. Then use telnet utility to connect to it:
user@ubuntu:~$ telnet localhost 4444 Trying 127.0.0.1... Connected to localhost. Escape character is ‘^]‘.
If connection has succeeded, you should see "Accepting new TCP connection" message in ServerAgent console log. Type "test" and press Enter in telnet chat, server should answer with short "Yep":
test Yep
Type "exit":
exit Connection closed by foreign host.
That‘s it. You sending a command line, server answering. Command line consists of command, sometimes with parameters. Parameters are separated from command with a colon sign.
Possible commands are:
- exit - terminates current client session and closes connection to agent, no parameters
- test - test if server is alive, no parameters
- shutdown - terminate all client connections and shutdown agent process, no parameters
- interval - change metrics reporting interval used in ‘metrics‘ command, single parameter is integer value in seconds. Interval can be changed in the middle of metrics reporting. Example: interval:5
- metrics - starts automatic metrics collection, parameters are metrics list to collect, described below. Example: metrics:cpu
- metrics-single - calls single metric collection iteration. Example: metrics-single:memory
Specifying Metrics
Metrics list consists of metric specifications, separated by TAB character. Metric collection output consists of float values, TAB separated. Example:
metrics-single:cpumemory 22.0573689416419457.52359562205553
Each metric specification consists of several fields, colon-separated. Short example:
metrics-single:cpu:idle memory:free 80.02238388360381 57.52359562205553
Fields number is metric-type specific. Possible metric types are:
- cpu
- memory
- swap
- disks
- network
- tcp
- tail
- exec
- jmx
Fields corresponding to each metric type are described at metrics page. Last example (Yep, ServerAgent can be shell exec vulnerability. If you have issue with this, ask me and I‘ll introduce ‘secure‘ mode, disabling insecure metric types):
metrics-single:exec:/bin/sh:-c:free | grep Mem | awk ‘{print $7}‘ 1152488
四、Jmeter壓力測試和監控示例
將JMeterPlugins.jar包復制到Jmeter的lib目錄下面的ext目錄下面,重新啟動Jmeter,我們點擊添加就可以看到出現了很多的jp@gc-開頭的文件.
這裏監控內存我們使用的是:jp@gc - PerfMon Metrics Collectot
在使用之前,我們需要運行/serverAgent/startAgent.bat這個文件,我們需要將serverAgent目錄及下面的文件復制到我們測試的服務器上,然後點擊打開(我這裏是本機,直接在本機上面打開這個應用系統即可),它的默認端口為4444。
一切準備好後,點擊啟動,即可得到如下圖:
並配置這個監聽器
你就可以得到系統運行時,你所需要的常用的性能值了。
監控內存及CPU等(jconsole)
本文轉自: 清明-心若淡定 https://www.cnblogs.com/saryli/p/5434927.html
jmeter --- 監控器 Plugins (&jconsole)