Python脚本

import subprocess
import json

curl_command = ['curl','-s','http://localhost:8088/dc-summer/monitor/database/stat.session?timely=true']

output = subprocess.check_output(curl_command).decode('utf-8')

try:
data = json.loads(output)
formatted_data = json.dumps(data,indent=4)
print(formatted_data)

print('--------------------------------------')

data2 = data['result']
formatted_data2 = json.dumps(data2,indent=4)
print(formatted_data2)

n1=0
for d in data2:
    if d['session_id']:
	    print(d['session_id'])
		n1=n1+1
		
n = len(data2)
print('-------------------------[%s][%s]-------------------' % (n,n1))

except json.JSONDecodeError:
print("Failed to parse JSON response.")
print("Raw output:")
print(output)

posted @ 2024-09-25 16:16  utf-8-python  阅读(18)  评论(0)    收藏  举报