# -*- coding: utf-8 -*-
__author__ = 'Administrator'
__time__ = '2018-04-28 上午 10:34'
import redis
import sys
import time
HOST='172.18.101.29'
PORT='6579'
times=5000
result_file='D://re.txt'
#HOST=sys.argv[1]
#PORT=int(sys.argv[2])
#times=int(sys.argv[3])
#result_file=(sys.argv[4])
sleep=1
title='used_memory_rss,'+'used_memory_peak,'+'used_memory,'+'mem_fragmentation_ratio,'+'instantaneous_ops_per_sec,'+'rejected_connections,'+'connected_clients,'+'blocked_clients'
def connect_redis(host,port):
r=redis.Redis(host,port,socket_timeout=5,socket_connect_timeout=5)
return r
def main():
i=1
r=connect_redis(HOST,PORT)
refile_object=open(result_file,'a')
try:
r.ping()
except:
print(HOST,PORT,'down')
sys.exit(1)
print (title)
while i <= times:
redis_info=r.info()
used_memory_rss=int(redis_info['used_memory_rss'])
used_memory_peak_human=redis_info['used_memory_peak_human']
used_men_human=redis_info['used_memory_human']
mem_fragmentation_ratio=redis_info['mem_fragmentation_ratio']
instantaneous_ops_per_sec=redis_info['instantaneous_ops_per_sec']
rejected_connections=redis_info['rejected_connections']
connected_clients=redis_info['connected_clients']
blocked_clients=redis_info['blocked_clients']
#print redis_info
result=str(used_memory_rss)+', '+str(used_memory_peak_human)+', '+str(used_men_human)+', '+str(mem_fragmentation_ratio)+', '+str(instantaneous_ops_per_sec)+', '+str(rejected_connections)+', '+str(connected_clients)+', '+str(blocked_clients)
i=i+1
print (result)
refile_object.write(result)
refile_object.write('\n')
time.sleep(sleep)
if (i%10==0):
print(title)
refile_object.close()
if __name__ == '__main__':
main()