bundles/minecraft: add monitoring via telegraf

This commit is contained in:
Franzi 2022-11-13 17:47:19 +01:00
parent cb1222600d
commit 019d5ce2b6
Signed by: kunsi
GPG key ID: 12E3D2136B818350
3 changed files with 87 additions and 3 deletions

View file

@ -1,5 +1,8 @@
from json import dumps from json import dumps
JOLOKIA_VERSION = '1.7.1'
JOLOKIA_SHA1 = 'd9cf8215598480c98c03a2409344aba20d29884b'
java_opts = set() java_opts = set()
for k, v in node.metadata.get('minecraft/java_opts').items(): 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: else:
java_opts.add(f'{k}={v}') java_opts.add(f'{k}={v}')
# World
directories['/home/minecraft/world'] = { directories['/home/minecraft/world'] = {
'owner': 'minecraft', 'owner': 'minecraft',
'group': 'minecraft', 'group': 'minecraft',
@ -23,6 +27,7 @@ directories['/home/minecraft/world_the_end'] = {
'group': 'minecraft', 'group': 'minecraft',
} }
# The actual server
files['/usr/local/lib/systemd/system/minecraft.service'] = { files['/usr/local/lib/systemd/system/minecraft.service'] = {
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
@ -41,6 +46,9 @@ files['/home/minecraft/eula.txt'] = {
files['/home/minecraft/server.properties'] = { files['/home/minecraft/server.properties'] = {
# get it from data/minecraft/files/{node.name} # get it from data/minecraft/files/{node.name}
'source': node.name, 'source': node.name,
'triggers': {
'svc_systemd:minecraft:restart',
},
} }
version, build_nr = node.metadata.get('minecraft/version') version, build_nr = node.metadata.get('minecraft/version')
@ -49,6 +57,9 @@ files['/home/minecraft/minecraft_server.jar'] = {
'content_type': 'download', 'content_type': 'download',
'source': f'https://api.papermc.io/v2/projects/paper/versions/{version}/builds/{build_nr}/downloads/paper-{version}-{build_nr}.jar', '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), 'content_hash': node.metadata.get('minecraft/sha1', None),
'triggers': {
'svc_systemd:minecraft:restart',
},
} }
svc_systemd['minecraft'] = { svc_systemd['minecraft'] = {
@ -64,6 +75,7 @@ svc_systemd['minecraft'] = {
}, },
} }
# Permissions
files['/home/minecraft/ops.json'] = { files['/home/minecraft/ops.json'] = {
'content': dumps( 'content': dumps(
[ [
@ -74,7 +86,10 @@ files['/home/minecraft/ops.json'] = {
} for name, uuid in sorted(node.metadata.get('minecraft/ops', {}).items()) } for name, uuid in sorted(node.metadata.get('minecraft/ops', {}).items())
], ],
indent=4, indent=4,
) ),
'triggers': {
'svc_systemd:minecraft:restart',
},
} }
if node.metadata.get('minecraft/allowlist', {}): 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()) } for name, uuid in sorted(node.metadata.get('minecraft/allowlist').items())
], ],
indent=4, 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',
},
}

View file

@ -33,6 +33,62 @@ defaults = {
'-XX:MaxGCPauseMillis': 200, '-XX:MaxGCPauseMillis': 200,
'-XX:MaxTenuringThreshold': 1, '-XX:MaxTenuringThreshold': 1,
'-XX:SurvivorRatio': 32, '-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': { 'users': {

View file

@ -7,7 +7,7 @@ broadcast-rcon-to-ops=true
debug=false debug=false
difficulty=easy difficulty=easy
enable-command-block=false enable-command-block=false
enable-jmx-monitoring=false enable-jmx-monitoring=true
enable-query=false enable-query=false
enable-rcon=true enable-rcon=true
enable-status=true enable-status=true