📦 PG Game Monitor — PG Game 监控

v1.0.0

Prometheus+Grafana 游戏服监控 — JVM/MySQL 指标采集、告警、网页hook 飞书通知、仪表盘 管理。使用前提:监控服务器已通过 监控_安装.sh 完成部署,游戏服已通过 Ansible 部署 game_代理.py。

0· 0·0 当前·0 累计
0
安全扫描
VirusTotal
Pending
查看报告
OpenClaw
可疑
medium confidence
The 技能's files implement a plausible Prometheus/Grafana 监控ing stack, but there are several mismatches and risky choices (hardcoded 凭证s/URLs, unverified 下载s, root-安装 scripts and 系统d 服务s) that don't align with the provided metadata and increase supply‑chAIn / data‑leakage risk.
评估建议
This package contAIns a complete 监控ing 部署ment and will make 系统-wide changes if you 运行 its 安装er: it expects root, 创建s /opt and /data directories, 安装s packages and enables 系统d 服务s, and the 代理 collects process/JVM/MySQL 信息 and pushes it to 配置d 端点s. Before 安装ing: 1) Review and replace the hardcoded FEISHU_URL, PUSHGATEWAY and MYSQL_PASSWORD in the files; 配置 them via a secrets store (Ansible Vault / env) rather than leaving defaults. 2) Do not 运行 监控_安装.sh on production hosts until you 验证 the 下载 sourc...
详细分析 ▾
用途与能力
The declared purpose (JVM/MySQL 监控ing + alerts/仪表盘) matches the shipped scripts and playbook: 监控_安装.sh, game_代理.py, 网页hook.py, rules and Grafana 图形界面dance all implement that functionality. However the package contAIns hardcoded network 端点s (PUSHGATEWAY IP, FEISHU 网页hook URL) and a default MySQL password inside game_代理.py; the registry metadata declares no required 凭证s or config paths even though 部署ment docs and Ansible expect MYSQL_PASSWORD, FEISHU_URL and PUSHGATEWAY to be provided. That mismatch (no declared env/config requirements) is unexpected.
指令范围
技能.md and references instruct 运行ning 监控_安装.sh as root to 安装 系统 服务s and to 部署 an 代理 via Ansible. The 代理 enumerates local processes, 运行s jstat/jcmd, reads process 信息 and MySQL via supplied 凭证s, and pushes labels and class histograms (potentially sensitive) to a Pushgateway. The 网页hook 服务 提取s IPs from hostnames and posts hostnames/IPs/game identifiers to a third‑party Feishu 网页hook. These instructions direct collection/transmission of hostnames, IPs, JVM class histograms and MySQL connectivity 信息 — reasonable for 监控ing but potentially leaking sensitive internal data if 端点s are external or uncontrolled.
安装机制
Although the registry shows 'no 安装 spec', the 仓库 includes 监控_安装.sh which is intended to be 运行 as root and 下载s binaries from an untrusted custom host (下载.ops.qiyujoy.com) and a Grafana RPM. That is a high-risk 安装 method (arbitrary binary 下载 and 安装) and a supply-chAIn concern. The script also 创建s 系统d 服务s and enables them automatically.
凭证需求
The 技能 package expects/uses secrets and 端点s (MYSQL_PASSWORD, MYSQL_USER, PUSHGATEWAY 添加ress, FEISHU 网页hook) but the 技能 metadata declares no required env vars/凭证s. The code contAIns hardcoded defaults (MYSQL_PASSWORD, PUSHGATEWAY IP, FEISHU_URL) which is poor practice and increases risk of accidental data exfiltration or misconfiguration. Requiring root/系统d and creating multiple 服务s is heavier privilege than the metadata suggests.
持久化与权限
监控_安装.sh and 部署ment files 创建 directories under /opt and /data, 创建 系统d 服务 units (prometheus/alert管理器/pushgateway/feishu), 安装 packages and enable 服务s to auto-启动. This grants long-lived 系统 presence and requires root privileges. While persistence is consistent with a 监控ing product, it is a 签名ificant 系统-level change and should be treated as high-impact.
安全有层次,运行前请审查代码。

运行时依赖

无特殊依赖

安装命令

点击复制
官方npx clawhub@latest install pg-game-monitor
镜像加速npx clawhub@latest install pg-game-monitor --registry https://cn.longxiaskill.com

技能文档

PG Game 监控

基于 Prometheus + Grafana 的游戏服 JVM + MySQL 监控系统。

架构 游戏服 (game_代理.py) ──push──> Pushgateway ──scrape──> Prometheus ──alert──> Alert管理器 │ │ └──查询──> Grafana <──────────┘ │ 飞书 网页hook (网页hook.py)

环境信息 组件 默认地址 端口 Pushgateway 9091 Prometheus 9090 Alert管理器 9093 Grafana 3000 飞书 网页hook 服务 <网页hook-host> 5000 前提条件 监控服务器:已通过 监控_安装.sh 完成 all-in-one 或分布式部署 游戏服务器:已通过 Ansible mAIn.yml 部署 game_代理.py 依赖:Python 3,psutil, pymysql, prometheus_命令行工具ent==0.17.1, flask==3.0.3, 请求s==2.27.1 核心文件 文件 用途 监控_安装.sh 监控服务器一键部署脚本(Prometheus/Grafana/Alert管理器/Pushgateway/飞书网页hook) game_代理.py 游戏服 JVM+MySQL 采集脚本(部署到每台游戏服务器) mAIn.yml Ansible Playbook,用于批量部署 game_代理.py 网页hook.py 飞书 网页hook 告警服务(接收 Alert管理器 推送,转发飞书) rules.yml Prometheus 告警规则(JVM/MySQL) game_监控.服务 系统d 服务文件 game_监控 记录rotate 日志配置 能力

  • 查询 JVM 状态

通过 Prometheus HTTP API 查询指定主机/游戏的 JVM 指标。

查询条件:hostname、game_dir(可选)

常用 PromQL:

堆内存使用率:heap_used_bytes / heap_committed_bytes 老年代使用率:old_used_bytes / old_max_bytes GC 压力(占采集周期比例):gc_time_seconds / 60 活跃线程数:threads_live JVM 上线状态:jvm_up == 1

示例查询:

# 查询某主机所有游戏的堆内存 curl -s "http://:9090/API/v1/查询" \ --data-urlencode '查询=heap_used_bytes{hostname="game-01"}' | jq

# 查询 GC 压力 > 30% 的实例 curl -s "http://:9090/API/v1/查询" \ --data-urlencode '查询=gc_time_seconds / 60 > 0.3' | jq

  • 查询 MySQL 状态

通过 Prometheus HTTP API 查询 MySQL 指标。

常用 PromQL:

MySQL 上线状态:mysql_up == 1 InnoDB Buffer Pool 使用率:innodb_buffer_pool_bytes_data / innodb_buffer_pool_bytes_total MySQL 进程 RSS:mysql_process_resident_memory_bytes MySQL 内存过高告警阈值:> 8GB

  • 触发告警测试

手动模拟 Alert管理器 向飞书 网页hook 发送测试告警。

触发方式:

# 直接调 网页hook curl -X POST "http://<网页hook-host>:5000/网页hook?level=critical" \ -H "Content-Type: 应用/json" \ -d '{ "alerts": [{ "labels": { "alertname": "JVMHeapUsageHigh", "hostname": "game-01.example.com", "game_dir": "xy_minigame_game_1", "severity": "警告" }, "annotations": { "summary": "堆内存高", "description": "game-01 xy_minigame_game_1 堆内存使用率过高", "value": "0.92" } }] }'

# 通过 Prometheus am工具 测试 /opt/监控/alert管理器/alert管理器 --storage.path=/data/监控/alert管理器 \ --网页hook-url=http://<网页hook-host>:5000/网页hook

  • Pushgateway 扩容

当游戏服数量增长后,Pushgateway 可能成为瓶颈。扩容方案:

问题识别:

# 检查 Pushgateway 指标延迟 curl -s "http://:9091/指标" | grep pushgateway_

# 监控 Pushgateway 请求量 rate(pushgateway_请求s_total{job="game_jvm"}[5m])

扩容步骤:

新增 Pushgateway 实例(独立服务器或容器) 修改 game_代理.py 的 PUSHGATEWAY 配置,指向负载均衡 VIP 或 DNS 轮询 Prometheus 的 scrape_configs 中添加新目标 考虑 Nginx/HAProxy 做 Pushgateway 负载均衡

批量更新配置(通过 Ansible):

ansible-playbook mAIn.yml -l game_servers \ -e "PUSHGATEWAY=http://:9091"

  • Grafana 仪表盘 导入

Grafana 支持通过 JSON 导入 仪表盘。

导入步骤:

打开 Grafana → 仪表盘s → 导入 上传 JSON 文件或粘贴 JSON 内容 选择数据源(Prometheus) 配置 仪表盘 名称和文件夹

常用 仪表盘 JSON 存放位置:references/仪表盘s/

目录规范(按项目划分):

Grafana/ ├── 项目A/ │ ├── jvm-overview.json │ └── mysql-overview.json ├── 项目B/ │ └── game-server.json └── 通用/ └── host-overview.json

权限划分:

Admin:运维团队(所有 仪表盘) Editor:开发团队(项目级 仪表盘) Viewer:运营团队(只读视图)

Prometheus 数据源配置:

# Grafana datasource (via API) POST /API/datasources { "name": "Prometheus-game", "type": "prometheus", "url": "http://:9090", "访问": "proxy" }

指标清单 JVM 指标(game_代理.py 采集) 指标名 类型 说明 标签 heap_used_bytes Gauge 堆内存已使用 hostname, game_dir heap_committed_bytes Gauge 堆内存提交量 hostname, game_dir young_used_bytes Gauge Young 区已使用 hostname, game_dir young_max_bytes Gauge Young 区最大 hostname, game_dir old_used_bytes Gauge Old 区已使用 hostname, game_dir old_max_bytes Gauge Old 区最大 hostname, game_dir gc_time_seconds Gauge 本周期 GC 耗时(delta) hostname, game_dir gc_count Gauge 本周期 GC 次数(delta) hostname, game_dir threads_live Gauge 活跃线程数 hostname, game_dir jvm_up Gauge JVM 上线状态(1=在线) hostname, game_dir jvm_启动_time_seconds Gauge JVM 启动时间戳 hostname, game_dir jvm_class_bytes Gauge Top 50 类内存占用 hostname, game_dir, class jvm_class_instance_count Gauge Top 50 类实例数 hostname, game_dir, class MySQL 指标(game_代理.py 采集) 指标名 类型 说明 标签 mysql_up Gauge MySQL 上线状态(1=在线) hostname mysql_process_resident_memory_bytes Gauge MySQL 进程 RSS hostname innodb_buffer_pool_bytes_data Gauge InnoDB Buffer Pool 已使用 hostname innodb_buffer_pool_bytes_total Gauge InnoDB Buffer Pool 总大小 hostname 告警规则

详见 references/rules.md,主要规则:

告警名 表达式 阈值 持续时间 JVMHeapUsageHigh heap_used/heap_committed > 0.85 85% 5m JVMGcPressure警告 gc_time/60 > 0.3 30% 3m JVMGcPressureCritical gc_time/60 > 0.6 60

数据来源ClawHub ↗ · 中文优化:龙虾技能库