
itzg/mc-monitor]([] ,适用于服务器管理员实时掌握服务器运行状态。
status 子命令快速检查指定 Minecraft 服务器的在线状态,返回明确的退出码(0 表示成功,1 表示失败)。gather-for-telegraf 子命令周期性采集服务器指标(如在线人数、响应时间等),并通过 Influx 线协议发送至 Telegraf。status 子命令的退出码触发自动化告警或故障恢复流程。status:检查服务器状态用于查询指定 Minecraft 服务器的实时状态,返回服务器是否可达及基本信息。
参数:
--host:Minecraft 服务器地址(必填)。--port:服务器端口(可选,默认 25565)。退出码:
0:服务器状态正常(可达)。1:服务器状态异常(不可达或无响应)。示例:
bashdocker run -ti --rm itzg/mc-monitor status --host mc.hypixel.net --port 25565
gather-for-telegraf:周期性指标收集用于周期性采集一个或多个 Minecraft 服务器的性能指标,并通过 TCP 协议以 Influx 线协议格式发送至 Telegraf。
status 子命令)通过 docker run 直接执行状态检查:
bash# 检查 mc.hypixel.net:25565 的状态 docker run -ti --rm itzg/mc-monitor status --host mc.hypixel.net
gather-for-telegraf 子命令)通过 Docker Compose 部署 Telegraf 与 mc-monitor,实现指标采集与存储。
步骤 1:准备 Telegraf 配置文件
创建 telegraf.conf,配置 Telegraf 监听 TCP 端口接收指标:
toml[[inputs.socket_listener]] service_address = "tcp://:8094" # 监听 8094 端口接收 Influx 协议数据 [[outputs.file]] files = ["stdout"] # 将接收到的指标输出到标准输出(可替换为 InfluxDB 等存储)
步骤 2:编写 Docker Compose 配置
创建 docker-compose.yml,定义 Telegraf 和 mc-monitor 服务:
yamlversion: '3' services: telegraf: image: telegraf:1.13 volumes: - ./telegraf.conf:/etc/telegraf/telegraf.conf:ro # 挂载配置文件 ports: - "8094:8094" # 暴露 TCP 端口供 mc-monitor 发送数据 monitor: image: itzg/mc-monitor command: gather-for-telegraf # 启动指标收集模式 environment: GATHER_INTERVAL: 10s # 采集间隔(如 10s、1m) GATHER_TELEGRAF_ADDRESS: telegraf:8094 # Telegraf 的 TCP 地址 GATHER_SERVERS: mc.hypixel.net,localhost:25565 # 监控的服务器列表(逗号分隔)
步骤 3:启动服务并查看指标
启动服务:
bashdocker-compose up
Telegraf 服务输出的指标示例(Influx 线协议格式):
minecraft_status,host=mc.hypixel.net,port=25565,status=success response_time=0.***,online=51201i,max=90000i 1576971568953660767 minecraft_status,host=localhost,port=25565,status=success response_time=0.05234512,online=10i,max=20i 1576971579020125479
gather-for-telegraf 子命令)使用 gather-for-telegraf 时,需通过环境变量配置采集参数:
| 环境变量 | 描述 | 示例值 |
|---|---|---|
GATHER_INTERVAL | 指标采集间隔(支持 s 秒、m 分等单位) | 10s(每 10 秒采集一次) |
GATHER_TELEGRAF_ADDRESS | Telegraf 服务的 TCP 地址(格式 host:port) | telegraf:8094 |
GATHER_SERVERS | 待监控的 Minecraft 服务器列表(逗号分隔,支持 host 或 host:port) | mc.hypixel.net,localhost:25566 |
gather-for-telegraf 输出的指标格式示例:
minecraft_status,host=mc.hypixel.net,port=25565,status=success response_time=0.***,online=51201i,max=90000i 1576971568953660767
host(服务器地址)、port(端口)、status(采集状态,success/failure)。response_time(响应时间,单位秒)、online(当前在线人数)、max(服务器最大容纳人数)。

manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务