-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
287 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
bungee/src/main/kotlin/dev/cubxity/plugins/metrics/bungee/UnifiedMetricsBungeePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...main/kotlin/dev/cubxity/plugins/metrics/bungee/bootstrap/UnifiedMetricsBungeeBootstrap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
bungee/src/main/kotlin/dev/cubxity/plugins/metrics/bungee/metric/EventsMetric.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
bungee/src/main/kotlin/dev/cubxity/plugins/metrics/bungee/metric/server/ServerCollector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
bungee/src/main/kotlin/dev/cubxity/plugins/metrics/bungee/metric/server/ServerMetric.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters