Skip to content

Commit

Permalink
feat: added GC metrics collector
Browse files Browse the repository at this point in the history
  • Loading branch information
Cubxity committed Jun 23, 2021
1 parent 6416d41 commit 775e77c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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.common.metric.system

import dev.cubxity.plugins.metrics.api.metric.collector.MILLISECONDS_PER_SECOND
import dev.cubxity.plugins.metrics.api.metric.collector.MetricCollector
import dev.cubxity.plugins.metrics.api.metric.data.CounterSample
import dev.cubxity.plugins.metrics.api.metric.data.MetricSample
import java.lang.management.ManagementFactory

class GCCollector : MetricCollector {
private val beans = ManagementFactory.getGarbageCollectorMXBeans()

override fun collect(): List<MetricSample> = beans.map {
CounterSample("jvm_gc_seconds_total", it.collectionTime / MILLISECONDS_PER_SECOND, mapOf("gc" to it.name))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SystemMetric : Metric {
override val collectors: List<MetricCollector> = listOf(
MemoryCollector(),
ProcessCollector(),
ThreadCollector()
ThreadCollector(),
GCCollector()
)
}

0 comments on commit 775e77c

Please sign in to comment.