I am running a python script that grabs metrics for our PCF environment. It runs the command "cf nozzle" and saves the output. currently the output is:
origin:"rep" eventType:ContainerMetric timestamp:1549634851407422442 deployment:"cf" job:"diego_cell" index:"133834a1-b38a-41fc-9c86-3fc0433ca25c" ip:"10.54.168.53" tags: containerMetric: a59a-7d65bc026e54" instanceIndex:3 cpuPercentage:0.0002414595272222457 memoryBytes:4562944 diskBytes:10043392 memoryBytesQuota:13 4217728 diskBytesQuota:1073741824 >
origin:"rep" eventType:ContainerMetric timestamp:1549634851407427339 deployment:"cf" job:"diego_cell" index:"133834a1-b38a-41fc-9c86-3fc0433ca25c" ip:"10.54.168.53" tags: containerMetric: 973d-2b929bd948e1" instanceIndex:1 cpuPercentage:0.08058658221147202 memoryBytes:277782528 diskBytes:210866176 memoryBytesQuota:5 36870912 diskBytesQuota:268435456 >
origin:"rep" eventType:ContainerMetric timestamp:1549634851407432095 deployment:"cf" job:"diego_cell" index:"133834a1-b38a-41fc-9c86-3fc0433ca25c" ip:"10.54.168.53" tags: containerMetric: 80f9-3e91490ace2b" instanceIndex:2 cpuPercentage:0.697502774289568 memoryBytes:366649344 diskBytes:189415424 memoryBytesQuota:107 3741824 diskBytesQuota:268435456 >
I want to be able to organize this output better by making each metric block into it's own dictionary/list. That way I'll be able to grab certain metrics for monitoring.
My current code is:
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)