You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Karate Gatling与Grafana集成:能否向InfluxDB写入原始测量数据?

解决Karate Gatling写入InfluxDB原始数据的方案

要获取每个请求的原始测量数据而非聚合值,需调整Gatling的InfluxDB配置,开启原始数据写入功能,具体步骤如下:

1. 通过配置文件开启原始数据写入

编辑Gatling的gatling.conf配置文件,找到influxdb节点,添加enableRawData = true:

gatling {
  data {
    writers = ["console", "file", "influxdb"]
  }
  influxdb {
    url = "http://localhost:8086"
    username = "admin"
    password = "admin"
    database = "gatling"
    enableRawData = true  # 关键配置:启用原始请求数据写入
    writeInterval = 10s
  }
}

2. 通过代码配置(可选)

如果需要在测试代码中直接配置,可自定义InfluxDB协议并启用原始数据:

import io.gatling.core.Predef._
import com.intuit.karate.gatling.Predef._
import io.gatling.influxdb.Predef._

class PerformanceSimulation extends Simulation {
  // 配置InfluxDB并开启原始数据
  val influxDbConfig = InfluxDbProtocol(
    url = "http://localhost:8086",
    username = "admin",
    password = "admin",
    database = "gatling",
    enableRawData = true
  )

  val testScenario = scenario("API性能测试")
    .exec(karateFeature("classpath:features/api_test.feature"))

  setUp(testScenario.inject(atOnceUsers(10)))
    .protocols(karateProtocol)
    .reportConfig(reportConfig.influxDb(influxDbConfig))
}

3. 在Grafana中使用原始数据

配置完成后,InfluxDB会自动创建gatling_raw测量表,包含每个请求的requestName、responseTime、status、timestamp等原始字段。在Grafana中:

  • 选择gatling_raw作为数据源表
  • 以timestamp为时间轴,responseTime为数值指标
  • 可按requestName分组,生成每个接口的响应时间趋势图、分布直方图等,实现类似Newman的可视化效果

注意:原始数据会增加InfluxDB的存储负载,高并发长时长测试需提前评估存储资源;确保使用的Karate Gatling版本对应Gatling 3.7+(如Karate 1.3.0及以上),以支持enableRawData配置。

内容的提问来源于stack exchange,提问作者sergej_m

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 02:25:49