From f3bcbbd6ba8b904fe6d5b6bf7cda60d9d2f18b50 Mon Sep 17 00:00:00 2001 From: SurDaft - Jack Stupple Date: Sun, 6 Feb 2022 00:57:23 +0000 Subject: [PATCH 01/11] Rename stat (since 1.17) --- minecraft_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index c768ea0..5459c00 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -271,7 +271,7 @@ class MinecraftCollector(object): damage_taken.add_sample('damage_taken',value=value,labels={'player':name}) elif stat == "minecraft:damage_dealt": 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}) elif stat == "minecraft:walk_one_cm": cm_traveled.add_sample("cm_traveled",value=value,labels={'player':name,'method':"walking"}) From ebc51821696f2b68af668a4911ae3ea2dfe52694 Mon Sep 17 00:00:00 2001 From: Jack Stupple Date: Sun, 20 Feb 2022 13:00:55 +0000 Subject: [PATCH 02/11] Implement HTTP_PORT environment variable --- minecraft_exporter.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index c768ea0..64101da 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -314,9 +314,15 @@ if __name__ == '__main__': if all(x in os.environ for x in ['RCON_HOST','RCON_PASSWORD']): print("RCON is enabled for "+ os.environ['RCON_HOST']) - start_http_server(8000) + HTTP_PORT = os.environ.get('HTTP_PORT') + if HTTP_PORT == None: + HTTP_PORT = 8000 + + start_http_server(HTTP_PORT) REGISTRY.register(MinecraftCollector()) - print("Exporter started on Port 8000") + + print(f'Exporter started on Port {HTTP_PORT}') + while True: time.sleep(1) schedule.run_pending() From 55acfc182dd80d6e3ea5f9392aad4c948652687b Mon Sep 17 00:00:00 2001 From: SurDaft - Jack Stupple Date: Sun, 20 Feb 2022 13:40:59 +0000 Subject: [PATCH 03/11] Create docker-image.yml --- .github/workflows/docker-image.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..077ed68 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,26 @@ +name: Docker Image CI + +on: + workflow_dispatch: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - 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 From c56894ca12ca9e769626785dc69f885cab165328 Mon Sep 17 00:00:00 2001 From: Jack Stupple Date: Mon, 21 Feb 2022 08:06:39 +0000 Subject: [PATCH 04/11] Ignore test world --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c1bada --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# for testing +world From dc6be5857b4664baafae0ed92ab8f3fac01c6a7a Mon Sep 17 00:00:00 2001 From: Jack Stupple Date: Mon, 21 Feb 2022 08:08:34 +0000 Subject: [PATCH 05/11] Ensure docker file uses context of the current source application --- docker-compose.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index cb439b4..a7b1c74 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,8 @@ version: '3.1' services: minecraft-exporter: - image: 'joshi425/minecraft_exporter' + build: + context: . environment: RCON_HOST: RCON_PORT: @@ -9,4 +10,4 @@ services: ports: - 9700:8000 volumes: - - /path/to/minecraft/world:/world:ro + - ./world:/world:ro From a8f5554608f82abeef4a4b126c8eade9bdb2191e Mon Sep 17 00:00:00 2001 From: Jack Stupple Date: Mon, 21 Feb 2022 08:11:40 +0000 Subject: [PATCH 06/11] Add examples checkout master uses --- .github/workflows/docker-image.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 077ed68..01c9646 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -14,6 +14,7 @@ jobs: 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 From 5caee9673604664c5489952a0a041f16b28aefa2 Mon Sep 17 00:00:00 2001 From: Jack Stupple Date: Mon, 21 Feb 2022 08:20:29 +0000 Subject: [PATCH 07/11] Update README --- README.md | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f878fa5..d21568e 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,16 @@ # 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. -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 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 @@ -18,8 +19,22 @@ rcon.password=Password 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 @@ -59,7 +74,9 @@ player_used_crafting_table player_quests_finished # support for betterquesting 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_ticktime @@ -68,7 +85,7 @@ overall_ticktime 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 @@ -76,7 +93,7 @@ dynmap_chunk_loading_statistics_count 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_5m From 8ad70b028b5797d3153a224c0b00dff274c9ccd9 Mon Sep 17 00:00:00 2001 From: Jack Stupple Date: Mon, 21 Feb 2022 08:24:49 +0000 Subject: [PATCH 08/11] Fix env being a string --- minecraft_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index 0a4b687..259507b 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -314,7 +314,7 @@ if __name__ == '__main__': if all(x in os.environ for x in ['RCON_HOST','RCON_PASSWORD']): print("RCON is enabled for "+ os.environ['RCON_HOST']) - HTTP_PORT = os.environ.get('HTTP_PORT') + HTTP_PORT = int(os.environ.get('HTTP_PORT')) if HTTP_PORT == None: HTTP_PORT = 8000 From ccb72d660cd040fb8b86c21a2b776cf1c99dec4a Mon Sep 17 00:00:00 2001 From: Jack Stupple Date: Mon, 21 Feb 2022 08:59:36 +0000 Subject: [PATCH 09/11] Add pterodactyl egg config --- egg-minecraft-prom-exporter.json | 70 ++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 egg-minecraft-prom-exporter.json diff --git a/egg-minecraft-prom-exporter.json b/egg-minecraft-prom-exporter.json new file mode 100644 index 0000000..6f80e55 --- /dev/null +++ b/egg-minecraft-prom-exporter.json @@ -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\": \"Startup complete\"\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" + } + ] +} \ No newline at end of file From 14d2739c342d0ad7fc8432766ba2042a307c299d Mon Sep 17 00:00:00 2001 From: Jack Stupple Date: Mon, 21 Feb 2022 09:02:05 +0000 Subject: [PATCH 10/11] Reimplement pre 1.17 --- minecraft_exporter.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index 259507b..cbf5602 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -273,6 +273,8 @@ class MinecraftCollector(object): damage_dealt.add_sample('damage_dealt',value=value,labels={'player':name}) elif stat == "minecraft:play_time": 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": cm_traveled.add_sample("cm_traveled",value=value,labels={'player':name,'method':"walking"}) elif stat == "minecraft:walk_on_water_one_cm": From ef2be87e09597669a899cb963b679612e189a095 Mon Sep 17 00:00:00 2001 From: Jack Stupple Date: Tue, 22 Feb 2022 19:27:06 +0000 Subject: [PATCH 11/11] Correct typo in egg config --- egg-minecraft-prom-exporter.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/egg-minecraft-prom-exporter.json b/egg-minecraft-prom-exporter.json index 6f80e55..3db4a8f 100644 --- a/egg-minecraft-prom-exporter.json +++ b/egg-minecraft-prom-exporter.json @@ -18,7 +18,7 @@ "startup": "python3 minecraft_exporter.py", "config": { "files": "{}", - "startup": "{\r\n \"done\": \"Startup complete\"\r\n}", + "startup": "{\r\n \"done\": \"Exporter started on Port\"\r\n}", "logs": "{}", "stop": "^C" }, @@ -67,4 +67,4 @@ "rules": "numeric|min:0|max:35000" } ] -} \ No newline at end of file +}