-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Cubxity/dev
Release 0.2.0
- Loading branch information
Showing
47 changed files
with
681 additions
and
466 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
52 changes: 52 additions & 0 deletions
52
api/src/main/kotlin/dev/cubxity/plugins/metrics/api/metric/collector/Counter.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,52 @@ | ||
/* | ||
* 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.api.metric.collector | ||
|
||
import dev.cubxity.plugins.metrics.api.metric.data.CounterSample | ||
import dev.cubxity.plugins.metrics.api.metric.data.MetricSample | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
/** | ||
* @param name name of the sample. Should end with '_total' | ||
*/ | ||
class Counter(val name: String) : MetricCollector { | ||
private val tags: MutableMap<String, String> = HashMap() | ||
private val count = AtomicInteger() | ||
|
||
override fun collect(): List<MetricSample> { | ||
val sample = CounterSample(name, count.get().toDouble(), tags) | ||
return listOf(sample) | ||
} | ||
|
||
fun inc() { | ||
count.incrementAndGet() | ||
} | ||
|
||
fun dec() { | ||
count.decrementAndGet() | ||
} | ||
|
||
operator fun plusAssign(delta: Int) { | ||
count.addAndGet(delta) | ||
} | ||
|
||
operator fun minusAssign(delta: Int) { | ||
count.addAndGet(-delta) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
api/src/main/kotlin/dev/cubxity/plugins/metrics/api/metric/collector/Gauge.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,56 @@ | ||
/* | ||
* 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.api.metric.collector | ||
|
||
import dev.cubxity.plugins.metrics.api.metric.data.GaugeSample | ||
import dev.cubxity.plugins.metrics.api.metric.data.MetricSample | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
/** | ||
* @param name name of the sample. | ||
*/ | ||
class Gauge(val name: String) : MetricCollector { | ||
private val tags: MutableMap<String, String> = HashMap() | ||
private val count = AtomicInteger() | ||
|
||
override fun collect(): List<MetricSample> { | ||
val sample = GaugeSample(name, count.get().toDouble(), tags) | ||
return listOf(sample) | ||
} | ||
|
||
fun set(value: Int) { | ||
count.set(value) | ||
} | ||
|
||
fun inc() { | ||
count.incrementAndGet() | ||
} | ||
|
||
fun dec() { | ||
count.decrementAndGet() | ||
} | ||
|
||
operator fun plusAssign(delta: Int) { | ||
count.addAndGet(delta) | ||
} | ||
|
||
operator fun minusAssign(delta: Int) { | ||
count.addAndGet(-delta) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
api/src/main/kotlin/dev/cubxity/plugins/metrics/api/metric/collector/MetricCollector.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,33 @@ | ||
/* | ||
* 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.api.metric.collector | ||
|
||
import dev.cubxity.plugins.metrics.api.metric.data.MetricSample | ||
|
||
const val NANOSECONDS_PER_SECOND: Double = 1E9 | ||
const val MILLISECONDS_PER_SECOND: Double = 1E3 | ||
|
||
interface MetricCollector { | ||
/** | ||
* Collects the metric and returns a list of samples. | ||
* | ||
* @return [List] of [MetricSample] | ||
*/ | ||
fun collect(): List<MetricSample> | ||
} |
45 changes: 45 additions & 0 deletions
45
api/src/main/kotlin/dev/cubxity/plugins/metrics/api/metric/data/MetricSample.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,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/>. | ||
*/ | ||
|
||
package dev.cubxity.plugins.metrics.api.metric.data | ||
|
||
data class MetricSample( | ||
val type: MetricType, | ||
val name: String, | ||
val value: Double, | ||
val tags: Map<String, String> = emptyMap() | ||
) | ||
|
||
fun MetricSample( | ||
type: MetricType, | ||
name: String, | ||
value: Number, | ||
tags: Map<String, String> = emptyMap() | ||
): MetricSample = MetricSample(type, name, value.toDouble(), tags) | ||
|
||
fun CounterSample(name: String, value: Double, tags: Map<String, String> = emptyMap()): MetricSample = | ||
MetricSample(MetricType.Counter, name, value, tags) | ||
|
||
fun CounterSample(name: String, value: Number, tags: Map<String, String> = emptyMap()): MetricSample = | ||
MetricSample(MetricType.Counter, name, value, tags) | ||
|
||
fun GaugeSample(name: String, value: Double, tags: Map<String, String> = emptyMap()): MetricSample = | ||
MetricSample(MetricType.Gauge, name, value, tags) | ||
|
||
fun GaugeSample(name: String, value: Number, tags: Map<String, String> = emptyMap()): MetricSample = | ||
MetricSample(MetricType.Gauge, name, value, tags) |
28 changes: 28 additions & 0 deletions
28
api/src/main/kotlin/dev/cubxity/plugins/metrics/api/metric/data/MetricType.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,28 @@ | ||
/* | ||
* 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.api.metric.data | ||
|
||
/** | ||
* Prometheus-compatible metric types. The Prometheus server does not yet make use of the type information. | ||
*/ | ||
sealed class MetricType { | ||
object Unknown : MetricType() | ||
object Counter : MetricType() | ||
object Gauge : MetricType() | ||
} |
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
Oops, something went wrong.