python 字典如何删除
claclassssh_linux():#linux信息获取基本函数类def__init__(self,ip,port,account,password):self.ip...
cla
class ssh_linux(): #linux信息获取基本函数类
def __init__(self,ip,port,account,password):
self.ip=ip
self.port=int(port)
self.account=account
self.password=password
self.os='linux'
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.ip,self.port,self.account,self.password,timeout=5)
self.p=ssh
except:
print 'faild'
def disk_usage(self):
ssh=self.p
cmd="df -h|tr -s ' '|cut -d ' ' -f5|grep -o '[0-9]*'|sort -rn|head -n1"
stdin, stdout, stderr = ssh.exec_command(cmd)
out= stdout.readlines()
err= stderr.readlines()
if len(err)==0:
for i in out:
DMSDircEqui.DMSDircEquiClass().DMSDataDircUpDate(self.ip,'disk',i[:-1])
print '%s %s disk_usage: %s' %(self.os,self.ip,i[:-1])
else:
for j in err:
print j[:-1]
def memory_usage(self):
ssh=self.p
cmd='free -m|head -n2|tail -n1|tr -s " "|cut -d " " -f4'
stdin, stdout, stderr = ssh.exec_command(cmd)
out= stdout.readlines()
err= stderr.readlines()
if len(err)==0:
for i in out:
DMSDircEqui.DMSDircEquiClass().DMSDataDircUpDate(self.ip,'mem',i[:-1])
print '%s %s memory_usage: %s' %(self.os,self.ip,i[:-1])
else:
for j in err:
print j[:-1]
ssh.close() 展开
class ssh_linux(): #linux信息获取基本函数类
def __init__(self,ip,port,account,password):
self.ip=ip
self.port=int(port)
self.account=account
self.password=password
self.os='linux'
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.ip,self.port,self.account,self.password,timeout=5)
self.p=ssh
except:
print 'faild'
def disk_usage(self):
ssh=self.p
cmd="df -h|tr -s ' '|cut -d ' ' -f5|grep -o '[0-9]*'|sort -rn|head -n1"
stdin, stdout, stderr = ssh.exec_command(cmd)
out= stdout.readlines()
err= stderr.readlines()
if len(err)==0:
for i in out:
DMSDircEqui.DMSDircEquiClass().DMSDataDircUpDate(self.ip,'disk',i[:-1])
print '%s %s disk_usage: %s' %(self.os,self.ip,i[:-1])
else:
for j in err:
print j[:-1]
def memory_usage(self):
ssh=self.p
cmd='free -m|head -n2|tail -n1|tr -s " "|cut -d " " -f4'
stdin, stdout, stderr = ssh.exec_command(cmd)
out= stdout.readlines()
err= stderr.readlines()
if len(err)==0:
for i in out:
DMSDircEqui.DMSDircEquiClass().DMSDataDircUpDate(self.ip,'mem',i[:-1])
print '%s %s memory_usage: %s' %(self.os,self.ip,i[:-1])
else:
for j in err:
print j[:-1]
ssh.close() 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询