diff --git a/01_卡资(金)/金仓_存储备份/服务器管理/scripts/存客宝_CPU与网络用量查询.py b/01_卡资(金)/金仓_存储备份/服务器管理/scripts/存客宝_CPU与网络用量查询.py new file mode 100644 index 00000000..9fba71a7 --- /dev/null +++ b/01_卡资(金)/金仓_存储备份/服务器管理/scripts/存客宝_CPU与网络用量查询.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +存客宝宝塔 42.194.245.239:查询 CPU 与网络用量。 +依赖:仅标准库。需将本机 IP 加入存客宝面板「设置」→「API 接口」白名单。 +""" +import time +import hashlib +import json +import urllib.request +import urllib.parse +import ssl + +PANEL_URL = "https://42.194.245.239:9988" +API_KEY = "TNKjqDv5N1QLOU20gcmGVgr82Z4mXzRi" +ssl._create_default_https_context = ssl._create_unverified_context + +def sign(): + t = int(time.time()) + s = str(t) + hashlib.md5(API_KEY.encode()).hexdigest() + return {"request_time": t, "request_token": hashlib.md5(s.encode()).hexdigest()} + +def post(endpoint, data=None): + url = PANEL_URL + endpoint + payload = sign() + if data: + payload.update(data) + req = urllib.request.Request(url, data=urllib.parse.urlencode(payload).encode()) + try: + with urllib.request.urlopen(req, timeout=15) as resp: + return json.loads(resp.read().decode()) + except Exception as e: + return {"status": False, "msg": str(e)} + +def main(): + print("=" * 56) + print(" 存客宝宝塔 42.194.245.239 · CPU 与网络用量") + print("=" * 56) + + # 1. 系统总览(CPU、内存、负载、磁盘) + sys_info = post("/system?action=GetSystemTotal", {}) + if sys_info.get("status") is False or sys_info.get("msg"): + print("❌ 系统接口:", sys_info.get("msg", sys_info)) + print("\n说明:将本机 IP 加入存客宝面板「设置」→「API 接口」白名单后可重新运行本脚本。") + return 1 + if "cpuRealUsed" not in sys_info and "load_average" not in sys_info: + print("❌ 未返回系统数据(可能 IP 未加入 API 白名单):", sys_info) + return 1 + + print("\n【CPU 与负载】") + print(" CPU 使用率: %s%%" % sys_info.get("cpuRealUsed", "N/A")) + print(" 负载(1/5/15): %s" % sys_info.get("load_average", "N/A")) + print("\n【内存】") + print(" 已用: %s%%" % sys_info.get("memRealUsed", "N/A")) + print(" 总/已用: %s / %s" % (sys_info.get("memTotal", "N/A"), sys_info.get("memRealUsed", "N/A"))) + print("\n【磁盘】") + print(" 使用率: %s%%" % sys_info.get("diskPer", "N/A")) + + # 2. 网络状态(实时流量) + net_info = post("/system?action=GetNetWork", {}) + if net_info.get("status") is False or net_info.get("msg"): + print("\n【网络】❌", net_info.get("msg", net_info)) + return 0 + if isinstance(net_info, dict) and (net_info.get("net_in") is not None or net_info.get("net_out") is not None or "net" in str(net_info).lower()): + print("\n【网络流量】") + for k, v in sorted(net_info.items()): + if v is not None and (k.startswith("net") or "byte" in k.lower() or "flow" in k.lower() or "in" in k or "out" in k): + print(" %s: %s" % (k, v)) + if not any(k.startswith("net") or "in" in k or "out" in k for k in (net_info.keys() if isinstance(net_info, dict) else [])): + print(" 原始数据:", json.dumps(net_info, ensure_ascii=False, indent=2)[:500]) + else: + print("\n【网络】 原始返回:", json.dumps(net_info, ensure_ascii=False)[:400]) + + print("\n" + "=" * 56) + return 0 + +if __name__ == "__main__": + exit(main()) diff --git a/运营中枢/工作台/gitea_push_log.md b/运营中枢/工作台/gitea_push_log.md index ff41db5c..6e36134f 100644 --- a/运营中枢/工作台/gitea_push_log.md +++ b/运营中枢/工作台/gitea_push_log.md @@ -28,3 +28,4 @@ | 2026-02-18 14:43:00 | 🔄 卡若AI 同步 2026-02-18 14:42 | 更新:运营中枢工作台 | 排除 >20MB: 5 个 | | 2026-02-19 11:54:40 | 🔄 卡若AI 同步 2026-02-19 11:54 | 更新:总索引与入口、金仓、水桥平台对接、运营中枢工作台 | 排除 >20MB: 5 个 | | 2026-02-19 14:33:01 | 🔄 卡若AI 同步 2026-02-19 14:32 | 更新:金仓、运营中枢工作台 | 排除 >20MB: 5 个 | +| 2026-02-19 14:41:41 | 🔄 卡若AI 同步 2026-02-19 14:41 | 更新:运营中枢工作台 | 排除 >20MB: 5 个 | diff --git a/运营中枢/工作台/代码管理.md b/运营中枢/工作台/代码管理.md index 9fe56306..c5a670a2 100644 --- a/运营中枢/工作台/代码管理.md +++ b/运营中枢/工作台/代码管理.md @@ -31,3 +31,4 @@ | 2026-02-18 14:43:00 | 成功 | 成功 | 🔄 卡若AI 同步 2026-02-18 14:42 | 更新:运营中枢工作台 | 排除 >20MB: 5 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) | | 2026-02-19 11:54:40 | 成功 | 成功 | 🔄 卡若AI 同步 2026-02-19 11:54 | 更新:总索引与入口、金仓、水桥平台对接、运营中枢工作台 | 排除 >20MB: 5 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) | | 2026-02-19 14:33:01 | 成功 | 成功 | 🔄 卡若AI 同步 2026-02-19 14:32 | 更新:金仓、运营中枢工作台 | 排除 >20MB: 5 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) | +| 2026-02-19 14:41:41 | 成功 | 成功 | 🔄 卡若AI 同步 2026-02-19 14:41 | 更新:运营中枢工作台 | 排除 >20MB: 5 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) | diff --git a/运营中枢/工作台/宝塔与存客宝服务器_消费与流量说明.md b/运营中枢/工作台/宝塔与存客宝服务器_消费与流量说明.md index 7cb8a6dc..4c91b8e1 100644 --- a/运营中枢/工作台/宝塔与存客宝服务器_消费与流量说明.md +++ b/运营中枢/工作台/宝塔与存客宝服务器_消费与流量说明.md @@ -134,10 +134,42 @@ sshpass -p 'Zhiqun1984' ssh -o StrictHostKeyChecking=no root@42.194.245.239 'bas --- -## 六、相关链接与文档 +## 六、存客宝 CPU 与网络用量分析 + +### 6.1 本机一键查询(需 API 白名单) + +脚本:`01_卡资(金)/金仓_存储备份/服务器管理/scripts/存客宝_CPU与网络用量查询.py` + +- **作用**:通过宝塔 API 拉取存客宝当前 **CPU 使用率、负载(1/5/15)、内存、磁盘、网络流量**。 +- **前提**:存客宝面板 → 设置 → API 接口 → 将本机公网 IP 加入白名单。 +- **执行**:`python3 "01_卡资(金)/金仓_存储备份/服务器管理/scripts/存客宝_CPU与网络用量查询.py"` +- **当前状态**:未加白名单时返回「IP校验失败,您的访问IP为[59.61.68.20]」,加白名单后即可在本机直接跑出用量。 + +### 6.2 拿到数据后如何看(分析含义) + +| 指标 | 含义 | 关注点 | +|------|------|--------| +| **CPU 使用率** | 当前 CPU 占用百分比 | 长期 >80% 需排查进程;偶发尖峰可结合业务时段看。 | +| **负载 load_average** | 1/5/15 分钟平均排队进程数 | 2 核机器:若 1 分钟负载持续 >2 表示 CPU 吃紧。 | +| **内存已用** | 已用内存占比 | 接近 100% 会触发 swap,影响性能。 | +| **磁盘使用率** | 根分区/数据盘占用 | 超 85% 需清理或扩容,避免写满。 | +| **网络 net_in / net_out** | 实时或累计入站/出站流量(字节) | 出站(net_out) 对应公网流量,与云厂商计费相关;突增可能为活动、爬虫、同步或异常外连。 | + +### 6.3 无法用 API 时的替代方式 + +- **方式 A**:登录宝塔面板 https://42.194.245.239:9988 → 首页看 CPU/内存/网络实时;「监控」看历史曲线。 +- **方式 B**:在能 SSH 登录的机器上执行: + `ssh root@42.194.245.239 'uptime; free -h; cat /proc/net/dev'` + 或运行 `存客宝_服务器流量与负载查询.sh`(见第五节)。 +- **方式 C**:腾讯云控制台 → 云服务器 → 存客宝实例 → 监控:看 **CPU 利用率、公网出带宽、出网流量** 趋势。 + +--- + +## 七、相关链接与文档 - 服务器资产与宝塔 API:`运营中枢/工作台/00_账号与API索引.md`(第五节) - 服务器管理 SKILL:`01_卡资(金)/金仓_存储备份/服务器管理/SKILL.md` - 宝塔 API 文档(含 GetNetWork 流量):`01_卡资(金)/金仓_存储备份/服务器管理/参考资料/宝塔api接口文档.md` - 腾讯云费用总览:https://console.cloud.tencent.com/expense/overview +- 存客宝 CPU/网络用量查询:`01_卡资(金)/金仓_存储备份/服务器管理/scripts/存客宝_CPU与网络用量查询.py` - 存客宝服务器流量与负载查询脚本:`01_卡资(金)/金仓_存储备份/服务器管理/scripts/存客宝_服务器流量与负载查询.sh`