Skip to content

Commit

Permalink
feat: added support for BungeeCord
Browse files Browse the repository at this point in the history
  • Loading branch information
Cubxity committed Jun 23, 2021
1 parent 70a4181 commit 1d8b331
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ package dev.cubxity.plugins.metrics.api.platform
sealed class PlatformType(val name: String) {
object Bukkit : PlatformType("Bukkit")
object Velocity : PlatformType("Velocity")
object BungeeCord : PlatformType("BungeeCord")
}
45 changes: 45 additions & 0 deletions bungee/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers.
* Copyright (C) 2021 Cubxity
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

plugins {
id("com.github.johnrengelman.shadow")
}

repositories {
maven("https://oss.sonatype.org/content/repositories/snapshots/")
}

dependencies {
api(project(":unifiedmetrics-core"))

compileOnly("net.md-5", "bungeecord-api", "1.17-R0.1-SNAPSHOT")
}

tasks {
shadowJar {
archiveClassifier.set("")
}
processResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE

from("src/main/resources") {
expand("version" to version)
include("plugin.yml")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers.
* Copyright (C) 2021 Cubxity
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.bungee

import dev.cubxity.plugins.metrics.api.UnifiedMetrics
import dev.cubxity.plugins.metrics.bungee.bootstrap.UnifiedMetricsBungeeBootstrap
import dev.cubxity.plugins.metrics.bungee.metric.EventsMetric
import dev.cubxity.plugins.metrics.bungee.metric.server.ServerMetric
import dev.cubxity.plugins.metrics.core.plugin.CoreUnifiedMetricsPlugin

class UnifiedMetricsBungeePlugin(
override val bootstrap: UnifiedMetricsBungeeBootstrap
) : CoreUnifiedMetricsPlugin() {
override fun registerPlatformService(api: UnifiedMetrics) {
// Bungee doesn't have a service manager
}

override fun registerPlatformMetrics() {
super.registerPlatformMetrics()

apiProvider.metricsManager.apply {
with(config.metrics.collectors) {
if (server) registerMetric(ServerMetric(bootstrap))
if (events) registerMetric(EventsMetric(bootstrap))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers.
* Copyright (C) 2021 Cubxity
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.bungee.bootstrap

import dev.cubxity.plugins.metrics.api.platform.PlatformType
import dev.cubxity.plugins.metrics.bungee.UnifiedMetricsBungeePlugin
import dev.cubxity.plugins.metrics.common.UnifiedMetricsBootstrap
import dev.cubxity.plugins.metrics.common.plugin.dispatcher.CurrentThreadDispatcher
import dev.cubxity.plugins.metrics.common.plugin.logger.JavaLogger
import kotlinx.coroutines.CoroutineDispatcher
import net.md_5.bungee.api.plugin.Plugin
import java.nio.file.Path

class UnifiedMetricsBungeeBootstrap : Plugin(), UnifiedMetricsBootstrap {
private val plugin = UnifiedMetricsBungeePlugin(this)

override val type: PlatformType
get() = PlatformType.BungeeCord

override val version: String
get() = description.version

override val serverBrand: String
get() = proxy.name

override val dataDirectory: Path
get() = dataFolder.toPath()

override val configDirectory: Path
get() = dataFolder.toPath()

override val logger = JavaLogger(getLogger())

override val dispatcher: CoroutineDispatcher = CurrentThreadDispatcher

override fun onEnable() {
plugin.enable()
}

override fun onDisable() {
plugin.disable()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers.
* Copyright (C) 2021 Cubxity
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.bungee.metric

import dev.cubxity.plugins.metrics.api.metric.Metric
import dev.cubxity.plugins.metrics.api.metric.collector.Counter
import dev.cubxity.plugins.metrics.api.metric.collector.MetricCollector
import dev.cubxity.plugins.metrics.bungee.bootstrap.UnifiedMetricsBungeeBootstrap
import net.md_5.bungee.api.event.ChatEvent
import net.md_5.bungee.api.event.PlayerDisconnectEvent
import net.md_5.bungee.api.event.PostLoginEvent
import net.md_5.bungee.api.event.ProxyPingEvent
import net.md_5.bungee.api.plugin.Listener
import net.md_5.bungee.event.EventHandler

@Suppress("UNUSED_PARAMETER")
class EventsMetric(private val bootstrap: UnifiedMetricsBungeeBootstrap) : Metric, Listener {
private val joinCounter = Counter("minecraft_events_join_total")
private val quitCounter = Counter("minecraft_events_quit_total")
private val chatCounter = Counter("minecraft_events_chat_total")
private val pingCounter = Counter("minecraft_events_ping_total")

override val collectors: List<MetricCollector> =
listOf(joinCounter, quitCounter, chatCounter, pingCounter)

override fun initialize() {
bootstrap.proxy.pluginManager.registerListener(bootstrap, this)
}

override fun dispose() {
bootstrap.proxy.pluginManager.unregisterListener(this)
}

@EventHandler
fun onJoin(event: PostLoginEvent) {
joinCounter.inc()
}

@EventHandler
fun onQuit(event: PlayerDisconnectEvent) {
quitCounter.inc()
}

@EventHandler
fun onChat(event: ChatEvent) {
chatCounter.inc()
}

@EventHandler
fun onPing(event: ProxyPingEvent) {
pingCounter.inc()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers.
* Copyright (C) 2021 Cubxity
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.bungee.metric.server

import dev.cubxity.plugins.metrics.api.metric.collector.MetricCollector
import dev.cubxity.plugins.metrics.api.metric.data.GaugeSample
import dev.cubxity.plugins.metrics.api.metric.data.MetricSample
import dev.cubxity.plugins.metrics.bungee.bootstrap.UnifiedMetricsBungeeBootstrap

class ServerCollector(private val bootstrap: UnifiedMetricsBungeeBootstrap) : MetricCollector {
override fun collect(): List<MetricSample> {
val proxy = bootstrap.proxy
return listOf(
GaugeSample("minecraft_plugins", proxy.pluginManager.plugins.size),
GaugeSample("minecraft_players_count", proxy.onlineCount),
GaugeSample("minecraft_players_max", proxy.config.playerLimit)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers.
* Copyright (C) 2021 Cubxity
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.bungee.metric.server

import dev.cubxity.plugins.metrics.api.metric.Metric
import dev.cubxity.plugins.metrics.api.metric.collector.MetricCollector
import dev.cubxity.plugins.metrics.bungee.bootstrap.UnifiedMetricsBungeeBootstrap

class ServerMetric(bootstrap: UnifiedMetricsBungeeBootstrap) : Metric {
override val collectors: List<MetricCollector> = listOf(ServerCollector(bootstrap))
}
5 changes: 5 additions & 0 deletions bungee/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: UnifiedMetrics
main: dev.cubxity.plugins.metrics.bungee.bootstrap.UnifiedMetricsBungeeBootstrap
description: "Fully-featured metrics plugin for Minecraft servers"
author: Cubxity
version: ${version}
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ include(modulePrefix + "common")
include(modulePrefix + "core")
include(modulePrefix + "bukkit")
include(modulePrefix + "velocity")
include(modulePrefix + "bungee")

include(modulePrefix + "influx-driver")
include(modulePrefix + "prometheus-driver")
Expand All @@ -34,6 +35,7 @@ project(modulePrefix + "common").projectDir = File(rootDir, "common")
project(modulePrefix + "core").projectDir = File(rootDir, "core")
project(modulePrefix + "bukkit").projectDir = File(rootDir, "bukkit")
project(modulePrefix + "velocity").projectDir = File(rootDir, "velocity")
project(modulePrefix + "bungee").projectDir = File(rootDir, "bungee")

val driversDir = File(rootDir, "drivers")
project(modulePrefix + "influx-driver").projectDir = File(driversDir, "influx")
Expand Down

0 comments on commit 1d8b331

Please sign in to comment.