Gatling性能测试结果无法推送至EC2的InfluxDB,求排查指导
让我们一步步拆解可能的问题点,从配置到网络再到InfluxDB的设置逐个验证:
1. 先修正Gatling Graphite配置的低级错误
你在gatling.conf里的graphite.host写了带http://前缀的地址,但Graphite(Carbon)协议是基于纯TCP/UDP的,不需要HTTP前缀。直接改成域名/IP即可:
graphite { // ...其他配置 host = "ec2-54-67-97-86.us-west-1.compute.amazonaws.com" // 去掉http://前缀 // ...其他配置 }
Gatling的Graphite Writer是直接和端口2003建立TCP连接,不是发送HTTP请求,这个前缀会导致连接失败。
2. 确认EC2安全组开放了2003端口
你的EC2实例安全组必须允许本地Windows机器的公网IP访问2003端口(TCP协议,和Gatling配置一致):
- 登录AWS控制台,找到目标EC2实例的安全组
- 添加入站规则:自定义TCP,端口2003,源设置为你本地机器的公网IP(可以通过本地浏览器查
whatismyip获取) - 测试阶段可以临时用
0.0.0.0/0开放所有IP,但测试完成后一定要改回指定IP,避免安全风险
另外,如果Ubuntu实例开启了ufw防火墙,也要放行2003端口:
sudo ufw allow 2003/tcp sudo ufw reload
3. 验证InfluxDB的Graphite插件是否正确启用
InfluxDB默认不会自动监听Graphite端口,你需要手动配置并开启:
- 打开InfluxDB配置文件:
sudo nano /etc/influxdb/influxdb.conf
- 找到
[[graphite]]区块,取消注释并修改为以下配置(和Gatling的参数匹配):
[[graphite]] enabled = true bind-address = ":2003" # 监听2003端口,和Gatling的port一致 database = "graphite" # 对应你已创建的graphite数据库 protocol = "tcp" # 和Gatling的protocol一致 separator = "." # 匹配Gatling默认的点分隔符
- 重启InfluxDB服务:
sudo systemctl restart influxdb
- 验证端口监听状态:
netstat -tulpn | grep 2003
如果看到influxd进程监听0.0.0.0:2003,说明配置生效。
4. 测试本地到EC2的网络连通性
在本地Windows机器上,用PowerShell测试能否连接到EC2的2003端口:
Test-NetConnection ec2-54-67-97-86.us-west-1.compute.amazonaws.com -Port 2003
如果返回TcpTestSucceeded : True,说明网络通畅;如果失败,回到安全组/防火墙配置检查。
5. 手动发送测试数据验证InfluxDB接收能力
在本地用PowerShell手动发一条测试数据到InfluxDB的Graphite端口,排除Gatling本身的问题:
$socket = New-Object System.Net.Sockets.TcpClient("ec2-54-67-97-86.us-west-1.compute.amazonaws.com", 2003) $stream = $socket.GetStream() $writer = New-Object System.IO.StreamWriter($stream) $writer.WriteLine("gatling.test.sample 123 $(Get-Date -UFormat %s)") $writer.Flush() $writer.Close() $socket.Close()
然后到InfluxDB里查询:
use graphite select * from "gatling.test.sample"
如果能查到这条数据,说明InfluxDB的Graphite配置没问题,问题出在Gatling的配置或运行逻辑;如果查不到,继续排查InfluxDB的Graphite插件配置。
6. 检查Gatling日志
运行Gatling测试时,查看控制台输出或results目录下的gatling.log,有没有GraphiteDataWriter相关的错误(比如连接超时、拒绝连接),这些日志会直接指出问题根源。
内容的提问来源于stack exchange,提问作者Tk infostrings

