python实时监控服务器性能
监控服务器各项性能指标,以下为监控测试流程 1、mysql数据库插入数据 1.1 大家要首先在服务器上安装一个mysql,此项略。。。 1.2 登录mysql新建一个cpu库和cpu表 1.3 连接数据库,代码如下 1 import pymysql 2 class Conn: 3 def __init__ (self): 4 self.connect = pymysql.connect( 5 host = " 192.168.1.124 " , 6 port = 3306 , 7 user = " root " , 8 passwd = " testmysql " , 9 db = " cpu " , 10 charset = " utf8 " 11 ) 12 self.cur = self.connect.cursor() 13 14 def insert(self,data): 15 sql = " insert into cpu(cpu_idle,memory_used,memory_free,disk_C_free) values ('%s','%s','%s','%s') " 16 self.cur.execute(sql% data) 17 # self.connect.close() 18 self.connect.commit() 19 20 # if __name