重磅!!!监控分布式NVIDIA-GPU状态

简介:Uptime Kuma是一个易于使用的自托管监控工具,它的界面干净简洁,部署和使用都非常方便,用来监控GPU是否在占用,非常美观。

历史攻略:

docker应用:搭建uptime-kuma监控站点

win下持续观察nvidia-smi

Python:查看windows下GPU的使用情况、利用率

使用Supervisor部署Sanic应用

操作步骤:

1、容器搭建Uptime Kuma。详见 - 历史攻略链接1

2、安装nvidia-smi。详见 - 历史攻略链接2

3、搭建sanic服务端:主要是写访问nvidia-smi的一个接口。

4、配置Uptime Kuma。

安装依赖:

复制代码
pip install paramiko
pip install sanic

案例源码:

复制代码
# -*- coding: utf-8 -*-
# time: 2024/4/23 20:15
# file: server.py
# 公众号: 玩转测试开发

import re
import paramiko
import datetime
from sanic import Sanic
from sanic.response import json


class ParamikoTool(object):
    def __init__(self, user, password, host, port=22, timeout=60):
        self.user = user
        self.password = password
        self.host = host
        self.port = port
        self.timeout = timeout

    def send_command(self, command):
        print(f"send command:{command}")
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(self.host, self.port, self.user, self.password)
        stdin, stdout, stderr = ssh.exec_command(command)
        out = stdout.readlines()
        err = stderr.readlines()
        ssh.close()
        out_result = "".join(out)
        err_result = "".join(err)

        result = out_result + err_result
        print(result)

        return result


app = Sanic("MyHelloWorldApp")


@app.post("/")
async def hello_world(request):
    data = request.json
    print(f"data:{data}")

    get_command = dict()

    get_command["user"] = data["user"]
    get_command["password"] = data["password"]
    get_command["host"] = data["host"]

    if data.get("port") is None:
        get_command["port"] = 22

    else:
        get_command["port"] = data["port"]

    if data.get("timeout") is None:
        get_command["timeout"] = 60

    else:
        get_command["timeout"] = data["timeout"]

    user = get_command["user"]
    password = get_command["password"]
    host = get_command["host"]

    pt = ParamikoTool(user=user, password=password, host=host)
    smi_data = pt.send_command("nvidia-smi")
    utilization_rate = float(re.findall("MiB \|(.*?)%", smi_data)[0])
    card_used = True if utilization_rate > 0 else False

    if card_used:
        # 如果已经使用则,返回异常。否则正常返回
        return BaseException
    else:
        server_data = {
            "card_used": card_used,
            "date": str(datetime.datetime.now())[:19],
        }
        del pt

        return json(server_data)


if __name__ == '__main__':
    app.run(host="0.0.0.0", port=8009, auto_reload=True)

运行接口服务端:python server.py 或者参考详见 - 历史攻略链接4

Uptime Kuma配置监控项:多个机器的卡就发起多个监控项,填入对应账号密码即可。

主界面效果:

服务器接口响应情况:

小结:同理可以监控各类服务,进程,端口,占用。本质是:通过启动一个接口服务,将Uptime Kuma监控平台的接口请求,先指向这个服务接口,接口通过paramiko的方式,在对应的服务器执行对应的命令,解析这个命令,然后返回给Uptime Kuma平台。

相关推荐
cnbestec8 分钟前
Xela矩阵三轴触觉传感器的工作原理解析与应用场景
人工智能·线性代数·触觉传感器
不爱写代码的玉子16 分钟前
HALCON透视矩阵
人工智能·深度学习·线性代数·算法·计算机视觉·矩阵·c#
sbc-study29 分钟前
PCDF (Progressive Continuous Discrimination Filter)模块构建
人工智能·深度学习·计算机视觉
EasonZzzzzzz37 分钟前
计算机视觉——相机标定
人工智能·数码相机·计算机视觉
猿小猴子1 小时前
主流 AI IDE 之一的 Cursor 介绍
ide·人工智能·cursor
要努力啊啊啊1 小时前
Reranker + BM25 + FAISS 构建高效的多阶段知识库检索系统一
人工智能·语言模型·自然语言处理·faiss
EasyDSS1 小时前
国标GB28181设备管理软件EasyGBS远程视频监控方案助力高效安全运营
网络·人工智能
蓝婷儿1 小时前
6个月Python学习计划 Day 16 - 面向对象编程(OOP)基础
开发语言·python·学习
春末的南方城市1 小时前
港科大&快手提出统一上下文视频编辑 UNIC,各种视频编辑任务一网打尽,还可进行多项任务组合!
人工智能·计算机视觉·stable diffusion·aigc·transformer
叶子2024221 小时前
学习使用YOLO的predict函数使用
人工智能·学习·yolo