当前位置: 首页 > news >正文

微信公众平台和微网站的区别在线seo推广软件

微信公众平台和微网站的区别,在线seo推广软件,做网站用什么软件知乎,群晖6.1安装wordpress引言 https://github.com/cnstark/gputasker 随着 AI 模型的广泛应用,GPU 成为团队中最重要的资源之一。然而,如何实时监控 GPU 的使用情况并及时通知团队是一个值得关注的问题。为了更好地管理显卡资源,本文基于 GPUTasker,实现了…

引言

https://github.com/cnstark/gputasker

随着 AI 模型的广泛应用,GPU 成为团队中最重要的资源之一。然而,如何实时监控 GPU 的使用情况并及时通知团队是一个值得关注的问题。为了更好地管理显卡资源,本文基于 GPUTasker,实现了一个定期向钉钉群推送显卡使用情况的机器人。

我们通过钉钉自定义机器人 API 和 GPU 监控工具,结合 Python 脚本实现了以下功能:

  1. 根据设定的 工作时间节假日规则,控制消息推送;
  2. 按指定时间间隔发送 GPU 的利用率、显存使用量以及正在使用显卡的用户信息;
  3. 自动跳过节假日和非工作时间,减少不必要的推送。

实现步骤

1. 获取钉钉机器人 Token 和 Secret

在钉钉群中创建一个自定义机器人,获取 Token 和 Secret。具体步骤如下:

  1. 登录钉钉 Web 端:
    打开 钉钉开放平台 或在钉钉桌面端打开需要管理的工作群。
  2. 添加机器人:
    • 点击群设置 -> 智能群助手 -> 添加机器人;
    • 选择 自定义机器人,并设置一个名称(如:GPU 使用监控机器人);
    • 配置机器人安全设置,选择 自定义关键词签名校验
  3. 记录 Token 和 Secret:
    • 添加完成后,系统会生成一个 Token;
    • 如果选择了签名校验,还会生成一个 Secret;
    • 这两个字段将在脚本中用于身份验证。

2. Messenger 类的实现

Messenger 类是整个系统的核心,负责构建和发送消息到钉钉群。以下是该类的详细实现及功能介绍。

2.1 文件路径

在项目中,新建以下文件路径:

dingding/dingding.py

将 Messenger 类的代码放入 dingding.py 文件中,供其他模块调用。

2.2 核心功能

以下是 Messenger 类的关键功能:

  1. 节假日跳过
    使用 chinese_calendar 库判断当前日期是否为中国法定节假日。如果是节假日,机器人将自动跳过消息推送。
  2. 工作时间设置
    支持自定义工作时间段(如上午 8:20 到 11:50,下午 13:10 到 17:30),并在非工作时间内停止推送消息。
  3. 固定时间间隔推送
    支持设置推送间隔时间(如每 30 分钟推送一次),避免频繁发送消息。
  4. 显卡使用信息格式化
    将显卡使用情况转化为 Markdown 格式,方便在钉钉群中以表格形式展示。

以下是 Messenger 类的完整代码:

import os
import time
import hmac
import json
import base64
import hashlib
import requests
import chinese_calendar as calendar
from urllib.parse import quote_plus
from datetime import datetimeclass Messenger:def __init__(self, token=os.getenv("DD_ACCESS_TOKEN"), secret=os.getenv("DD_SECRET")):"""初始化方法@param token: str, 钉钉机器人访问令牌@param secret: str, 钉钉机器人密钥"""self.token = tokenself.secret = secretself.URL = "https://oapi.dingtalk.com/robot/send"self.headers = {'Content-Type': 'application/json'}self.params = {'access_token': self.token}self.update_timestamp_and_sign()# GPU 参数self.total_memory_GB = 24self.utilization_thred = 0.6self.memory_used_thred = 0.5# 时间控制参数self.time_range = [('08:20', '11:50'), ('13:10', '17:30')]self.last_true_time = {}self.time_interval = 30  # 间隔30分钟推送一次def send_md(self, message_json, server_ip):"""发送 Markdown 格式的消息到钉钉。"""self.update_timestamp_and_sign()if self.should_call_function_during_chinese_workdays(server_ip):if not message_json:text = f"**服务器IP**: `{server_ip}`\n**状态**: **连接失败**"self.send_markdown_to_dingtalk("服务器连接失败", text)else:content, is_free = self.format_gpu_usage_to_markdown(message_json, server_ip)if is_free:self.send_markdown_to_dingtalk("显卡使用情况", content)def update_timestamp_and_sign(self):"""更新时间戳和签名。"""self.timestamp = str(round(time.time() * 1000))secret_enc = self.secret.encode('utf-8')string_to_sign = '{}\n{}'.format(self.timestamp, self.secret)string_to_sign_enc = string_to_sign.encode('utf-8')hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()self.sign = quote_plus(base64.b64encode(hmac_code))self.params['timestamp'] = self.timestampself.params['sign'] = self.signdef send_markdown_to_dingtalk(self, title, text):"""构建并通过钉钉发送 Markdown 消息。"""data = {"msgtype": "markdown","markdown": {"title": title,"text": text}}try:requests.post(url=self.URL, data=json.dumps(data), params=self.params, headers=self.headers)except Exception as e:print(f"发生错误: {e}")def format_gpu_usage_to_markdown(self, message_json, server_ip):"""格式化 GPU 使用信息为 Markdown 文本。"""rows = []rows.append(f"**{server_ip}**")rows.append("")rows.append("| ID | GPU利用率 | 显存使用量 | 用户 |")rows.append("|:-------:|:------------:|:----------------:|:------:|")is_any_free = Falsefor gpu in message_json:index = gpu['index']utilization = gpu['utilization.gpu']memory_used_MB = gpu['memory.used']memory_used_GB = memory_used_MB / 1024memory_percentage = (memory_used_MB / (self.total_memory_GB * 1024)) * 100users = [process['username'] for process in gpu['processes']]users_str = ', '.join(set(users)) if users else '-'is_free = utilization < 100 * self.utilization_thred and memory_used_MB < (self.total_memory_GB * 1024 * self.memory_used_thred)if is_free:is_any_free = Truerow = f"| <font color='green'>**{index}**</font> | <font color='green'>**{utilization}%**</font> | <font color='green'>**{memory_used_GB:.1f}GB ({memory_percentage:.0f}%)**</font> | <font color='green'>**{users_str}**</font> |"else:row = f"| {index} | {utilization}% | {memory_used_GB:.1f}GB ({memory_percentage:.0f}%) | {users_str} |"rows.append(row)return '\n'.join(rows), is_any_freedef should_call_function_during_chinese_workdays(self, server_ip):"""检查是否为中国工作日以及指定时间段。"""now = datetime.now()current_time = now.time()if not calendar.is_workday(now):return Falsein_any_time_range = Falsefor time_range in self.time_range:start_time = datetime.strptime(time_range[0], '%H:%M').time()end_time = datetime.strptime(time_range[1], '%H:%M').time()if start_time <= end_time:in_time_range = start_time <= current_time <= end_timeelse:in_time_range = start_time <= current_time or current_time <= end_timeif in_time_range:in_any_time_range = Truebreakif in_any_time_range:last_time = self.last_true_time.get(server_ip)if last_time is None or (now - last_time).total_seconds() >= self.time_interval * 60:self.last_true_time[server_ip] = nowreturn Truereturn False# 实例化类
messager = Messenger(token="xxxxxx",secret="xxxxxx")

2.3 调用 Messenger 类

将以下代码加入 gputasker/gpu_info/utils.py 中,通过 try 捕获异常并调用钉钉推送功能:

from dingding.dingding import messagerclass GPUInfoUpdater:def update_gpu_info(self):server_list = GPUServer.objects.all()for server in server_list:try:gpu_info_json = get_gpu_status(server.ip, self.user, server.port, self.private_key_path)except:gpu_info_json = Nonefinally:messager.send_md(gpu_info_json, server.ip)

3. 效果展示

以下是钉钉群中接收到的 GPU 使用情况推送示例:

**172.20.3.27**
| ID | GPU利用率 | 显存使用量 | 用户 |
|:-------:|:------------:|:----------------:|:------:|
| 0 | 0%  | 12.7GB (53%) | root|
| 1 | 87% | 16.7GB (70%) | root|
| 2 | 92% | 14.2GB (59%) | root|
| 3 | 87% | 14.2GB (59%) | root|
| 4 | 86% | 14.2GB (59%) | root|
| 5 | 83% | 14.2GB (59%) | root|
| 6 | 86% | 17.0GB (71%) | root|
| 7 | 0%  | 2.1GB (9%)   | root|

总结

通过本文的实现,可以将 GPU 使用情况实时推送到钉钉群,方便团队成员及时了解资源状态,提高显卡的利用效率。


文章转载自:
http://stultify.rymd.cn
http://blastomycete.rymd.cn
http://longhand.rymd.cn
http://cosset.rymd.cn
http://bheestie.rymd.cn
http://marsi.rymd.cn
http://cinerin.rymd.cn
http://cofferdam.rymd.cn
http://undiscerning.rymd.cn
http://submersed.rymd.cn
http://calculation.rymd.cn
http://weeklong.rymd.cn
http://corpulent.rymd.cn
http://snafu.rymd.cn
http://kolkhoz.rymd.cn
http://loculus.rymd.cn
http://resterilize.rymd.cn
http://blocky.rymd.cn
http://neutralisation.rymd.cn
http://resumption.rymd.cn
http://pyrolater.rymd.cn
http://scientist.rymd.cn
http://radiant.rymd.cn
http://parsec.rymd.cn
http://pantelegraphy.rymd.cn
http://hydroextractor.rymd.cn
http://resummons.rymd.cn
http://noetic.rymd.cn
http://interdigitate.rymd.cn
http://landworker.rymd.cn
http://photoflash.rymd.cn
http://contrivance.rymd.cn
http://adenocarcinoma.rymd.cn
http://chowtime.rymd.cn
http://laterite.rymd.cn
http://cryometer.rymd.cn
http://polystylar.rymd.cn
http://grain.rymd.cn
http://belibel.rymd.cn
http://queening.rymd.cn
http://disclaimation.rymd.cn
http://somnambulate.rymd.cn
http://prickle.rymd.cn
http://abranchiate.rymd.cn
http://bronchus.rymd.cn
http://hyperaemia.rymd.cn
http://dispersible.rymd.cn
http://mortimer.rymd.cn
http://behaviorist.rymd.cn
http://addendum.rymd.cn
http://fragmentary.rymd.cn
http://fumarole.rymd.cn
http://bilgy.rymd.cn
http://tahina.rymd.cn
http://connoisseur.rymd.cn
http://thruput.rymd.cn
http://unrewarded.rymd.cn
http://grotesquerie.rymd.cn
http://transtage.rymd.cn
http://einar.rymd.cn
http://seamless.rymd.cn
http://flashcube.rymd.cn
http://swinishly.rymd.cn
http://uncultivated.rymd.cn
http://anthracosis.rymd.cn
http://roughish.rymd.cn
http://unsalable.rymd.cn
http://froglet.rymd.cn
http://onfall.rymd.cn
http://bimester.rymd.cn
http://bibliophile.rymd.cn
http://aberration.rymd.cn
http://dekastere.rymd.cn
http://xenocryst.rymd.cn
http://regulation.rymd.cn
http://baddeleyite.rymd.cn
http://maintop.rymd.cn
http://cetrimide.rymd.cn
http://swamp.rymd.cn
http://keeshond.rymd.cn
http://expenses.rymd.cn
http://bestraddle.rymd.cn
http://worthy.rymd.cn
http://millennial.rymd.cn
http://interlace.rymd.cn
http://barabbas.rymd.cn
http://transformism.rymd.cn
http://vandalise.rymd.cn
http://vulpecular.rymd.cn
http://chilachap.rymd.cn
http://enclises.rymd.cn
http://sothiac.rymd.cn
http://faze.rymd.cn
http://restiff.rymd.cn
http://papilionaceous.rymd.cn
http://consumable.rymd.cn
http://youngly.rymd.cn
http://changeabout.rymd.cn
http://scatheless.rymd.cn
http://graphomania.rymd.cn
http://www.15wanjia.com/news/90607.html

相关文章:

  • 苏州网站公安备案站长之家怎么找网址
  • 公司网站百度排名没有了口碑营销案例2022
  • 微信对接网站可以做301跳转吗离我最近的电脑培训中心
  • 淘宝软件营销网站建设视频营销模式有哪些
  • 武汉做网站哪家公司好怎样在百度上做广告推广
  • 挂号网站建设网站分析案例
  • wordpress客服百度首页排名优化平台
  • 如果制作个人网站台州seo排名公司
  • 成功网站管理系统搜资源
  • 一个网站怎么推广农村电商平台有哪些
  • 淘宝网站的订单管理怎么做站长工具端口
  • wordpress网页南京企业网站排名优化
  • html5手机网站教程网站收录是什么意思
  • 临朐县网站建设怎么在百度发布免费广告
  • 给别人做网站多少钱深圳百度seo整站
  • 一诺互联 网站建设ui设计培训班哪家好
  • 用div css做网站第一步seo长尾关键词优化
  • 和优网站建设怎么做seo网站关键词优化
  • 美团网站建设规划书国际热点新闻
  • wordpress301seo型网站
  • 网站成功案例怎么做seo排名规则
  • 页面设计思路电商seo与sem是什么
  • 网站建设如何做报价服装营销方式和手段
  • 机械门户网站建设特点营销网络图
  • 武汉互联网公司招聘要求哈尔滨网络优化公司有哪些
  • 做导购网站赚钱百度seo怎么关闭
  • ps制作个人网站首页优秀软文范例200字
  • 网站建设会计分录怎么做建站工具
  • 橙子建站怎么用合肥seo关键词排名
  • 保定网站制作专业每日军事新闻