Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion jmx-scraper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ dependencies {
runtimeOnly("org.terracotta:jmxremote_optional-tc:1.0.8")

implementation("io.opentelemetry.instrumentation:opentelemetry-jmx-metrics")

implementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")

testImplementation("org.junit-pioneer:junit-pioneer")
Expand Down Expand Up @@ -99,6 +98,46 @@ tasks {
}
}

//
// task that run weaver within gradle;
tasks.register("runWeaver", Exec::class) {
standardOutput = System.out
executable = "docker"

val WEAVER_CONTAINER = "otel/weaver@sha256:5425ade81dc22ddd840902b0638b4b6a9186fb654c5b50c1d1ccd31299437390"
val projectRoot = project.layout.projectDirectory.asFile.absolutePath
val modelPath = project.layout.projectDirectory.dir("model").asFile.absolutePath
val templatePath = project.layout.projectDirectory.dir("templates").asFile.absolutePath
val outputPath = project.layout.projectDirectory.file("src/main/resources").asFile.absolutePath

val file_args = if (org.gradle.internal.os.OperatingSystem.current().isWindows())
// Don't need to worry about file system permissions in docker.
listOf()
else {
// Make sure we run as local file user
val unix = com.sun.security.auth.module.UnixSystem()
val uid = unix.getUid() // $(id -u $USERNAME)
val gid = unix.getGid() // $(id -g $USERNAME)
listOf("-u", "$uid:$gid")
}

val weaver_args = listOf(
"--rm",
"--platform=linux/x86_64",
"--mount", "type=bind,source=${modelPath},target=/home/weaver/source,readonly",
"--mount", "type=bind,source=${templatePath},target=/home/weaver/templates,readonly",
"--mount", "type=bind,source=${outputPath},target=/home/weaver/target",
"--mount", "type=bind,source=${projectRoot},target=/home/weaver",
"${WEAVER_CONTAINER}",
"registry", "generate",
"--registry=/home/weaver/source",
"--templates=/home/weaver/templates",
"rules",
"/home/weaver/target/")

setArgs(listOf("run") + file_args + weaver_args)
}

// Don't publish non-shadowed jar (shadowJar is in shadowRuntimeElements)
with(components["java"] as AdhocComponentWithVariants) {
configurations.forEach {
Expand Down
16 changes: 16 additions & 0 deletions jmx-scraper/model/attributes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
groups:
- id: metric.attributes
type: attribute_group
brief: "Metric attributes."
attributes:
- id: pool.name
brief: "Pool name."
type: string
stability: beta
examples: [ "Memory pool 1", "Code Cache", "Metaspace", "Compressed Class Space"]

- id: gc.name
brief: "Garbage Collector name."
type: string
stability: beta
examples: [ "Parallel GC", "G1 Young Generation"]
146 changes: 146 additions & 0 deletions jmx-scraper/model/metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
groups:
- id: jvm.classes.loaded
type: metric
brief: "number of loaded classes"
metric_name: jvm.classes.loaded
instrument: updowncounter
unit: "{class}"
stability: beta

- id: jvm.gc.collections.count
type: metric
brief: "total number of collections that have occurred"
metric_name: jvm.gc.collections.count
instrument: counter
unit: "{collection}"
stability: beta
attributes:
- ref: gc.name
requirement_level: required

- id: jvm.gc.collections.elapsed
type: metric
brief: "the approximate accumulated collection elapsed time in milliseconds"
metric_name: jvm.gc.collections.elapsed
instrument: counter
unit: ms
stability: beta
attributes:
- ref: gc.name
requirement_level: required

- id: jvm.memory.heap.committed
type: metric
brief: "current heap size"
metric_name: jvm.memory.heap.committed
instrument: gauge
unit: By
stability: beta

- id: jvm.memory.heap.init
type: metric
brief: "initial heap size"
metric_name: jvm.memory.heap.init
instrument: gauge
unit: By
stability: beta

- id: jvm.memory.heap.max
type: metric
brief: "max heap size"
metric_name: jvm.memory.heap.max
instrument: gauge
unit: By
stability: beta

- id: jvm.memory.heap.used
type: metric
brief: "current heap usage"
metric_name: jvm.memory.heap.used
instrument: gauge
unit: By
stability: beta

- id: jvm.memory.nonheap.committed
type: metric
brief: "current non-heap size"
metric_name: jvm.memory.nonheap.committed
instrument: gauge
unit: By
stability: beta

- id: jvm.memory.nonheap.init
type: metric
brief: "initial non-heap size"
metric_name: jvm.memory.nonheap.init
instrument: gauge
unit: By
stability: beta

- id: jvm.memory.nonheap.max
type: metric
brief: "max non-heap size"
metric_name: jvm.memory.nonheap.max
instrument: gauge
unit: By
stability: beta

- id: jvm.memory.nonheap.used
type: metric
brief: "current non-heap usage"
metric_name: jvm.memory.nonheap.used
instrument: gauge
unit: By
stability: beta

- id: jvm.memory.pool.committed
type: metric
brief: "current memory pool size"
metric_name: jvm.memory.pool.committed
instrument: gauge
unit: By
stability: beta
attributes:
- ref: pool.name
requirement_level: required

- id: jvm.memory.pool.init
type: metric
brief: "initial memory pool size"
metric_name: jvm.memory.pool.init
instrument: gauge
unit: By
stability: beta
attributes:
- ref: pool.name
requirement_level: required

- id: jvm.memory.pool.max
type: metric
brief: "max memory pool size"
metric_name: jvm.memory.pool.max
instrument: gauge
unit: By
stability: beta
attributes:
- ref: pool.name
requirement_level: required

- id: jvm.memory.pool.used
type: metric
brief: "current memory pool usage"
metric_name: jvm.memory.pool.used
instrument: gauge
unit: By
stability: beta
attributes:
- ref: pool.name
requirement_level: required

- id: jvm.threads.count
type: metric
brief: "current number of thread count"
metric_name: jvm.threads.count
instrument: gauge
unit: "{thread}"
stability: beta
8 changes: 8 additions & 0 deletions jmx-scraper/model/registry_manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: JMX scraper
semconv_version: v0.1.0
schema_base_url: https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/jmx-scraper/model

# Define where weaver should look for templates
templates:
- id: jvm
file: templates/registry/rules/jvm.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ protected MetricsVerifier createMetricsVerifier() {
"jvm.memory.heap.committed",
metric ->
metric
.hasDescription("current heap usage")
.hasDescription("current heap size")
.hasUnit("By")
.isGauge()
.hasDataPointsWithoutAttributes())
.add(
"jvm.memory.heap.init",
metric ->
metric
.hasDescription("current heap usage")
.hasDescription("initial heap size")
.hasUnit("By")
.isGauge()
.hasDataPointsWithoutAttributes())
.add(
"jvm.memory.heap.max",
metric ->
metric
.hasDescription("current heap usage")
.hasDescription("max heap size")
.hasUnit("By")
.isGauge()
.hasDataPointsWithoutAttributes())
Expand All @@ -122,23 +122,23 @@ protected MetricsVerifier createMetricsVerifier() {
"jvm.memory.nonheap.committed",
metric ->
metric
.hasDescription("current non-heap usage")
.hasDescription("current non-heap size")
.hasUnit("By")
.isGauge()
.hasDataPointsWithoutAttributes())
.add(
"jvm.memory.nonheap.init",
metric ->
metric
.hasDescription("current non-heap usage")
.hasDescription("initial non-heap size")
.hasUnit("By")
.isGauge()
.hasDataPointsWithoutAttributes())
.add(
"jvm.memory.nonheap.max",
metric ->
metric
.hasDescription("current non-heap usage")
.hasDescription("max non-heap size")
.hasUnit("By")
.isGauge()
.hasDataPointsWithoutAttributes())
Expand All @@ -154,23 +154,23 @@ protected MetricsVerifier createMetricsVerifier() {
"jvm.memory.pool.committed",
metric ->
metric
.hasDescription("current memory pool usage")
.hasDescription("current memory pool size")
.hasUnit("By")
.isGauge()
.hasDataPointsWithAttributes(memoryAttributes))
.add(
"jvm.memory.pool.init",
metric ->
metric
.hasDescription("current memory pool usage")
.hasDescription("initial memory pool size")
.hasUnit("By")
.isGauge()
.hasDataPointsWithAttributes(memoryAttributes))
.add(
"jvm.memory.pool.max",
metric ->
metric
.hasDescription("current memory pool usage")
.hasDescription("max memory pool size")
.hasUnit("By")
.isGauge()
.hasDataPointsWithAttributes(memoryAttributes))
Expand All @@ -186,7 +186,7 @@ protected MetricsVerifier createMetricsVerifier() {
"jvm.threads.count",
metric ->
metric
.hasDescription("number of threads")
.hasDescription("current number of thread count")
.hasUnit("{thread}")
.isGauge()
.hasDataPointsWithoutAttributes());
Expand Down
Loading
Loading