Skip to content

Commit

Permalink
Merge pull request #39 from Cubxity/dev/0.3.x
Browse files Browse the repository at this point in the history
UnifiedMetrics 0.3.2
  • Loading branch information
Cubxity authored Oct 5, 2021
2 parents 4c42143 + 2ae8d42 commit 5f92a38
Show file tree
Hide file tree
Showing 32 changed files with 876 additions and 55 deletions.
Binary file added .github/assets/dmc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/assets/grafana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew shadowJar --no-daemon
run: ./gradlew assemble --no-daemon
- name: Set variables
id: vars
run: echo ::set-output name=version::${GITHUB_REF#refs/*\/dev/}
Expand All @@ -29,4 +29,4 @@ jobs:
title: "Development Build (${{ steps.vars.outputs.version }})"
files: |
api/build/libs/*.jar
platforms/*/build/libs/*.jar
platforms/*/build/libs/*(.jar|!(*-dev.jar))
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew shadowJar --no-daemon
run: ./gradlew assemble --no-daemon
- name: Set variables
id: vars
run: echo ::set-output name=version::${GITHUB_REF#refs/tags/v}
Expand All @@ -28,4 +28,4 @@ jobs:
title: "UnifiedMetrics ${{ steps.vars.outputs.version }}"
files: |
api/build/libs/*.jar
platforms/*/build/libs/*.jar
platforms/*/build/libs/*(.jar|!(*-dev.jar))
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ UnifiedMetrics is a fully-featured free and open-source metrics collection plugi
licensed under [GNU LGPLv3](COPYING.LESSER).

![Grafana Dashboard](.github/assets/grafana.png)
<p align="center">
<a href="https://snapshot.raintank.io/dashboard/snapshot/i0Btqtz01e4DkmW3N89y61wc5tIMJZKm">
Click here for preview!
</a>
</p>
*This is a custom-made dashboard, which is not public, yet.*

## Features

Expand All @@ -28,6 +24,7 @@ licensed under [GNU LGPLv3](COPYING.LESSER).
**Server:**

- 1.8+ Spigot servers *(includes Spigot-based forks)*
- 1.16+ Fabric servers
- Minestom
- Velocity
- BungeeCord
Expand Down Expand Up @@ -90,13 +87,13 @@ $ git clone https://github.com/Cubxity/UnifiedMetrics && cd UnifiedMetrics
Open a terminal in the cloned directory and run the following command. The following command will build all subprojects.

```bash
$ ./gradlew shadowJar
$ ./gradlew assemble
```

To build a specific subproject, you can prefix it with the subproject path. For example:

```bash
$ `./gradlew :unifiedmetrics-platform-bukkit:shadowJar`
$ `./gradlew :unifiedmetrics-platform-bukkit:assemble`
```

The output artifacts can be found in `subproject/build/libs`.
Expand All @@ -115,6 +112,10 @@ val api = UnifiedMetricsProvider.get()

## Special Thanks

UnifiedMetrics is a proud partner of DedicatedMC! Get your Raw Power Hosting today with **15% OFF** using code `UnifiedMetrics`!

[![DedicatedMC Logo](.github/assets/dmc.png)](https://dedimc.promo/UnifiedMetrics)

YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET
applications. YourKit is the creator of [YourKit Java Profiler](https://www.yourkit.com/java/profiler/),
[YourKit .NET Profiler](https://www.yourkit.com/.net/profiler/),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package dev.cubxity.plugins.metrics.api.metric.collector

import dev.cubxity.plugins.metrics.api.metric.data.Metric

const val NANOSECONDS_PER_MILLISECOND: Double = 1E6
const val NANOSECONDS_PER_SECOND: Double = 1E9
const val MILLISECONDS_PER_SECOND: Double = 1E3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sealed class PlatformType(val name: String) {
// Server implementations
object Bukkit : PlatformType("Bukkit")
object Minestom : PlatformType("Minestom")
object Fabric : PlatformType("Fabric")

// Proxies
object Velocity : PlatformType("Velocity")
Expand Down
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ plugins {
allprojects {
group = "dev.cubxity.plugins"
description = "Fully featured metrics collector agent for Minecraft servers."
version = "0.3.1"
version = "0.3.2"

repositories {
mavenCentral()
Expand All @@ -45,4 +45,9 @@ subprojects {
freeCompilerArgs = listOf("-Xopt-in=kotlin.RequiresOptIn")
}
}
afterEvaluate {
tasks.findByName("shadowJar")?.also {
tasks.named("assemble") { dependsOn(it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,30 @@ enum class PrometheusMode {
@Serializable
data class PrometheusHttpConfig(
val host: String = "0.0.0.0",
val port: Int = 9100
val port: Int = 9100,
val authentication: AuthenticationConfig = AuthenticationConfig()
)

@Serializable
data class PushGatewayConfig(
val job: String = "unifiedmetrics",
val url: String = "http://pushgateway:9091",
val authentication: PushGatewayAuthenticationConfig = PushGatewayAuthenticationConfig(),
val authentication: AuthenticationConfig = AuthenticationConfig(),
val interval: Long = 10
)

@Serializable
data class PushGatewayAuthenticationConfig(
val scheme: PushGatewayAuthenticationScheme = PushGatewayAuthenticationScheme.Basic,
val username: String = "username",
val password: String = "password"
)

@Serializable
enum class PushGatewayAuthenticationScheme {
enum class AuthenticationScheme {
@SerialName("NONE")
None,

@SerialName("BASIC")
Basic
}
}

@Serializable
data class AuthenticationConfig(
val scheme: AuthenticationScheme = AuthenticationScheme.None,
val username: String = "username",
val password: String = "password"
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,48 @@

package dev.cubxity.plugins.metrics.prometheus.exporter

import com.sun.net.httpserver.BasicAuthenticator
import dev.cubxity.plugins.metrics.api.UnifiedMetrics
import dev.cubxity.plugins.metrics.prometheus.PrometheusMetricsDriver
import dev.cubxity.plugins.metrics.prometheus.collector.UnifiedMetricsCollector
import dev.cubxity.plugins.metrics.prometheus.config.AuthenticationScheme
import io.prometheus.client.CollectorRegistry
import io.prometheus.client.exporter.HTTPServer
import java.net.InetSocketAddress

class PrometheusHTTPExporter(private val api: UnifiedMetrics, private val driver: PrometheusMetricsDriver) : PrometheusExporter {
class PrometheusHTTPExporter(
private val api: UnifiedMetrics,
private val driver: PrometheusMetricsDriver
) : PrometheusExporter {
private var server: HTTPServer? = null

override fun initialize() {
val registry = CollectorRegistry()
registry.register(UnifiedMetricsCollector(api))

server = HTTPServer(InetSocketAddress(driver.config.http.host, driver.config.http.port), registry)
server = HTTPServer.Builder()
.withHostname(driver.config.http.host)
.withPort(driver.config.http.port)
.withRegistry(registry)
.apply {
with(driver.config.http.authentication) {
if (scheme == AuthenticationScheme.Basic) {
withAuthenticator(Authenticator(username, password))
}
}
}
.build()
}

override fun close() {
server?.close()
server = null
}

private class Authenticator(
private val username: String,
private val password: String
) : BasicAuthenticator("unifiedmetrics") {
override fun checkCredentials(username: String?, password: String?): Boolean =
this.username == username && this.password == password
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package dev.cubxity.plugins.metrics.prometheus.exporter
import dev.cubxity.plugins.metrics.api.UnifiedMetrics
import dev.cubxity.plugins.metrics.prometheus.PrometheusMetricsDriver
import dev.cubxity.plugins.metrics.prometheus.collector.MetricSamplesCollection
import dev.cubxity.plugins.metrics.prometheus.config.PushGatewayAuthenticationScheme
import dev.cubxity.plugins.metrics.prometheus.config.AuthenticationScheme
import io.prometheus.client.exporter.BasicAuthHttpConnectionFactory
import io.prometheus.client.exporter.PushGateway
import kotlinx.coroutines.*
Expand All @@ -42,7 +42,7 @@ class PushGatewayExporter(

gateway = PushGateway(URL(config.url)).apply {
with(config.authentication) {
if (scheme == PushGatewayAuthenticationScheme.Basic) {
if (scheme == AuthenticationScheme.Basic) {
setConnectionFactory(BasicAuthHttpConnectionFactory(username, password))
}
}
Expand Down
96 changes: 96 additions & 0 deletions platforms/fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* This file is part of UnifiedMetrics.
*
* UnifiedMetrics is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* UnifiedMetrics 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with UnifiedMetrics. If not, see <https://www.gnu.org/licenses/>.
*/

plugins {
id("fabric-loom") version "0.9.9"
id("net.kyori.blossom")
}

dependencies {
// https://fabricmc.net/versions.html
minecraft("com.mojang:minecraft:1.17.1")
mappings("net.fabricmc:yarn:1.17.1+build.61:v2")
modImplementation("net.fabricmc:fabric-loader:0.11.7")

modImplementation("net.fabricmc.fabric-api:fabric-api:0.40.1+1.17")
modImplementation("net.fabricmc:fabric-language-kotlin:1.6.5+kotlin.1.5.31")

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

include(project(":unifiedmetrics-core"))
include(project(":unifiedmetrics-common"))
include("com.charleskorn.kaml:kaml:0.36.0")
include("com.charleskorn.kaml:kaml-jvm:0.36.0")
include("org.snakeyaml:snakeyaml-engine:2.3")
include(project(":unifiedmetrics-api"))
include(project(":unifiedmetrics-driver-influx"))
include("com.influxdb:influxdb-client-java:3.3.0")
include("com.influxdb:influxdb-client-core:3.3.0")
include("com.influxdb:influxdb-client-utils:3.3.0")
include("com.google.code.findbugs:jsr305:3.0.2")
include("com.squareup.retrofit2:retrofit:2.9.0")
include("com.squareup.okhttp3:okhttp:4.7.2")
include("com.squareup.okio:okio:2.6.0")
include("com.squareup.okhttp3:logging-interceptor:4.7.2")
include("org.apache.commons:commons-csv:1.8")
include("io.reactivex.rxjava2:rxjava:2.2.19")
include("org.reactivestreams:reactive-streams:1.0.3")
include("io.swagger:swagger-annotations:1.6.1")
include("io.gsonfire:gson-fire:1.8.4")
include("com.squareup.retrofit2:converter-scalars:2.9.0")
include("com.squareup.retrofit2:converter-gson:2.9.0")
include(project(":unifiedmetrics-driver-prometheus"))
include("io.prometheus:simpleclient_httpserver:0.12.0")
include("io.prometheus:simpleclient:0.12.0")
include("io.prometheus:simpleclient_tracer_otel:0.12.0")
include("io.prometheus:simpleclient_tracer_common:0.12.0")
include("io.prometheus:simpleclient_tracer_otel_agent:0.12.0")
include("io.prometheus:simpleclient_common:0.12.0")
include("io.prometheus:simpleclient_pushgateway:0.12.0")
}

loom {
runs {
named("server") {
isIdeConfigGenerated = true
}
}
}

tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}

processResources {
inputs.property("version", project.version)

filesMatching("fabric.mod.json") {
expand("version" to project.version)
}
}

compileJava {
options.encoding = "UTF-8"
options.release.set(8)
}
}

blossom {
replaceTokenIn("src/main/kotlin/dev/cubxity/plugins/metrics/fabric/bootstrap/UnifiedMetricsFabricBootstrap.kt")
replaceToken("@version@", version)
}
Loading

0 comments on commit 5f92a38

Please sign in to comment.