mod 元信息与打包数据

[!INFO] Git Commit: 5ea0bc3 | Updated: 2026-10-01

基本信息

属性 值
modid prometheus_exporter
mod 名称 Prometheus Exporter
@Mod 类 com.github.cpburnz.minecraft_prometheus_exporter.PrometheusExporterMod
作者 cpburnz(原作者)、Caedis(GTNH 维护)
接受版本 [1.7.10];acceptableRemoteVersions = *
适用侧 仅服务端(客户端在 preInit 直接 return)
源码文件总数 20 个 .java(16 个 main + 4 个 test)
自有方块 / 物品 / 实体 0 / 0 / 0
指令 1 个:/prometheus(别名 /prom)
Access Transformer META-INF/mpe_AT.cfg(1 条)

本 mod 不向游戏内添加任何内容,因此可以随时用新版本 jar 覆盖旧版而不影响存档。 它向 JVM 内嵌的 HTTP 服务器暴露 Prometheus 抓取端点。

modid 的来源

modid 在两处一致,没有使用 gradleTokenModId 占位符:

  • PrometheusExporterMod.java:51 — public static final String MODID = "prometheus_exporter";
  • gradle.properties — modId = prometheus_exporter

gradle.properties 中 gradleTokenModId = (空值), 而 generateGradleTokenClass = com.github.cpburnz.minecraft_prometheus_exporter.prometheus_exporter.Tags、 gradleTokenVersion = VERSION、replaceGradleTokenInFile =(空值)。

Tags 类由构建期生成,源码树中不存在(git ls-files 中无对应文件), 仓库内唯一引用点是 PrometheusExporterMod.java:24 的 import 与 :44 的 version = Tags.VERSION。所以运行期可读的 modid 只有 prometheus_exporter。

modid 含下划线(prometheus_exporter),资源域同为 assets/prometheus_exporter/——两者一致, 不存在 modid ≠ 资源域的情况。仓库中另有 3 处从上游遗留的另一种写法: 包名 com.github.cpburnz.minecraft_prometheus_exporter 与日志类别字符串 "prometheus_exporter"(Sampler.java:24),而主类的 logger 用的是 LogManager.getLogger(MODID)(PrometheusExporterMod.java:62),也是 prometheus_exporter。 即两个 logger 同名,见下文。

Access Transformer

mpe_AT.cfg 只有 1 行,作用是开放 TileEntity 的类名映射表:

public net.minecraft.tileentity.TileEntity field_145853_j # classToNameMap

field_145853_j 是 TileEntity.classToNameMap(Map<Class<? extends TileEntity>, String>)的 混淆字段名。开放它是为了 TileEntities 采集器在 tileentities_details 模式下取到方块实体的 注册名(TileEntities.java:52):

String teName = (String) TileEntity.classToNameMap.get(teClass);
if (teName != null) { ... }

classToNameMap 对未注册的 TileEntity 类返回 null,此时该实体被静默跳过、不计数—— teName != null 是唯一的入账条件(TileEntities.java:53-56)。

打包的 Prometheus 客户端库

usesShadowedDependencies = true,4 个 io.prometheus 依赖被 shadow 进本 jar 并重定位包名:

依赖 版本
io.prometheus:simpleclient 0.16.0
io.prometheus:simpleclient_hotspot 0.16.0
io.prometheus:simpleclient_httpserver 0.16.0
io.prometheus:simpleclient_pushgateway 0.16.0

simpleclient_pushgateway 被声明为依赖但源码中无任何引用(无 Pushgateway 导入), 属于未使用的打包依赖。另两个非 shadow 依赖:

依赖 配置 作用
com.github.GTNewHorizons:GTNHLib:0.6.3:dev api 配置系统 + 事件总线
com.github.GTNewHorizons:ServerUtilities:2.1.17:dev devOnlyNonPublishable 队伍采集器的编译期依赖

ServerUtilities 是 devOnly——运行期不要求安装,ModCompat 会在采集时检查 (见 指标与采集器)。

资源目录

文件 用途
mcmod.info 标准 Forge 元信息,logoFile 指向内嵌 PNG
META-INF/mpe_AT.cfg 1 条 access transformer
assets/prometheus_exporter/Prometheus_Exporter.png 模组图标

没有语言文件(src/main/resources 下无任何 .lang / en_us.json)。这与 PrometheusCommand.java:19-20 的一条 TODO 吻合:

// TODO: I can't get ChatComponentTranslation to work with strings defined in
// "assets/prometheus_exporter/lang/en_us.json".

该 TODO 引用的 en_us.json 在仓库中并不存在——是一条失效的遗留注释。后果是 /prometheus 的所有提示消息都是硬编码英文字符串常量(定义在 PrometheusCommand 接口中,:25-50),不可本地化。详见 prometheus 指令。

事件与生命周期

主类只有 4 个事件处理器:

事件 方法 动作
FMLPreInitializationEvent onPreInitialization 注册配置;客户端在此 return(:207),服务端侧注册事件总线(:210-212)
FMLServerStartingEvent onServerStarting 注册 /prometheus 指令;记录 mc_server(:221-227)
FMLServerStartedEvent onServerStarted 服务端侧 startExporter()(:237-243)
FMLServerStoppedEvent onServerStopped stopExporter()(若在运行);mc_server = null(:250-256)

客户端仍然会加载本 mod(preInit 注册配置后直接返回),但不会启动 HTTP 服务器、 不会注册任何采集器、不会注册指令。

两处同名的 logger

private static final Logger LOG = LogManager.getLogger(MODID);            // PrometheusExporterMod:62
private static final Logger LOG = LogManager.getLogger("prometheus_exporter");  // Sampler:24

两个 logger 使用同一个 log4j2 logger 名,因此在日志配置中表现为同一个类别, 无法区分来源。Ticks 则用 PrometheusExporterMod.LOG。

事件总线的注册方式

@Mod.EventHandler 处理 FML 事件(preInit / server starting / started / stopped), 而两个采集器基类用 GTNHLib 的 @EventBusSubscriber 注解注册到 com.gtnewhorizon.gtnhlib.eventbus.EventBusSubscriber——不是 Forge 的 @Mod.EventBusSubscriber:

类 注解来源 静态订阅方法
CollectorScheduler GTNHLib @EventBusSubscriber onServerTick(TickEvent.ServerTickEvent)(:79-84)
Ticks GTNHLib @EventBusSubscriber onServerTick、onDimensionTick(:260-288)

Ticks 还带一个 GTNHLib 的条件注解 @EventBusSubscriber.Condition:

@EventBusSubscriber.Condition
public static boolean enabled() { return ExporterConfig.collector.ticks; }

Ticks.java:105-108。该条件在事件分发时求值,因此把配置里的 ticks 从 true 改为 false 后无需重启即可停止接收 tick 事件——与其他采集器不同,后者的开关只在 initCollectors() 时读取一次。详见 配置。