JMeter - 从 2 个 csv 文件中捕获列并将其写入第三个文件

JMeter - Capture Columns from 2 csv files and write it to a 3rd file

我有 2 个 csv 文件

文件 1:

         Name                 Start_Time
eml-alertservice               19:42:12
eml-redis                      19:42:12
eml-fluentd                    19:42:12
eml-kube-prometheus-stack      19:42:13
mwl-query-service              19:42:13
eml-grafana                    19:42:13
entity-management-service      19:42:14
snomed-service                 19:44:04
nuevo-dcm-services-wado        19:44:05
eis-common-postgres            19:45:43

文件 2:

   OS         K3s        Duration
18:10:06    18:10:45     39 secs
18:53:38    18:54:17     39 secs
20:03:19    20:03:58     39 secs
16:27:45    16:28:51     66 secs
19:38:12    19:39:12     60 secs

从文件 1 中,除第一行外,捕获了全部数据。从文件 2 中,仅提取最后一行的第二列。将这些数据写入文件 3。在文件 3 中,从第 2 列中减去第 3 列(这些是时间值)并在第 4 列中显示结果(以秒为单位的时间)。总的来说,文件 3 应该看起来像

文件 3:

         Name                 Start_Time            K3s         Duration
eml-alertservice               19:42:12           19:39:12      60 secs
eml-redis                      19:42:12           19:39:12      60 secs
eml-fluentd                    19:42:12           19:39:12      60 secs
eml-kube-prometheus-stack      19:42:13           19:39:12      61 secs
mwl-query-service              19:42:13           19:39:12      61 secs
eml-grafana                    19:42:13           19:39:12      61 secs
entity-management-service      19:42:14           19:39:12      62 secs
snomed-service                 19:44:04           19:39:12      292 secs
nuevo-dcm-services-wado        19:44:05           19:39:12      293 secs
eis-common-postgres            19:45:43           19:39:12      391 secs

感谢您的支持。

此致, 阿吉特

您可以使用任何合适的 JSR223 Test Element with Groovy language

示例代码:

def time = (new File('file2.csv').readLines().last() =~ /(\d{2}:\d{2}:\d{2})/)[1][1]

def file1 = new File('file1.csv').readLines()

def names = file1.drop(1).collect { line -> (line =~ /([a-z\-\_]+)/)[0][1] }
def times = file1.drop(1).collect { line -> (line =~ /(\d{2}:\d{2}:\d{2})/)[0][1] }

def file3 = new File('file3.csv')

file3 << 'Name' << '\t' << 'Start_Time' << '\t' << 'K3s' << '\t' << 'Duration' << System.getProperty('line.separator')

names.eachWithIndex { name, index ->

    def endTime = Date.parse('hh:mm:ss', times.get(index) as String)
    def startTime = Date.parse('hh:mm:ss', time as String)
    def delta = (endTime.getTime() - startTime.getTime()) / 1000 + ' secs'
    file3 << name << '\t' << times.get(index) << '\t' << time << '\t' << delta << System.getProperty('line.separator')
}