我有一个 Groovy 脚本:
def results = []
def cluster = ['cluster1', 'cluster1', 'cluster1', 'cluster1', 'cluster1', 'cluster1'];
def ports = ['4344', '4344', '4344', '4344', '4344', '4344'];
def hostname = [ 'cluster1.com','cluster1.com','cluster1.com','cluster1.com','cluster1.com','cluster1.com' ];
def heapu = ['533.6', '526.72' , '518.82' , '515.73', '525.69', '517.71'] ;
def heapm = ['1212.15', '1212.15', '1212.15', '1212.15', '1212.15', '1212.15'];
def times = ['2017-10-08T07:26:21.050Z', '2017-10-08T07:26:11.042Z', '2017-10-08T07:25:51.047Z', '2017-10-08T07:25:31.055Z', '2017-10-08T07:26:01.047Z', '2017-10-08T07:25:41.041Z'] ;
for (int i = 0; i < cluster.size(); ++i){
def c = cluster[i]
def p = ports[i]
def h = hostname[i]
def hu = heapu[i]
def hm = heapm[i]
def t = times[i]
results.add(['cluster': c,
'port': p,
'hostname': h,
'heap_used': hu,
'heap_max': hm,
'times': t])
results = results.unique()
}
// return ['results': results, 'singlex': singlex]
for (i = 0; i < results.size(); i++){
println(results[i])
}
此脚本的输出如下所示:
[cluster:cluster1, port:4344, hostname:cluster1.com, heap_used:533.6, heap_max:1212.15, times:2017-10-08T07:26:21.050Z]
[cluster:cluster1, port:4344, hostname:cluster1.com, heap_used:526.72, heap_max:1212.15, times:2017-10-08T07:26:11.042Z]
[cluster:cluster1, port:4344, hostname:cluster1.com, heap_used:518.82, heap_max:1212.15, times:2017-10-08T07:25:51.047Z]
[cluster:cluster1, port:4344, hostname:cluster1.com, heap_used:515.73, heap_max:1212.15, times:2017-10-08T07:25:31.055Z]
[cluster:cluster1, port:4344, hostname:cluster1.com, heap_used:525.69, heap_max:1212.15, times:2017-10-08T07:26:01.047Z]
[cluster:cluster1, port:4344, hostname:cluster1.com, heap_used:517.71, heap_max:1212.15, times:2017-10-08T07:25:41.041Z]
从输出中可以看出 - >我基本上有6条与时间戳不同的相同行。HeapSize 和 Max HeapSize 是不同的,但这并不重要。
由于集群对于所有六个条目 /cluster1/ 都是相同的,我认为它是一个输出。理想情况下,我想应用某种unique()函数,它可以为我提供一行作为输出
如下所示:
[cluster:cluster1, port:4344, hostname:cluster1.com, heap_used:523.0450, heap_max:1212.15, times:2017-10-08T07:25:41.041Z]
其中 heap_used 是 6 个值的平均值以及 heap_max。我知道在 python pandas 中我可以用一个命令来完成它。但是我不知道 groovy,我一直在互联网上搜索。
编辑:不幸的是,Groovy 解决方案不会将 1:1 转移到 Painless。