| name | ops-toolkit |
| description | Server Operations Toolkit — Monitoring, Log Analysis, Service Management, Docker (服务器运维工具集 — 监控巡检、日志分析、服务管理、Docker容器管理) |
| version | 2.0.0 |
| category | devops |
| license | MIT |
| author | dockercore |
| triggers | ["运维","巡检","监控","服务器状态","server health","log analysis","日志分析","故障排查","troubleshooting","服务管理","service management","docker管理","docker management","容器管理","container management","sre"] |
ops-toolkit — Server Operations Toolkit / 服务器运维工具集
A comprehensive Linux/macOS server operations skill covering 4 modules: Monitoring, Log Analysis, Service Management, and Docker Management.
全面的 Linux/macOS 服务器运维 skill,覆盖监控巡检、日志分析、服务管理、Docker 容器管理四大模块。
Module 1: Server Monitoring & Health Check / 模块一:服务器监控与巡检
Quick Health Check / 一键健康检查
Run the built-in health check script to automatically inspect CPU, memory, disk, network, processes, services, and Docker:
运行内置巡检脚本,自动检查 CPU、内存、磁盘、网络、进程、服务、Docker 状态:
bash ~/.hermes/skills/devops/ops-toolkit/scripts/health-check.sh --quick
bash ~/.hermes/skills/devops/ops-toolkit/scripts/health-check.sh --full
bash ~/.hermes/skills/devops/ops-toolkit/scripts/health-check.sh --help
Expected Output / 期望输出:
=========================================
服务器健康巡检 2026-04-14 14:36:20
系统: Darwin
=========================================
[系统信息]
主机名: zailing
内核: 25.4.0
运行时间: up 7 days, 23:51
当前用户: dockercore
[CPU]
[OK] CPU 使用率 51%
CPU 核心数: 8
负载均值: 10.75 8.35 7.25
[内存]
[OK] 内存使用率 8% (1340M/16384M)
可用内存: 694M
[WARN] Swap 使用率 95% (6836M/7168M)
[磁盘]
[OK] 挂载: / 大小: 460Gi 已用: 12Gi 可用: 46Gi 使用率: 21%
[WARN] 挂载: /System/Volumes/Data 大小: 460Gi 已用: 375Gi 可用: 46Gi 使用率: 89%
[网络]
[OK] 监听端口数: 20
端口列表: 80 3306 5000 8080 ...
[进程]
[OK] 进程总数: 565
[OK] 无僵尸进程
[Docker]
[OK] Docker 守护进程运行中
运行容器: 5
镜像数: 12
=========================================
巡检完成
=========================================
Output Legend / 输出图例:
[OK] = Normal / 正常
[WARN] = Warning, needs attention / 警告,需要关注
[FAIL] = Critical, must fix immediately / 严重,必须立即处理
CPU Monitoring / CPU 监控
top -bn1 | grep "Cpu(s)" | awk '{print "User: "$2", System: "$4", Idle: "$8}'
top -l 1 -n 0 | grep "CPU usage"
nproc
sysctl -n hw.ncpu
cat /proc/loadavg
sysctl -n vm.loadavg
mpstat -P ALL 1 1
ps aux --sort=-%cpu | head -11
ps aux -r | head -11
What is Load Average? / 什么是负载均值?
- The three numbers represent 1-minute, 5-minute, and 15-minute averages
- 三个数字分别代表 1分钟、5分钟和 15分钟的平均值
- If you have 4 cores, load of 4.0 means 100% busy
- 如果你有 4 个核心,负载 4.0 表示 100% 繁忙
- Load > core count = processes are waiting / 负载 > 核心数 = 进程在排队
Memory Monitoring / 内存监控
free -m
vm_stat
cat /proc/meminfo | head -20
sysctl -n hw.memsize
ps aux --sort=-%mem | head -11
ps aux -m | head -11
watch -n2 free -m
Understanding Memory: / 理解内存:
used = memory currently in use / 当前使用的内存
free = completely unused memory / 完全未使用的内存
available = memory available for new programs (includes cache that can be freed)
available = 可分配给新程序的内存(含可释放的缓存)
buffers/cache = disk cache, automatically freed when needed
buffers/cache = 磁盘缓存,需要时自动释放
- Don't panic if
free is low — Linux uses free memory for cache
free 很低不要慌 — Linux 会把空闲内存用作缓存
Disk Monitoring / 磁盘监控
df -hT -x tmpfs -x devtmpfs
df -h
df -i -x tmpfs -x devtmpfs
du -ah /path 2>/dev/null | sort -rh | head -10
findmnt
mount
iostat -xz 1 3
What are Inodes? / 什么是 Inode?
- Every file uses one inode. If you create millions of tiny files, inodes run out before disk space does.
- 每个文件占用一个 inode。如果创建大量小文件,inode 会比空间先耗尽。
Network Monitoring / 网络监控
ss -tlnp
lsof -iTCP -sTCP:LISTEN -P -n
ss -s
netstat -s
ss -ant | awk '{print $1}' | sort | uniq -c | sort -rn
ip -s link show eth0
netstat -I en0
iftop -i eth0
nload
ss -nt | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head -10
Process Monitoring / 进程监控
ps auxf
ps aux
ps aux | awk '$8=="Z"'
lsof 2>/dev/null | awk '{print $1}' | sort | uniq -c | sort -rn | head -10
cat /proc/sys/fs/file-nr
pidstat -p <PID> 1 5
Module 2: Log Analysis & Troubleshooting / 模块二:日志分析与故障排查
System Logs / 系统日志
journalctl -n 50 --no-pager
journalctl --since "2024-01-01" --until "2024-01-02"
journalctl -p err -n 50
journalctl -u nginx.service --since "1 hour ago"
journalctl -f
dmesg -T -l err,warn | tail -20
Log Search / 通用日志搜索
grep -rn "ERROR" /var/log/ --include="*.log" | tail -20
awk '/2024-01-15 10:00/,/2024-01-15 11:00/' /var/log/app.log
grep "ERROR" /var/log/app.log | awk -F'[: ]' '{print $1}' | sort | uniq -c | sort -rn | head -10
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn
awk '$NF > 5 {print $0}' /var/log/nginx/access.log | tail -20
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20
Common Log Paths / 常见日志路径
| Service 服务 | Path 路径 |
|---|
| System 系统 | /var/log/syslog or /var/log/messages |
| Auth 认证 | /var/log/auth.log or /var/log/secure |
| Nginx | /var/log/nginx/access.log, /var/log/nginx/error.log |
| MySQL | /var/log/mysql/error.log |
| PostgreSQL | /var/log/postgresql/ |
| Docker | journalctl -u docker.service |
| App 应用 | /var/log/app/, /opt/app/logs/ |
7-Step Troubleshooting Workflow / 故障排查工作流
- System overview / 系统层面:
health-check.sh --full 获取全局状态
- Recent errors / 最近错误:
journalctl -p err --since "1 hour ago"
- Service logs / 服务日志:
journalctl -u <service> --since "30 min ago"
- Resource bottleneck / 资源瓶颈:
top / iotop / iftop 定位 CPU/IO/网络瓶颈
- Disk space / 磁盘空间:
df -h 确认未满
- File handles / 文件句柄:
cat /proc/sys/fs/file-nr and lsof | wc -l
- Network connectivity / 网络连通:
curl -v <url> / telnet <host> <port> / traceroute <host>
Module 3: Service Management / 模块三:服务管理
systemd Service Operations / systemd 服务操作
systemctl status <service>
systemctl status nginx
systemctl start <service>
systemctl stop <service>
systemctl restart <service>
systemctl reload <service>
systemctl enable <service>
systemctl disable <service>
systemctl --failed
journalctl -u <service> -n 50 --no-pager
systemctl list-units --type=service --state=running
systemctl list-dependencies <service>
Common Service Names / 常用服务名对照
| Application 应用 | Service Name 服务名 |
|---|
| Nginx | nginx |
| Apache | apache2 / httpd |
| MySQL | mysql / mysqld |
| PostgreSQL | postgresql |
| Redis | redis / redis-server |
| Docker | docker / dockerd |
| SSH | sshd |
| Cron | cron / crond |
| Firewall | ufw / firewalld |
Process Management / 进程管理(非 systemd)
pgrep -af <keyword>
kill <PID>
kill -9 <PID>
pkill -f <pattern>
killall <process_name>
ss -tlnp | grep <PID>
lsof -i -P -n | grep <PID>
SIGTERM vs SIGKILL: / SIGTERM 和 SIGKILL 的区别:
kill (SIGTERM, signal 15): Asks the process to shut down gracefully. The process can clean up.
kill (SIGTERM, 信号15): 请求进程优雅退出。进程可以清理资源。
kill -9 (SIGKILL, signal 9): Immediately kills the process. No cleanup. May cause data corruption.
kill -9 (SIGKILL, 信号9): 立即杀死进程。无法清理。可能导致数据损坏。
- Always try
kill first. Only use kill -9 as last resort.
- 始终先尝试
kill。kill -9 只作为最后手段。
Firewall Management / 防火墙管理
ufw status
ufw allow 80/tcp
ufw deny 3306/tcp
firewall-cmd --list-all
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
iptables -L -n -v
Module 4: Docker & Container Management / 模块四:Docker / 容器管理
Container Lifecycle / 容器生命周期
docker ps
docker ps -a
docker start <container>
docker stop <container>
docker restart <container>
docker run -d --name myapp -p 8080:80 nginx:latest
docker rm <container>
docker rm -f <container>
docker container prune -f
Container Operations / 容器运维
docker logs <container>
docker logs --tail 100 -f <container>
docker logs --since 1h <container>
docker logs --since "2024-01-15T10:00:00" <container>
docker exec -it <container> bash
docker exec -it <container> sh
docker stats
docker stats <container>
docker inspect <container>
docker top <container>
docker port <container>
Image Management / 镜像管理
docker images
docker pull <image>:<tag>
docker build -t myapp:v1 .
docker rmi <image>
docker image prune -f
docker inspect <image>
docker history <image>
Docker Compose
docker compose up -d
docker compose down
docker compose down -v
docker compose ps
docker compose logs -f <service>
docker compose restart <service>
docker compose pull
docker compose up -d --build
docker compose up -d --scale <service>=3
Docker System Maintenance / Docker 系统维护
docker system df
docker system prune -f
docker system prune -a -f
docker builder prune -f
docker volume prune -f
What each prune removes: / 各清理命令删除什么:
| Command 命令 | Removes 删除内容 | Risk 风险 |
|---|
docker system prune -f | Stopped containers, dangling images, unused networks, build cache | Low / 低 |
docker system prune -a -f | Above + all unused images | Medium (need re-pull) / 中(需重新拉取) |
docker volume prune -f | Unused volumes | HIGH (data loss!) / 高(数据丢失!) |
docker image prune -f | Dangling images only | Low / 低 |
docker builder prune -f | Build cache | Low / 低 |
Alert Thresholds Reference / 告警阈值参考
| Metric 指标 | Warning 警告 | Critical 严重 | Explanation 说明 |
|---|
| CPU usage | >70% | >90% | Server may become unresponsive / 服务器可能无响应 |
| Memory usage | >80% | >90% | OOM killer may trigger / 可能触发 OOM 杀进程 |
| Swap usage | >30% | >50% | Excessive swap = slow performance / 大量 Swap = 性能差 |
| Disk usage | >80% | >90% | Risk of write failure / 写入可能失败 |
| Inode usage | >80% | >90% | Cannot create new files / 无法创建新文件 |
| Zombie processes | >0 | >5 | May indicate bugs / 可能存在程序缺陷 |
| Load (1min) | >cores*0.7 | >cores | CPU overloaded / CPU 过载 |
Common Scenarios (Playbook) / 常见场景
"My server is slow / 服务器变慢了"
top -bn1 | head -20
free -m
iostat -xz 1 3
cat /proc/loadavg
"Disk is almost full / 磁盘快满了"
df -h
du -ah / 2>/dev/null | sort -rh | head -20
df -i
docker system prune -f
journalctl --vacuum-size=100M
"A service crashed / 服务挂了"
systemctl status <service>
journalctl -u <service> --since "30 min ago"
systemctl restart <service>
systemctl status <service>
curl -s http://localhost:<port>/
"Docker container keeps restarting / Docker 容器一直重启"
docker ps -a
docker logs --tail 100 <container>
docker inspect <container> | grep -A5 RestartPolicy
docker run -it --rm <image> sh
"High memory usage / 内存占用过高"
ps aux --sort=-%mem | head -11
free -m
pidstat -r -p <PID> 1 10
"Too many network connections / 网络连接异常多"
ss -ant | awk '{print $1}' | sort | uniq -c | sort -rn
ss -nt | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head -20
ss -tn | grep :80 | wc -l
iptables -A INPUT -s <bad_ip> -j DROP
Notes & Pitfalls / 注意事项与陷阱
- macOS compatibility / macOS 兼容性: The health-check.sh script auto-detects OS and uses appropriate commands. SKILL.md reference commands are primarily Linux-based. macOS differences: no
systemctl, no journalctl, no free, no /proc filesystem. macOS uses vm_stat, top -l 1, lsof, sysctl instead.
- Permissions / 权限问题: Some commands need
sudo (e.g., iptables, lsof for other users' processes, Docker for non-docker group users).
- Log rotation / 日志轮转: Before searching large log files, check size with
wc -l to avoid hanging.
- Docker log bloat / Docker 日志膨胀: Always configure
log-driver and log-opts in production to limit log size. Add to /etc/docker/daemon.json: {"log-driver": "json-file", "log-opts": {"max-size": "10m", "max-file": "3"}}.
kill -9 risk / kill -9 风险: Force kill may cause data loss. Always prefer kill (SIGTERM) first.
docker system prune -a / 深度清理风险: Removes ALL unused images. Next deploy will need to re-pull. Confirm before running.
- Container timezone / 容器时区: Docker containers default to UTC. Logs may be 8 hours behind local time. Set timezone with
-e TZ=Asia/Shanghai or mount /etc/localtime.
- macOS
/dev disk 100%: This is normal for devfs virtual filesystem, not an actual problem. Can be safely ignored in health check reports.
Multi-Agent Integration / 多智能体集成
This skill can be used in three popular AI agents. Below are quick-start instructions.
此技能可在三大主流 AI 智能体中使用,以下是快速上手指南。
Claude Code (Anthropic)
Setup / 配置:
cat >> CLAUDE.md << 'EOF'
Health check script: bash scripts/health-check.sh --full
Key commands:
- Quick check: bash scripts/health-check.sh --quick
- Full check: bash scripts/health-check.sh --full
- Help: bash scripts/health-check.sh --help
EOF
mkdir -p .claude/commands
cat > .claude/commands/health-check.md << 'EOF'
Run the server health check and analyze results:
1. Execute: bash scripts/health-check.sh --full
2. Analyze any [WARN] or [FAIL] items
3. Suggest fixes for each issue found
EOF
mkdir -p .claude/agents
cat > .claude/agents/sre-operator.md << 'EOF'
---
name: sre-operator
description: SRE operations and health check agent
model: sonnet
tools: [Read, Bash]
---
You are an SRE operator. When asked about server health:
1. Run health-check.sh with appropriate flags
2. Analyze the output for warnings and failures
3. Provide actionable fix recommendations
4. For critical issues, suggest immediate mitigation steps
EOF
Usage / 使用:
claude -p "运行服务器巡检并分析结果" --allowedTools 'Read,Bash' --max-turns 10
claude "帮我检查服务器健康状态,分析巡检报告"
claude "Use @sre-operator to run a full health check"
/health-check
Hermes Agent (Nous Research)
Setup / 配置:
hermes skills search ops-toolkit
hermes skills install ops-toolkit
cp -r ~/.hermes/skills/devops/ops-toolkit ~/.hermes/skills/devops/ops-toolkit
Usage / 使用:
/skill ops-toolkit
hermes -s ops-toolkit
Gateway Mode / 网关模式:
Run health checks from Telegram, Discord, Slack, WhatsApp, etc.
从 Telegram、Discord、Slack、WhatsApp 等平台触发巡检。
hermes gateway run
OpenClaw
Setup / 配置:
cp -r ~/.hermes/skills/devops/ops-toolkit ~/.openclaw/skills/ops-toolkit
openclaw skills list
openclaw skills info ops-toolkit
Usage / 使用:
openclaw agent --local "运行健康巡检脚本 bash scripts/health-check.sh --full"
openclaw message send --channel telegram --target @mychat --message "巡检报告:CPU 85% 警告"
openclaw agent --to +155****0123 --message "帮我检查服务器状态" --deliver
Gateway Mode / 网关模式:
openclaw gateway --port 18789
Comparison / 对比
| Feature / 特性 | Claude Code | Hermes Agent | OpenClaw |
|---|
| Skill auto-load / 自动加载 | CLAUDE.md | ~/.hermes/skills/ | ~/.openclaw/skills/ |
| Custom commands / 自定义命令 | .claude/commands/ | /skill + cron | openclaw skills |
| Messaging platforms / 消息平台 | No | 15+ platforms | Multiple platforms |
| Parallel tasks / 并行任务 | tmux sessions | delegate_task | openclaw agents |
| Scheduled checks / 定时巡检 | External cron | Built-in cronjob | External cron |
| Chinese support / 中文支持 | Partial | Full (bilingual) | Full (中文版) |
Documentation / 文档