服务器巡检脚本-python3

服务器巡检脚本-python3

项目地址:https://gitee.com/oceanlee007/check

自动获取主机名,CPU核数,总内存。

检测剩余内存,使用内存,15分钟负载。

依据配置的磁盘挂载目录,获取磁盘容量,磁盘使用大小,磁盘可用大小,磁盘使用率

项目部分代码:

def login_by_passwd(server_host, server_port, username, password):
    ssh_client = paramiko.SSHClient()
    # 设置默认接收主机信任的策略,但是可能报告“不信任主机的”异常
    ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    with open('check.log', 'a', encoding="utf-8") as file_log:
        file_log.write(str(datetime.datetime.today()) + ': Connecting host: ' + server_host + '......' + '\n', )
    print(str(datetime.datetime.today()) + ': Connecting host: ' + server_host + '......')
    try:
        ssh_client.connect(hostname=server_host, port=server_port, username=username, password=password)
        print(str(datetime.datetime.today()) + ': Connect host: ' + server_host + ' success')
        with open('check.log', 'a', encoding="utf-8") as file_log:
            file_log.write(str(datetime.datetime.today()) + ': Connect host: ' + server_host + ' success' + '\n')
        paramiko.util.log_to_file('syslogin.log')
    except Exception as msq:
        print(str(datetime.datetime.today()) + f"{msq}")
        with open('check.log', 'a', encoding="utf-8") as file_log:
            file_log.write(str(datetime.datetime.today()) + ': ERROR: ' + server_host + f"{msq}" + '\n')

标题:服务器巡检脚本-python3
作者:LeeOcean
地址:https://www.leiocean.com/articles/2023/11/28/1701157334871.html

    评论
    0 评论
avatar

取消