使用python,本地监控远端linux服务器

import paramiko
import re

ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect(“192.168.126.130”,22,“root”,“kongziyue”)

command={‘neichun.log’:“cat /proc/meminfo”,
‘xiancheng.log’:‘vmstat 1 2 | tail -n 1’,
‘cpu.log’:‘cat /proc/cpuinfo’,
‘fuzai.log’:‘cat /proc/loadavg’,
‘wangluo.log’:‘cat /proc/net/dev’,
‘cipan.log’:‘df -h’,
‘duankou.log’:‘netstat -tplnu’
}

def quwenjian(command,filename):
stdin, stdout, stderr = ssh.exec_command(command)

wen=stdout.read()

with open(filename,'wb') as f:
    f.write(wen)

for i in list(command.items()):
quwenjian(i[1],i[0])

你可能感兴趣的:(python)