Skip to content

Commit

Permalink
[main] adds fabric support (#958)
Browse files Browse the repository at this point in the history
* adds fabric support

Signed-off-by: Mx772 <drewcarter0@gmail.com>

* Adds clarification for fabric support

Signed-off-by: Mx772 <drewcarter0@gmail.com>

---------

Signed-off-by: Mx772 <drewcarter0@gmail.com>
  • Loading branch information
Mx772 authored Sep 29, 2024
1 parent 8d571f4 commit fedbd56
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CONTAINER.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ You could use the flags too, but I would not recommend it. I prefer to use the e
| MC_RCON_ADDRESS | Address for the Minecraft RCON. |
| MC_RCON_PASSWORD | Password for the Minecraft RCON. |
| MC_NAME_SOURCE | How to retrieve names of players: offline, bukkit, mojang. |
| MC_MOD_SERVER_STATS | Additional server stats for papermc or forge |
| MC_MOD_SERVER_STATS | Additional server stats for papermc, forge, and fabric |

### Legal Disclaimer 👮

Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Flags:
Password of the Minecraft rcon.
--mc.name-source="mojang" How to retrieve names of players: offline, bukkit, mojang.
--mc.mod-server-stats=MC.MOD-SERVER-STATS
Additional server stats for papermc, purpurmc or forge
Additional server stats for papermc, purpurmc, forge, or fabric.
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
--version Show application version.
Expand All @@ -162,17 +162,17 @@ Flags:
You can override CLI flags using config file. By default, `config.yml` located in the current directory is used. Path to
config file can be changed using `--config-path` CLI flag.

| Key in config file | Equivalent CLI flag | ENV variable | Description |
|----------------------------|----------------------------------|-------------------------------|--------------------------------------------------------------|
| `metrics-path` | `--web.telemetry-path` | WEB_TELEMETRY_PATH | Path under which to expose metrics. |
| `listen-address` | `--web.listen-address` | WEB_LISTEN_ADDRESS | Address to listen on for web interface and telemetry. |
| `disable-exporter-metrics` | `--web.disable-exporter-metrics` | WEB_DISABLED_EXPORTER_METRICS | Disabling collection of exporter metrics (like go_*) |
| `web-config` | `--mc.config-path` | MC_CONFIG_PATH | Path to YAML file with config for the mc variables |
| `world-path` | `--mc.world` | MC_WORLD | Path to the world folder. |
| `rcon-address` | `--mc.rcon-address` | MC_RCON_ADDRESS | Address for the Minecraft RCON. |
| `rcon-password` | `--mc.rcon-password` | MC_RCON_PASSWORD | Password for the Minecraft RCON. |
| `name-source` | `--mc.name-source` | MC_NAME_SOURCE | How to retrieve names of players: offline, bukkit, mojang. |
| `mod-server-stats` | `--mc.mod-server-stats` | MC_MOD_SERVER_STATS | Set server for additional stats (papermc, purpurmc or forge) |
| Key in config file | Equivalent CLI flag | ENV variable | Description |
|----------------------------|----------------------------------|-------------------------------|-----------------------------------------------------------------------|
| `metrics-path` | `--web.telemetry-path` | WEB_TELEMETRY_PATH | Path under which to expose metrics. |
| `listen-address` | `--web.listen-address` | WEB_LISTEN_ADDRESS | Address to listen on for web interface and telemetry. |
| `disable-exporter-metrics` | `--web.disable-exporter-metrics` | WEB_DISABLED_EXPORTER_METRICS | Disabling collection of exporter metrics (like go_*) |
| `web-config` | `--mc.config-path` | MC_CONFIG_PATH | Path to YAML file with config for the mc variables |
| `world-path` | `--mc.world` | MC_WORLD | Path to the world folder. |
| `rcon-address` | `--mc.rcon-address` | MC_RCON_ADDRESS | Address for the Minecraft RCON. |
| `rcon-password` | `--mc.rcon-password` | MC_RCON_PASSWORD | Password for the Minecraft RCON. |
| `name-source` | `--mc.name-source` | MC_NAME_SOURCE | How to retrieve names of players: offline, bukkit, mojang. |
| `mod-server-stats` | `--mc.mod-server-stats` | MC_MOD_SERVER_STATS | Set server for additional stats (papermc, purpurmc, forge, or fabric) |

#### Disable exporter metrics

Expand Down Expand Up @@ -440,9 +440,11 @@ minecraft_won_raids_total{player="ediri"} 0

#### Metrics for specific mods

To export the metrics for a specific mod, you can set the flag: `--mc.mod-server-stats=forge|papermc` or use the
To export the metrics for a specific mod, you can set the flag: `--mc.mod-server-stats=forge|papermc|fabric` or use the
environment variable `MC_MOD_SERVER_STATS`.

**Note:** Fabric requires the [Fabric TPS](https://modrinth.com/mod/fabric-tps) mod.

#### Forge

`minecraft-exporter` exports mean TPS and mean tick time for every dimension and of course the overall mean TPS and mean
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewConfg() *Config {
rconAddress = kingpin.Flag("mc.rcon-address", "Address of the Minecraft rcon.").Envar("MC_RCON_ADDRESS").Default(":25575").String()
rconPassword = kingpin.Flag("mc.rcon-password", "Password of the Minecraft rcon.").Envar("MC_RCON_PASSWORD").String()
nameSource = kingpin.Flag("mc.name-source", "How to retrieve names of players: offline, bukkit, mojang.").Envar("MC_NAME_SOURCE").Default("mojang").String()
modServerStats = kingpin.Flag("mc.mod-server-stats", "Set server for additional stats (papermc, purpurmc or forge)").Envar("MC_MOD_SERVER_STATS").String()
modServerStats = kingpin.Flag("mc.mod-server-stats", "Set server for additional stats (papermc, purpurmc, forge, or fabric)").Envar("MC_MOD_SERVER_STATS").String()
)
return &Config{
ConfigPath: configPath,
Expand Down
26 changes: 26 additions & 0 deletions pkg/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ const (
Namespace = "minecraft"
Forge = "forge"
PaperMC = "papermc"
Fabric = "fabric"
PurpurMC = "purpurmc"
rconListCommand = "list"
rconForgeTpsCommand = "forge tps"
rconForgeEntityListCommand = "forge entity list"
rconTpsCommand = "tps"
rconFabricTpsCommand = "fabric tps"
)

// See for all details on the statistics of Minecraft https://minecraft.fandom.com/wiki/Statistics
Expand All @@ -46,6 +48,7 @@ type Exporter struct {
entityListRegexp *regexp.Regexp
paperMcTpsRegexp *regexp.Regexp
purpurMcTpsRegexp *regexp.Regexp
fabricMcTpsRegexp *regexp.Regexp

Check failure on line 51 in pkg/exporter/exporter.go

View workflow job for this annotation

GitHub Actions / lint

field `fabricMcTpsRegexp` is unused (unused)
// via advancements
// playerAdvancements *prometheus.Desc

Expand Down Expand Up @@ -843,6 +846,29 @@ func (e *Exporter) getServerStats(ch chan<- prometheus.Metric) (retErr error) {
}
}
}
} else if e.serverStats == Fabric {
resp, err := e.executeRCONCommand(rconFabricTpsCommand)
if err != nil {
return err
}
if resp != nil {
dimTpsList := e.dimensionRegexp.FindAllStringSubmatch(*resp, -1)
for _, dimTps := range dimTpsList {
namespace := dimTps[1]
dimension := dimTps[2]
meanTickTimeDimension := parseFloat64FromString(dimTps[3])
meanTpsDimension := parseFloat64FromString(dimTps[4])
ch <- prometheus.MustNewConstMetric(e.dimTps, prometheus.CounterValue, meanTpsDimension, namespace, dimension)
ch <- prometheus.MustNewConstMetric(e.dimTicktime, prometheus.CounterValue, meanTickTimeDimension, namespace, dimension)
}
overall := e.overallRegexp.FindStringSubmatch(*resp)
if len(overall) == 3 {
meanTickTime := parseFloat64FromString(overall[1])
meanTps := parseFloat64FromString(overall[2])
ch <- prometheus.MustNewConstMetric(e.overallTps, prometheus.CounterValue, meanTps)
ch <- prometheus.MustNewConstMetric(e.overallTicktime, prometheus.CounterValue, meanTickTime)
}
}
}
return nil
}
Expand Down

0 comments on commit fedbd56

Please sign in to comment.