一、需求背景
需要对某服务器进行压力测试,并实时生成服务器上的cpu和内存资源占用情况曲线图。
二、工具信息
Apache JMeter是一个用于进行软件压力测试的开源工具,基于Java开发。
本次使用版本信息如下:
windowns客户端:apache-jmeter-3.1 #java 1.8版本
被监控服务器Agent端:ServerAgent V2.2.0 #java 1.8版本
三、配置客户端
建议安装jdk 1.8版本,版本信息:
C:UsersYXTF>java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
1、下载jmeter工具:(下方链接包含所有版本信息)
https://archive.apache.org/dist/jmeter/binaries/
2、配置扩展组件
将JMeterPlugins-Extras.jar和JMeterPlugins-Standard.jar放在libext目录下。
地址:https://jmeter-plugins.org/install/Install/

3、配置测试计划
1)添加监听器

2)配置监控对象

3)设置线程组无限循环


4)设置Sampler


四、配置被监控端
被监控端可以是windowns服务器,也可以是Linux服务器。
服务器操作系统信息如下:
[root@XAYL ServerAgent-2.2.3]# cat /etc/os-release
NAME="Anolis OS"
VERSION="8.8"
ID="anolis"
ID_LIKE="rhel fedora centos"
VERSION_ID="8.8"
PLATFORM_ID="platform:an8"
PRETTY_NAME="Anolis OS 8.8"
ANSI_COLOR="0;31"
HOME_URL="https://openanolis.cn/"
java版本信息如下:
[root@XAYL ServerAgent]
openjdk version "1.8.0_402"
OpenJDK Runtime Environment (build 1.8.0_402-b06)
OpenJDK 64-Bit Server VM (build 25.402-b06, mixed mode)
将ServerAgent工具上传到被监控服务器,本次以Linux服务器为例:
解压后切换到目录:/root/ServerAgent
./startAgent.sh --tool PerfMonAgent --udp-port 8000 --tcp-port 8000 #执行指定端口启动
[root@XAYL ServerAgent]# ./startAgent.sh --tool PerfMonAgent --udp-port 8000 --tcp-port 8000INFO 2024-04-25 14:14:20.377 [kg.apc.p] (): Binding UDP to 8000
INFO 2024-04-25 14:14:21.379 [kg.apc.p] (): Binding TCP to 8000
INFO 2024-04-25 14:14:21.379 [kg.apc.p] (): JP@GC Agent v2.2.0 started
INFO 2024-04-25 14:14:21.533 [kg.apc.p] (): Accepting new TCP connection
ERROR 2024-04-25 14:14:21.534 [kg.apc.p] (): Error executing command
java.lang.UnsupportedOperationException: Unknown command [14]: 'GET / HTTP/1.1'
at kg.apc.perfmon.PerfMonMetricGetter.processCommand(PerfMonMetricGetter.java:87)
at kg.apc.perfmon.PerfMonMetricGetter.processNextCommand(PerfMonMetricGetter.java:101)
at kg.apc.perfmon.PerfMonWorker.read(PerfMonWorker.java:210)
at kg.apc.perfmon.PerfMonWorker.processCommands(PerfMonWorker.java:97)
at kg.apc.perfmon.AgentTool.processParams(AgentTool.java:72)
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:498)
at kg.apc.cmd.UniversalRunner.main(UniversalRunner.java:175)
经测试,被控端采用 ServerAgent-2.2.3版本也可以正常使用。
[root@XAYL ServerAgent-2.2.3]# ./startAgent.sh --tool PerfMonAgent --udp-port 8000 --tcp-port 8000
INFO 2024-04-25 14:21:17.472 [kg.apc.p] (): Binding UDP to 8000
INFO 2024-04-25 14:21:18.473 [kg.apc.p] (): Binding TCP to 8000
INFO 2024-04-25 14:21:18.474 [kg.apc.p] (): JP@GC Agent v2.2.3 started
INFO 2024-04-25 14:21:22.288 [kg.apc.p] (): Accepting new TCP connection
INFO 2024-04-25 14:21:22.290 [kg.apc.p] (): Yep, we received the 'test' command
INFO 2024-04-25 14:21:22.300 [kg.apc.p] (): Starting measures: cpu: memory:
INFO 2024-04-25 14:21:22.432 [kg.apc.p] (): Accepting new TCP connection
ERROR 2024-04-25 14:21:22.434 [kg.apc.p] (): Error executing command
五、常见问题处理
1、被监控端报错: Client disconnected
[root@XAYL ServerAgent]# ./startAgent.sh
INFO 2024-04-25 10:47:49.863 [kg.apc.p] (): Binding UDP to 4444
INFO 2024-04-25 10:47:50.864 [kg.apc.p] (): Binding TCP to 4444
INFO 2024-04-25 10:47:50.868 [kg.apc.p] (): JP@GC Agent v2.2.0 started
INFO 2024-04-25 10:59:06.192 [kg.apc.p] (): Accepting new TCP connection
INFO 2024-04-25 10:59:06.195 [kg.apc.p] (): Yep, we received the 'test' command
INFO 2024-04-25 10:59:06.325 [kg.apc.p] (): Starting measures: cpu: memory: disks i/o:
INFO 2024-04-25 10:59:06.814 [kg.apc.p] (): Client disconnected
INFO 2024-04-25 10:59:12.837 [kg.apc.p] (): Accepting new TCP connection
INFO 2024-04-25 10:59:12.838 [kg.apc.p] (): Yep, we received the 'test' command
INFO 2024-04-25 10:59:12.940 [kg.apc.p] (): Starting measures: cpu: memory: disks i/o:
INFO 2024-04-25 10:59:13.262 [kg.apc.p] (): Client disconnected
解决:
添加线程组>设置无限循环;
线程组中添加http请求,然后点击运行。
