Merge pull request #23 from surdaft/master

Rename stat (since 1.17) + Automated docker images + HTTP_PORT env variable
This commit is contained in:
Joshi 2022-02-23 22:55:54 +01:00 committed by GitHub
commit 299058a2a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 141 additions and 18 deletions

27
.github/workflows/docker-image.yml vendored Normal file
View file

@ -0,0 +1,27 @@
name: Docker Image CI
on:
workflow_dispatch:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Publish Docker Image
# You may pin to the exact commit or the version.
# uses: elgohr/Publish-Docker-Github-Action@191af57e15535d28b83589e3b5f0c31e76aa8733
uses: elgohr/Publish-Docker-Github-Action@3.04
with:
# The name of the image you would like to push
name: surdaft/minecraft-exporter
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# for testing
world

View file

@ -1,15 +1,16 @@
# minecraft-exporter # minecraft-exporter
this is a prometheus minecraft exporter This is a prometheus minecraft exporter
This exporter reads minecrafts nbt files, the advancements files and can optionally connect via RCON to your minecraft server. This exporter reads minecrafts nbt files, the advancements files and can optionally connect via RCON to your minecraft server.
to use it mount your world to /world in the container To use it mount your world to /world in the container
rcon connection is used to get online Players RCON connection is used to get online Players
On Forge Servers enable FORGE_SERVER to get tps information On Forge Servers enable FORGE_SERVER to get tps information
On Paper Servers enable PAPER_SERVER to get tps information On Paper Servers enable PAPER_SERVER to get tps information
to enable rcon on your minecraft server add the following to the server.properties file: To enable rcon on your minecraft server add the following to the server.properties file:
``` ```
broadcast-rcon-to-ops=false broadcast-rcon-to-ops=false
@ -18,8 +19,22 @@ rcon.password=Password
enable-rcon=true enable-rcon=true
``` ```
The RCON Module is only enabled if `RCON_HOST` and `RCON_PASSWORD` is set > Note: Broadcast RCON to ops is disabled, to avoid ops receiving spam whilst ingame.
---
# Environment Variables
| Name | Default | Description |
| ------------- | ------- | ------------------------------------------------- |
| RCON_HOST | `None` | Host of the RCON server |
| RCON_PORT | `None` | Port RCON is hosted on |
| RCON_PASSWORD | `None` | RCON Password for access |
| HTTP_PORT | `8000` | Port to host on, in case of using outside docker* |
> * Or other cases where you have limited control of port mappings, eg Pterodactyl.
---
# Usage # Usage
@ -59,7 +74,9 @@ player_used_crafting_table
player_quests_finished # support for betterquesting player_quests_finished # support for betterquesting
mc_custom # for 1.15 mc_custom # for 1.15
``` ```
the following Metrics are only exported if RCON is configured:
The following Metrics are only exported if RCON is configured:
``` ```
dim_tps dim_tps
dim_ticktime dim_ticktime
@ -68,7 +85,7 @@ overall_ticktime
player_online player_online
``` ```
the following Metrics are exposed if Dynmap Support is enabled: The following Metrics are exposed if Dynmap Support is enabled:
``` ```
dynmap_tile_render_statistics dynmap_tile_render_statistics
@ -76,7 +93,7 @@ dynmap_chunk_loading_statistics_count
dynmap_chunk_loading_statistics_duration dynmap_chunk_loading_statistics_duration
``` ```
the following Metrics are exposed if PAPER_SERVER is enabled: The following Metrics are exposed if PAPER_SERVER is enabled:
``` ```
tps_1m tps_1m
tps_5m tps_5m

View file

@ -1,7 +1,8 @@
version: '3.1' version: '3.1'
services: services:
minecraft-exporter: minecraft-exporter:
image: 'joshi425/minecraft_exporter' build:
context: .
environment: environment:
RCON_HOST: RCON_HOST:
RCON_PORT: RCON_PORT:
@ -9,4 +10,4 @@ services:
ports: ports:
- 9700:8000 - 9700:8000
volumes: volumes:
- /path/to/minecraft/world:/world:ro - ./world:/world:ro

View file

@ -0,0 +1,70 @@
{
"_comment": "DO NOT EDIT: FILE GENERATED AUTOMATICALLY BY PTERODACTYL PANEL - PTERODACTYL.IO",
"meta": {
"version": "PTDL_v1",
"update_url": null
},
"exported_at": "2022-02-21T08:57:54+00:00",
"name": "Minecraft Prom Exporter",
"author": "jack.stupple@protonmail.com",
"description": "Minecraft Prom Exporter",
"features": null,
"images": [
"joshi425\/minecraft_exporter",
"ghcr.io\/joshi425\/minecraft-exporter:latest",
"ghcr.io\/surdaft\/minecraft-exporter:latest"
],
"file_denylist": [],
"startup": "python3 minecraft_exporter.py",
"config": {
"files": "{}",
"startup": "{\r\n \"done\": \"Exporter started on Port\"\r\n}",
"logs": "{}",
"stop": "^C"
},
"scripts": {
"installation": {
"script": null,
"container": "alpine:3.4",
"entrypoint": "ash"
}
},
"variables": [
{
"name": "RCON Host",
"description": "Host of the minecraft server",
"env_variable": "RCON_HOST",
"default_value": "host.docker.internal",
"user_viewable": false,
"user_editable": false,
"rules": "string|max:32"
},
{
"name": "RCON Port",
"description": "Port of minecraft server RCON",
"env_variable": "RCON_PORT",
"default_value": "25575",
"user_viewable": false,
"user_editable": false,
"rules": "numeric|min:0|max:35000"
},
{
"name": "RCON Password",
"description": "Password for minecraft server RCON",
"env_variable": "RCON_PASSWORD",
"default_value": "",
"user_viewable": false,
"user_editable": false,
"rules": "string|min:0"
},
{
"name": "HTTP Port",
"description": "Port to host metric server on",
"env_variable": "HTTP_PORT",
"default_value": "8000",
"user_viewable": false,
"user_editable": false,
"rules": "numeric|min:0|max:35000"
}
]
}

View file

@ -322,9 +322,11 @@ class MinecraftCollector(object):
elif stat == "minecraft:damage_taken": elif stat == "minecraft:damage_taken":
damage_taken.add_sample('damage_taken', value=value, labels={'player': name}) damage_taken.add_sample('damage_taken', value=value, labels={'player': name})
elif stat == "minecraft:damage_dealt": elif stat == "minecraft:damage_dealt":
damage_dealt.add_sample('damage_dealt', value=value, labels={'player': name}) damage_dealt.add_sample('damage_dealt',value=value,labels={'player':name})
elif stat == "minecraft:play_one_minute": elif stat == "minecraft:play_time":
player_playtime.add_sample('player_playtime', value=value, labels={'player': name}) player_playtime.add_sample('player_playtime',value=value,labels={'player':name})
elif stat == "minecraft:play_one_minute": # pre 1.17
player_playtime.add_sample('player_playtime',value=value,labels={'player':name})
elif stat == "minecraft:walk_one_cm": elif stat == "minecraft:walk_one_cm":
cm_traveled.add_sample("cm_traveled", value=value, labels={'player': name, 'method': "walking"}) cm_traveled.add_sample("cm_traveled", value=value, labels={'player': name, 'method': "walking"})
elif stat == "minecraft:walk_on_water_one_cm": elif stat == "minecraft:walk_on_water_one_cm":
@ -368,11 +370,15 @@ class MinecraftCollector(object):
yield metric yield metric
if __name__ == '__main__': HTTP_PORT = int(os.environ.get('HTTP_PORT'))
collector = MinecraftCollector() if HTTP_PORT == None:
start_http_server(8000) HTTP_PORT = 8000
REGISTRY.register(collector)
print("Exporter started on Port 8000") start_http_server(HTTP_PORT)
REGISTRY.register(MinecraftCollector())
print(f'Exporter started on Port {HTTP_PORT}')
while True: while True:
try: try:
time.sleep(1) time.sleep(1)