Skip to content
Open
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
56 changes: 56 additions & 0 deletions jmx-scraper/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# https://github.com/open-telemetry/weaver/releases
# v0.18.0
WEAVER_CONTAINER=otel/weaver@sha256:5425ade81dc22ddd840902b0638b4b6a9186fb654c5b50c1d1ccd31299437390

# Next - we want to run docker as our local file user, so generated code is not
# owned by root, and we don't give unnecessary access.
#
# Determine if "docker" is actually podman
DOCKER_VERSION_OUTPUT := $(shell docker --version 2>&1)
DOCKER_IS_PODMAN := $(shell echo $(DOCKER_VERSION_OUTPUT) | grep -c podman)
ifeq ($(DOCKER_IS_PODMAN),0)
DOCKER_COMMAND := docker
else
DOCKER_COMMAND := podman
endif
DOCKER_RUN=$(DOCKER_COMMAND) run
DOCKER_USER=$(shell id -u):$(shell id -g)
DOCKER_USER_IS_HOST_USER_ARG=-u $(DOCKER_USER)
ifeq ($(DOCKER_COMMAND),podman)
# On podman, additional arguments are needed to make "-u" work
# correctly with the host user ID and host group ID.
#
# Error: OCI runtime error: crun: setgroups: Invalid argument
DOCKER_USER_IS_HOST_USER_ARG=--userns=keep-id -u $(DOCKER_USER)
endif

# Generate the rules files from the model
.PHONY: generate-rules
generate-rules:
mkdir -p output
$(DOCKER_RUN) \
$(DOCKER_USER_IS_HOST_USER_ARG) \
--mount 'type=bind,source=$(PWD)/model,target=/home/weaver/model,readonly' \
--mount 'type=bind,source=$(PWD)/templates,target=/home/weaver/templates,readonly' \
--mount 'type=bind,source=$(PWD)/output,target=/home/weaver/output' \
--mount 'type=bind,source=$(PWD),target=/home/weaver' \
${WEAVER_CONTAINER} registry generate \
--registry /home/weaver/model \
rules \
--future \
/home/weaver/output
cp ./output/jvm.yaml ./src/main/resources/jvm.yaml

# for Debugging purposes only: run a shell in the weaver container
.PHONY: weaver-shell
weaver-shell:
mkdir -p output
@echo "DOCKER_USER_IS_HOST_USER_ARG is: $(DOCKER_USER_IS_HOST_USER_ARG)"
$(DOCKER_RUN) \
$(DOCKER_USER_IS_HOST_USER_ARG) \
--mount 'type=bind,source=$(PWD)/model,target=/home/weaver/model,readonly' \
--mount 'type=bind,source=$(PWD)/templates,target=/home/weaver/templates,readonly' \
--mount 'type=bind,source=$(PWD)/output,target=/home/weaver/output' \
--mount 'type=bind,source=$(PWD),target=/home/weaver' \
--entrypoint sh \
-it ${WEAVER_CONTAINER}
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
20 changes: 12 additions & 8 deletions jmx-scraper/src/main/resources/jvm.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

rules:

# Rule for ClassLoading metrics
- bean: java.lang:type=ClassLoading
mapping:
LoadedClassCount:
Expand All @@ -10,6 +10,7 @@ rules:
unit: "{class}"
desc: number of loaded classes

# Rule for Garbage Collector metrics
- bean: java.lang:type=GarbageCollector,name=*
mapping:
CollectionCount:
Expand All @@ -27,43 +28,45 @@ rules:
metricAttribute:
name: param(name)

# Rule for Heap and Non-Heap Memory metrics
- bean: java.lang:type=Memory
unit: By
prefix: jvm.memory.
mapping:
HeapMemoryUsage.committed:
metric: heap.committed
desc: current heap usage
desc: current heap size
type: gauge
HeapMemoryUsage.init:
metric: heap.init
desc: current heap usage
desc: initial heap size
type: gauge
HeapMemoryUsage.max:
metric: heap.max
desc: current heap usage
desc: max heap size
type: gauge
HeapMemoryUsage.used:
metric: heap.used
desc: current heap usage
type: gauge
NonHeapMemoryUsage.committed:
metric: nonheap.committed
desc: current non-heap usage
desc: current non-heap size
type: gauge
NonHeapMemoryUsage.init:
metric: nonheap.init
desc: current non-heap usage
desc: initial non-heap size
type: gauge
NonHeapMemoryUsage.max:
metric: nonheap.max
desc: current non-heap usage
desc: max non-heap size
type: gauge
NonHeapMemoryUsage.used:
metric: nonheap.used
desc: current non-heap usage
type: gauge

# Rule for Memory Pool metrics
- bean: java.lang:type=MemoryPool,name=*
type: gauge
unit: By
Expand All @@ -83,9 +86,10 @@ rules:
metric: jvm.memory.pool.used
desc: current memory pool usage

# Rule for Threading metrics
- bean: java.lang:type=Threading
mapping:
ThreadCount:
metric: jvm.threads.count
unit: "{thread}"
desc: number of threads
desc: number of threads
Loading
Loading