我正在运行一个 python 脚本来获取我们 PCF 环境的指标。它运行命令“cf 喷嘴”并保存输出。目前的输出是:
来源:“rep” eventType:ContainerMetric 时间戳:1549634851407422442 部署:“cf” 作业:“diego_cell” 索引:“133834a1-b38a-41fc-9c86-3fc0433ca25c” ip:“10.54.168.53” 标签:containerMetric:a59a-7d65bc026e54” instanceIndex :3 cpuPercentage:0.0002414595272222457 memoryBytes:4562944 diskBytes:10043392 memoryBytesQuota:13 4217728 diskBytesQuota:1073741824 >
来源:“rep”事件类型:ContainerMetric 时间戳:1549634851407427339 部署:“cf”作业:“diego_cell”索引:“133834a1-b38a-41fc-9c86-3fc0433ca25c” ip:“10.54.168.53”索引标签:containerMetric:973d-2b929bd948e1 实例“ :1 cpuPercentage:0.08058658221147202 memoryBytes:277782528 diskBytes:210866176 memoryBytesQuota:5 36870912 diskBytesQuota:268435456 >
来源:“rep” eventType:ContainerMetric 时间戳:1549634851407432095 部署:“cf” 作业:“diego_cell” 索引:“133834a1-b38a-41fc-9c86-3fc0433ca25c” ip:“10.54.168.53” 标签:containerMetric:80f9-3e91490ace2b” instanceIndex :2 cpuPercentage:0.697502774289568 memoryBytes:366649344 diskBytes:189415424 memoryBytesQuota:107 3741824 diskBytesQuota:268435456 >
我希望能够通过将每个度量块放入它自己的字典/列表中来更好地组织这个输出。这样我就可以获取某些指标进行监控。
我目前的代码是:
import subprocess
nozzle_cmd = ['timeout', '10', 'cf', 'nozzle', '--filter', 'ContainerMetric']
process_nozzle = subprocess.run(nozzle_cmd, stdout=subprocess.PIPE)
nozzle_bytes = process_nozzle.stdout
nozzle_str = nozzle_bytes.decode("utf-8")
print(nozzle_str)