Skip to content

Commit 5f92a38

Browse files
authored
Merge pull request #39 from Cubxity/dev/0.3.x
UnifiedMetrics 0.3.2
2 parents 4c42143 + 2ae8d42 commit 5f92a38

File tree

32 files changed

+876
-55
lines changed

32 files changed

+876
-55
lines changed

.github/assets/dmc.png

1.04 MB
Loading

.github/assets/grafana.png

319 KB
Loading

.github/workflows/preview.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Grant execute permission for gradlew
1818
run: chmod +x gradlew
1919
- name: Build with Gradle
20-
run: ./gradlew shadowJar --no-daemon
20+
run: ./gradlew assemble --no-daemon
2121
- name: Set variables
2222
id: vars
2323
run: echo ::set-output name=version::${GITHUB_REF#refs/*\/dev/}
@@ -29,4 +29,4 @@ jobs:
2929
title: "Development Build (${{ steps.vars.outputs.version }})"
3030
files: |
3131
api/build/libs/*.jar
32-
platforms/*/build/libs/*.jar
32+
platforms/*/build/libs/*(.jar|!(*-dev.jar))

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Grant execute permission for gradlew
1818
run: chmod +x gradlew
1919
- name: Build with Gradle
20-
run: ./gradlew shadowJar --no-daemon
20+
run: ./gradlew assemble --no-daemon
2121
- name: Set variables
2222
id: vars
2323
run: echo ::set-output name=version::${GITHUB_REF#refs/tags/v}
@@ -28,4 +28,4 @@ jobs:
2828
title: "UnifiedMetrics ${{ steps.vars.outputs.version }}"
2929
files: |
3030
api/build/libs/*.jar
31-
platforms/*/build/libs/*.jar
31+
platforms/*/build/libs/*(.jar|!(*-dev.jar))

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ UnifiedMetrics is a fully-featured free and open-source metrics collection plugi
99
licensed under [GNU LGPLv3](COPYING.LESSER).
1010

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

1814
## Features
1915

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

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

9289
```bash
93-
$ ./gradlew shadowJar
90+
$ ./gradlew assemble
9491
```
9592

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

9895
```bash
99-
$ `./gradlew :unifiedmetrics-platform-bukkit:shadowJar`
96+
$ `./gradlew :unifiedmetrics-platform-bukkit:assemble`
10097
```
10198

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

116113
## Special Thanks
117114

115+
UnifiedMetrics is a proud partner of DedicatedMC! Get your Raw Power Hosting today with **15% OFF** using code `UnifiedMetrics`!
116+
117+
[![DedicatedMC Logo](.github/assets/dmc.png)](https://dedimc.promo/UnifiedMetrics)
118+
118119
YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET
119120
applications. YourKit is the creator of [YourKit Java Profiler](https://www.yourkit.com/java/profiler/),
120121
[YourKit .NET Profiler](https://www.yourkit.com/.net/profiler/),

api/src/main/kotlin/dev/cubxity/plugins/metrics/api/metric/collector/Collector.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package dev.cubxity.plugins.metrics.api.metric.collector
1919

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

22+
const val NANOSECONDS_PER_MILLISECOND: Double = 1E6
2223
const val NANOSECONDS_PER_SECOND: Double = 1E9
2324
const val MILLISECONDS_PER_SECOND: Double = 1E3
2425

api/src/main/kotlin/dev/cubxity/plugins/metrics/api/platform/PlatformType.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ sealed class PlatformType(val name: String) {
2121
// Server implementations
2222
object Bukkit : PlatformType("Bukkit")
2323
object Minestom : PlatformType("Minestom")
24+
object Fabric : PlatformType("Fabric")
2425

2526
// Proxies
2627
object Velocity : PlatformType("Velocity")

build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ plugins {
2828
allprojects {
2929
group = "dev.cubxity.plugins"
3030
description = "Fully featured metrics collector agent for Minecraft servers."
31-
version = "0.3.1"
31+
version = "0.3.2"
3232

3333
repositories {
3434
mavenCentral()
@@ -45,4 +45,9 @@ subprojects {
4545
freeCompilerArgs = listOf("-Xopt-in=kotlin.RequiresOptIn")
4646
}
4747
}
48+
afterEvaluate {
49+
tasks.findByName("shadowJar")?.also {
50+
tasks.named("assemble") { dependsOn(it) }
51+
}
52+
}
4853
}

drivers/prometheus/src/main/kotlin/dev/cubxity/plugins/metrics/prometheus/config/PrometheusConfig.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,30 @@ enum class PrometheusMode {
3939
@Serializable
4040
data class PrometheusHttpConfig(
4141
val host: String = "0.0.0.0",
42-
val port: Int = 9100
42+
val port: Int = 9100,
43+
val authentication: AuthenticationConfig = AuthenticationConfig()
4344
)
4445

4546
@Serializable
4647
data class PushGatewayConfig(
4748
val job: String = "unifiedmetrics",
4849
val url: String = "http://pushgateway:9091",
49-
val authentication: PushGatewayAuthenticationConfig = PushGatewayAuthenticationConfig(),
50+
val authentication: AuthenticationConfig = AuthenticationConfig(),
5051
val interval: Long = 10
5152
)
5253

5354
@Serializable
54-
data class PushGatewayAuthenticationConfig(
55-
val scheme: PushGatewayAuthenticationScheme = PushGatewayAuthenticationScheme.Basic,
56-
val username: String = "username",
57-
val password: String = "password"
58-
)
59-
60-
@Serializable
61-
enum class PushGatewayAuthenticationScheme {
55+
enum class AuthenticationScheme {
6256
@SerialName("NONE")
6357
None,
6458

6559
@SerialName("BASIC")
6660
Basic
67-
}
61+
}
62+
63+
@Serializable
64+
data class AuthenticationConfig(
65+
val scheme: AuthenticationScheme = AuthenticationScheme.None,
66+
val username: String = "username",
67+
val password: String = "password"
68+
)

drivers/prometheus/src/main/kotlin/dev/cubxity/plugins/metrics/prometheus/exporter/PrometheusHTTPExporter.kt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,48 @@
1717

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

20+
import com.sun.net.httpserver.BasicAuthenticator
2021
import dev.cubxity.plugins.metrics.api.UnifiedMetrics
2122
import dev.cubxity.plugins.metrics.prometheus.PrometheusMetricsDriver
2223
import dev.cubxity.plugins.metrics.prometheus.collector.UnifiedMetricsCollector
24+
import dev.cubxity.plugins.metrics.prometheus.config.AuthenticationScheme
2325
import io.prometheus.client.CollectorRegistry
2426
import io.prometheus.client.exporter.HTTPServer
25-
import java.net.InetSocketAddress
2627

27-
class PrometheusHTTPExporter(private val api: UnifiedMetrics, private val driver: PrometheusMetricsDriver) : PrometheusExporter {
28+
class PrometheusHTTPExporter(
29+
private val api: UnifiedMetrics,
30+
private val driver: PrometheusMetricsDriver
31+
) : PrometheusExporter {
2832
private var server: HTTPServer? = null
2933

3034
override fun initialize() {
3135
val registry = CollectorRegistry()
3236
registry.register(UnifiedMetricsCollector(api))
3337

34-
server = HTTPServer(InetSocketAddress(driver.config.http.host, driver.config.http.port), registry)
38+
server = HTTPServer.Builder()
39+
.withHostname(driver.config.http.host)
40+
.withPort(driver.config.http.port)
41+
.withRegistry(registry)
42+
.apply {
43+
with(driver.config.http.authentication) {
44+
if (scheme == AuthenticationScheme.Basic) {
45+
withAuthenticator(Authenticator(username, password))
46+
}
47+
}
48+
}
49+
.build()
3550
}
3651

3752
override fun close() {
3853
server?.close()
3954
server = null
4055
}
56+
57+
private class Authenticator(
58+
private val username: String,
59+
private val password: String
60+
) : BasicAuthenticator("unifiedmetrics") {
61+
override fun checkCredentials(username: String?, password: String?): Boolean =
62+
this.username == username && this.password == password
63+
}
4164
}

0 commit comments

Comments
 (0)