diff --git a/bundles/minecraft/items.py b/bundles/minecraft/items.py index 6f64243..9ad683b 100644 --- a/bundles/minecraft/items.py +++ b/bundles/minecraft/items.py @@ -1,5 +1,8 @@ from json import dumps +JOLOKIA_VERSION = '1.7.1' +JOLOKIA_SHA1 = 'd9cf8215598480c98c03a2409344aba20d29884b' + java_opts = set() for k, v in node.metadata.get('minecraft/java_opts').items(): @@ -8,6 +11,7 @@ for k, v in node.metadata.get('minecraft/java_opts').items(): else: java_opts.add(f'{k}={v}') +# World directories['/home/minecraft/world'] = { 'owner': 'minecraft', 'group': 'minecraft', @@ -23,6 +27,7 @@ directories['/home/minecraft/world_the_end'] = { 'group': 'minecraft', } +# The actual server files['/usr/local/lib/systemd/system/minecraft.service'] = { 'content_type': 'mako', 'context': { @@ -41,6 +46,9 @@ files['/home/minecraft/eula.txt'] = { files['/home/minecraft/server.properties'] = { # get it from data/minecraft/files/{node.name} 'source': node.name, + 'triggers': { + 'svc_systemd:minecraft:restart', + }, } version, build_nr = node.metadata.get('minecraft/version') @@ -49,6 +57,9 @@ files['/home/minecraft/minecraft_server.jar'] = { 'content_type': 'download', 'source': f'https://api.papermc.io/v2/projects/paper/versions/{version}/builds/{build_nr}/downloads/paper-{version}-{build_nr}.jar', 'content_hash': node.metadata.get('minecraft/sha1', None), + 'triggers': { + 'svc_systemd:minecraft:restart', + }, } svc_systemd['minecraft'] = { @@ -64,6 +75,7 @@ svc_systemd['minecraft'] = { }, } +# Permissions files['/home/minecraft/ops.json'] = { 'content': dumps( [ @@ -74,7 +86,10 @@ files['/home/minecraft/ops.json'] = { } for name, uuid in sorted(node.metadata.get('minecraft/ops', {}).items()) ], indent=4, - ) + ), + 'triggers': { + 'svc_systemd:minecraft:restart', + }, } if node.metadata.get('minecraft/allowlist', {}): @@ -87,5 +102,18 @@ if node.metadata.get('minecraft/allowlist', {}): } for name, uuid in sorted(node.metadata.get('minecraft/allowlist').items()) ], indent=4, - ) + ), + 'triggers': { + 'svc_systemd:minecraft:restart', + }, } + +# Monitoring +files['/home/minecraft/jolokia.jar'] = { + 'source': f'https://search.maven.org/remotecontent?filepath=org/jolokia/jolokia-jvm/{JOLOKIA_VERSION}/jolokia-jvm-{JOLOKIA_VERSION}.jar', + 'content_type': 'download', + 'content_hash': JOLOKIA_SHA1, + 'triggers': { + 'svc_systemd:minecraft:restart', + }, +} diff --git a/bundles/minecraft/metadata.py b/bundles/minecraft/metadata.py index f207e45..c4aa372 100644 --- a/bundles/minecraft/metadata.py +++ b/bundles/minecraft/metadata.py @@ -33,6 +33,62 @@ defaults = { '-XX:MaxGCPauseMillis': 200, '-XX:MaxTenuringThreshold': 1, '-XX:SurvivorRatio': 32, + '-javaagent:/home/minecraft/jolokia.jar=port=25576,host=localhost': None, + }, + }, + 'telegraf': { + 'input_plugins': { + 'builtin': { + 'jolokia2_agent': [{ + 'urls': ['http://localhost:25576/jolokia'], + 'metric': [ + { + 'name': 'minecraft_tick', + 'mbean': 'net.minecraft.server:type=Server', + 'paths': [ + 'averageTickTime', + ], + }, + { + 'name': 'minecraft_memory', + 'mbean': 'java.lang:type=Memory', + 'paths': [ + 'HeapMemoryUsage', + 'NonHeapMemoryUsage', + 'ObjectPendingFinalizationCount', + ], + }, + { + 'name': 'minecraft_gc', + 'mbean': 'java.lang:name=*,type=GarbageCollector', + 'paths': [ + 'CollectionTime', + 'CollectionCount', + ], + 'tag_keys': ['name'], + }, + { + 'name': 'minecraft_mempool', + 'mbean': 'java.lang:name=*,type=MemoryPool', + 'paths': [ + 'CollectionUsage', + 'PeakUsage', + 'Usage', + ], + 'tag_keys': ['name'], + }, + { + 'name': 'minecraft_os', + 'mbean': 'java.lang:type=OperatingSystem', + 'paths': [ + 'OpenFileDescriptorCount', + 'ProcessCpuLoad', + 'ProcessCpuTime', + ], + }, + ], + }], + }, }, }, 'users': { diff --git a/data/minecraft/files/rx300 b/data/minecraft/files/rx300 index ca39740..19e41fe 100644 --- a/data/minecraft/files/rx300 +++ b/data/minecraft/files/rx300 @@ -7,7 +7,7 @@ broadcast-rcon-to-ops=true debug=false difficulty=easy enable-command-block=false -enable-jmx-monitoring=false +enable-jmx-monitoring=true enable-query=false enable-rcon=true enable-status=true