從json字串獲取key的value
阿新 • • 發佈:2019-01-31
ubuntu1604:~$ cat locuststats.py
#!/usr/bin/env python
import urllib2
resp = urllib2.urlopen('http://10.129.47.154:8089/stats/requests')
d = resp.read()
import json
locus = json.loads(d)
del locus['errors']
#print json.dumps(locus,indent=4)
locus['stats'][1]["avg_response_time"]
print "user_count: %d" % locus['user_count']
print "slaves: %d" % locus['slave_count']
print "rt: %d" % locus['stats'][1]['avg_response_time']
print "rps: %0.2f" % locus['total_rps']
print "erros: %0.4f" % locus["fail_ratio"]
#!/usr/bin/env python
import urllib2
resp = urllib2.urlopen('http://10.129.47.154:8089/stats/requests')
d = resp.read()
import json
locus = json.loads(d)
del locus['errors']
#print json.dumps(locus,indent=4)
locus['stats'][1]["avg_response_time"]
print "user_count: %d" % locus['user_count']
print "slaves: %d" % locus['slave_count']
print "rt: %d" % locus['stats'][1]['avg_response_time']
print "rps: %0.2f" % locus['total_rps']
print "erros: %0.4f" % locus["fail_ratio"]
輸出結果如下:
ubuntu1604:~$ python locuststats.py
user_count: 100
slaves: 100
rt: 44
rps: 2187.50
erros: 0.0001