redis计算qps(total_commands_processed)

 

 

#!/bin/bash
now_date=`date "+%Y%m%d%H%M%S"`
total_commands_processed=`/usr/local/redis/bin/redis-cli -h 192.168.1.50 -a test123 -p 6379 info 2>/dev/null|grep total_commands_processed|awk -F':' '{print $2}'`

echo ${now_date}'|'${total_commands_processed}>>/tmp/total_commands_processed.log

 

 

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import time
import redis
def get_redis_qps():
    r = redis.Redis(host='192.168.1.50', port=6379, db=0, password='test123')
    prev_ops = 0

    while True:
        info = r.info("stats")
        ops = info['total_commands_processed']
        qps = ops - prev_ops
        prev_ops = ops
        print("QPS: "+str(qps))
        time.sleep(1)


get_redis_qps()

 

posted @ 2024-04-19 11:24  slnngk  阅读(86)  评论(0编辑  收藏  举报