python3.10監控redis例項
使用python3.10監控redis單例項,例項可用,連線數,埠.
import sys try: import redis except Exception as e: print('pip install redis') #安裝redis模組 sys.exit() class Redis: def __init__(self,host,port,password=None): self.host = host self.port = port self.password = password if self.password: self.rds = redis.StrictRedis(host=host,port=port,password=self.password) else: self.rds = redis.StrictRedis(host=host, port=port) try: self.info = self.rds.info() except Exception as e: self.info = None #返回redis版本 def redis_version(self): try: return "Redis版本:%s" % self.info['redis_version'] except Exception as e: return e def redis_ping(self): if self.rds.ping(): return "Redis例項可用" else: return "Redis例項不可用" sys.exit() def redis_connections(self): try: return "Redis連線數:%s" % self.info['connected_clients'] except Exception as e: return e def redis_port(self): try: return "Redis埠:%s" % self.info['tcp_port'] except Exception as e: return e def blocked_clients(self): try: return "Redis正在等待阻塞客房端的數量:%s" % self.info['blocked_clients'] except Exception as e: return e def redis_used_memory(self): memory = self.info['used_memory'] if memory: return "Redis記憶體使用:%.2fM" % (memory/1024) def redis_memory_usage(self): used_memory = self.info['used_memory'] max_memory = self.info['maxmemory'] system_memory = self.info['total_system_memory'] rate = 0 if max_memory: rate = float(used_memory) / float(max_memory) else: if system_memory: rate = float(used_memory) / float(system_memory) return "%.2f" % (rate * 100) def rejected_connections(self): try: return "Redis拒絕連線數:%s" % self.info['rejected_connections'] except Exception as e: return e def ops(self): try: return "Redis OPS值:%s" % self.info['instantaneous_ops_per_sec'] except Exception as e: return e def redis_expired(self): try: return "Redis命中率:%s" % self.info['expired_keys'] except Exception as e: return e def check(self): print(self.redis_version()) print(self.redis_ping()) print(self.redis_connections()) print(self.redis_port()) print(self.blocked_clients()) print(self.redis_used_memory()) print(self.redis_memory_usage()) print(self.rejected_connections()) print(self.ops()) print(self.redis_expired()) if __name__ == '__main__': a=Redis('127.0.0.1','6379','System135') a.check()
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25854343/viewspace-2937940/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- TenSunS監控REDIS:使用一個redis_exporter監控所有的Redis例項RedisExport
- 【Redis】redis阻塞監控項分析Redis
- Python實現遠端埠監控例項Python
- 例項程式碼分享Python實現Linux監控PythonLinux
- 大型監控網路系統規劃ip地址例項
- TenSunS監控Mysql:如何優雅的使用一個mysqld_exporter監控所有的MySQL例項MySqlExport
- 自定義監控項
- Redis 例項分析工具Redis
- redis sentinel哨兵 例項Redis
- 系統效能監控工具ssar例項精選 | 龍蜥SIG
- redis監控工具之redis-liveRedis
- 監控 redis 執行命令Redis
- docker redis 多個例項DockerRedis
- Laravel Redis 廣播 例項LaravelRedis
- Redis單例項安裝Redis單例
- Redis實戰篇(一)搭建Redis例項Redis
- Redis Manager 如何檢視監控Redis
- Prometheus Operator自定義監控項Prometheus
- 實時監控redis -- redislive與redis踩坑配置Redis
- redis效能監控工具redis-stat安裝初探Redis
- 使用夜鶯+categraf監控redis和redis叢集Redis
- Redis安裝+叢集+效能監控Redis
- canal同步mysql,監聽單例項,多例項配置MySql單例
- oracle監聽不到例項服務Oracle
- redis應用場景及例項Redis
- 資料庫DML監控一例資料庫
- 【Redis實戰專題】「效能監控系列」全方位探索Redis的效能監控以及最佳化指南Redis
- Redis 常用監控資訊命令總結Redis
- python獲取zabbix監控項圖形Python
- Linux系統效能監控採集項Linux
- 使用 vue 例項更好的監聽事件Vue事件
- 基於laravel的事件監聽例項Laravel事件
- oracle之 單例項監聽修改埠Oracle單例
- 輕鬆保障萬級例項,vivo服務端監控體系建設實踐服務端
- 【Redis 系列】redis 學習六,redis 事務處理和監控事務Redis
- 02 . Zabbix配置監控項及聚合圖形
- 使用Prometheus監控Linux系統各項指標PrometheusLinux指標
- zabbix5.0-04-給主機新增監控項