Skip to content

Commit c78b6ae

Browse files
committed
Use weaver to generate OSHI metrics
1 parent c965b09 commit c78b6ae

26 files changed

+889
-127
lines changed

instrumentation/oshi/Makefile

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# From where to resolve the containers (e.g. "otel/weaver").
2+
WEAVER_CONTAINER_REPOSITORY=docker.io
3+
# Versioned, non-qualified references to containers used in this Makefile.
4+
# These are parsed from dependencies.Dockerfile so dependabot will autoupdate
5+
# the versions of docker files we use.
6+
VERSIONED_WEAVER_CONTAINER_NO_REPO=$(shell cat weaver.Dockerfile | awk '$$4=="weaver" {print $$2}')
7+
# Versioned, non-qualified references to containers used in this Makefile.
8+
WEAVER_CONTAINER=$(WEAVER_CONTAINER_REPOSITORY)/$(VERSIONED_WEAVER_CONTAINER_NO_REPO)
9+
10+
# Next - we want to run docker as our local file user, so generated code is not
11+
# owned by root, and we don't give unnecessary access.
12+
#
13+
# Determine if "docker" is actually podman
14+
DOCKER_VERSION_OUTPUT := $(shell docker --version 2>&1)
15+
DOCKER_IS_PODMAN := $(shell echo $(DOCKER_VERSION_OUTPUT) | grep -c podman)
16+
ifeq ($(DOCKER_IS_PODMAN),0)
17+
DOCKER_COMMAND := docker
18+
else
19+
DOCKER_COMMAND := podman
20+
endif
21+
DOCKER_RUN=$(DOCKER_COMMAND) run
22+
DOCKER_USER=$(shell id -u):$(shell id -g)
23+
DOCKER_USER_IS_HOST_USER_ARG=-u $(DOCKER_USER)
24+
ifeq ($(DOCKER_COMMAND),podman)
25+
# On podman, additional arguments are needed to make "-u" work
26+
# correctly with the host user ID and host group ID.
27+
#
28+
# Error: OCI runtime error: crun: setgroups: Invalid argument
29+
DOCKER_USER_IS_HOST_USER_ARG=--userns=keep-id -u $(DOCKER_USER)
30+
endif
31+
32+
.PHONY: generate-docs
33+
generate-docs:
34+
mkdir -p docs
35+
$(DOCKER_RUN) --rm \
36+
$(DOCKER_USER_IS_HOST_USER_ARG) \
37+
--mount 'type=bind,source=$(PWD)/model,target=/home/weaver/model,readonly' \
38+
--mount 'type=bind,source=$(PWD)/templates,target=/home/weaver/templates,readonly' \
39+
--mount 'type=bind,source=$(PWD)/docs,target=/home/weaver/target' \
40+
${WEAVER_CONTAINER} registry generate \
41+
--registry=/home/weaver/model \
42+
markdown \
43+
--future \
44+
/home/weaver/target
45+
46+
.PHONY: check
47+
check:
48+
$(DOCKER_RUN) --rm \
49+
$(DOCKER_USER_IS_HOST_USER_ARG) \
50+
--mount 'type=bind,source=$(PWD)/model,target=/home/weaver/model,readonly' \
51+
--mount 'type=bind,source=$(PWD)/templates,target=/home/weaver/templates,readonly' \
52+
--mount 'type=bind,source=$(PWD)/docs,target=/home/weaver/target' \
53+
${WEAVER_CONTAINER} registry check \
54+
--registry=/home/weaver/model
55+
56+
.PHONY: generate-java
57+
generate-java:
58+
mkdir -p library/src/main/java/io/opentelemetry/oshi
59+
$(DOCKER_RUN) --rm \
60+
$(DOCKER_USER_IS_HOST_USER_ARG) \
61+
--mount 'type=bind,source=$(PWD)/model,target=/home/weaver/model,readonly' \
62+
--mount 'type=bind,source=$(PWD)/templates,target=/home/weaver/templates,readonly' \
63+
--mount 'type=bind,source=$(PWD)/library/src/main/java/io/opentelemetry/instrumentation/oshi,target=/home/weaver/target' \
64+
${WEAVER_CONTAINER} registry generate \
65+
--registry=/home/weaver/model \
66+
java \
67+
--future \
68+
/home/weaver/target
69+
70+
.PHONY: generate
71+
generate: generate-docs generate-java

instrumentation/oshi/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,18 @@
77
# Using OSHI with OpenTelemetry Java agent
88

99
Download oshi-core jar from https://search.maven.org/search?q=g:com.github.oshi%20AND%20a:oshi-core and place it on the class path. OpenTelemetry Java agent uses system class loader to load classes from the oshi-core jar that are used for the metrics.
10+
11+
12+
## Development with weaver
13+
14+
To regenerate the code (run these from within this `oshi` directory):
15+
16+
```bash
17+
make generate-java
18+
```
19+
20+
To regenerate the documentation:
21+
22+
```bash
23+
make generate-docs
24+
```
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Produced Metrics
2+
3+
4+
## Metric `system.memory.utilization`
5+
6+
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
7+
| -------- | --------------- | ----------- | -------------- | --------- |
8+
| `system.memory.utilization` | Gauge | `1` | System memory utilization | ![Development](https://img.shields.io/badge/-development-blue) |
9+
10+
11+
### `system.memory.utilization` Attributes
12+
13+
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
14+
|---|---|---|---|---|---|
15+
| `state` | string | The type of memory being measured. | `used`; `free`; `cached`; `buffered` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
16+
17+
18+
19+
## Metric `system.memory.usage`
20+
21+
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
22+
| -------- | --------------- | ----------- | -------------- | --------- |
23+
| `system.memory.usage` | UpDownCounter | `By` | System memory usage | ![Development](https://img.shields.io/badge/-development-blue) |
24+
25+
26+
### `system.memory.usage` Attributes
27+
28+
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
29+
|---|---|---|---|---|---|
30+
| `state` | string | The type of memory being measured. | `used`; `free`; `cached`; `buffered` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
31+
32+
33+
34+
## Metric `system.network.io`
35+
36+
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
37+
| -------- | --------------- | ----------- | -------------- | --------- |
38+
| `system.network.io` | Counter | `By` | System network IO | ![Development](https://img.shields.io/badge/-development-blue) |
39+
40+
41+
### `system.network.io` Attributes
42+
43+
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
44+
|---|---|---|---|---|---|
45+
| `device` | string | The name of the network device. | `eth0` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
46+
| `direction` | string | The direction of the flow of data being measured. | `receive`; `transmit`; `read`; `write` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
47+
48+
49+
50+
## Metric `system.network.packets`
51+
52+
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
53+
| -------- | --------------- | ----------- | -------------- | --------- |
54+
| `system.network.packets` | Counter | `{packets}` | System network packets | ![Development](https://img.shields.io/badge/-development-blue) |
55+
56+
57+
### `system.network.packets` Attributes
58+
59+
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
60+
|---|---|---|---|---|---|
61+
| `device` | string | The name of the network device. | `eth0` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
62+
| `direction` | string | The direction of the flow of data being measured. | `receive`; `transmit`; `read`; `write` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
63+
64+
65+
66+
## Metric `system.network.errors`
67+
68+
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
69+
| -------- | --------------- | ----------- | -------------- | --------- |
70+
| `system.network.errors` | Counter | `{errors}` | System network errors | ![Development](https://img.shields.io/badge/-development-blue) |
71+
72+
73+
### `system.network.errors` Attributes
74+
75+
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
76+
|---|---|---|---|---|---|
77+
| `device` | string | The name of the network device. | `eth0` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
78+
| `direction` | string | The direction of the flow of data being measured. | `receive`; `transmit`; `read`; `write` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
79+
80+
81+
82+
## Metric `system.disk.io`
83+
84+
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
85+
| -------- | --------------- | ----------- | -------------- | --------- |
86+
| `system.disk.io` | Counter | `By` | System disk IO | ![Development](https://img.shields.io/badge/-development-blue) |
87+
88+
89+
### `system.disk.io` Attributes
90+
91+
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
92+
|---|---|---|---|---|---|
93+
| `device` | string | The name of the network device. | `eth0` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
94+
| `direction` | string | The direction of the flow of data being measured. | `receive`; `transmit`; `read`; `write` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
95+
96+
97+
98+
## Metric `system.disk.operations`
99+
100+
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
101+
| -------- | --------------- | ----------- | -------------- | --------- |
102+
| `system.disk.operations` | Counter | `{operations}` | System disk operations | ![Development](https://img.shields.io/badge/-development-blue) |
103+
104+
105+
### `system.disk.operations` Attributes
106+
107+
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
108+
|---|---|---|---|---|---|
109+
| `device` | string | The name of the network device. | `eth0` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
110+
| `direction` | string | The direction of the flow of data being measured. | `receive`; `transmit`; `read`; `write` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
111+
112+
113+
114+
## Metric `runtime.java.memory`
115+
116+
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
117+
| -------- | --------------- | ----------- | -------------- | --------- |
118+
| `runtime.java.memory` | UpDownCounter | `By` | Runtime Java memory | ![Development](https://img.shields.io/badge/-development-blue) |
119+
120+
121+
### `runtime.java.memory` Attributes
122+
123+
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
124+
|---|---|---|---|---|---|
125+
| `type` | string | The type of memory measurement | `rss`; `vms` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
126+
127+
128+
129+
## Metric `runtime.java.cpu_time`
130+
131+
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
132+
| -------- | --------------- | ----------- | -------------- | --------- |
133+
| `runtime.java.cpu_time` | Gauge | `ms` | Runtime Java CPU time | ![Development](https://img.shields.io/badge/-development-blue) |
134+
135+
136+
### `runtime.java.cpu_time` Attributes
137+
138+
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
139+
|---|---|---|---|---|---|
140+
| `type` | string | The type of CPU time measurement | `user`; `system` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.oshi;
7+
8+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
10+
import io.opentelemetry.api.common.AttributeKey;
11+
12+
// This file is generated using weaver. Do not edit manually.
13+
14+
/** Attribute definitions generated from a Weaver model. Do not edit manually. */
15+
public final class CustomAttributes {
16+
17+
/** The name of the network device. */
18+
public static final AttributeKey<String> DEVICE = stringKey("device");
19+
20+
/** The direction of the flow of data being measured. */
21+
public static final AttributeKey<String> DIRECTION = stringKey("direction");
22+
23+
/** The type of memory being measured. */
24+
public static final AttributeKey<String> STATE = stringKey("state");
25+
26+
/** The type of measurement being taken. */
27+
public static final AttributeKey<String> TYPE = stringKey("type");
28+
29+
private CustomAttributes() {}
30+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.oshi;
7+
8+
import io.opentelemetry.api.metrics.Meter;
9+
import io.opentelemetry.api.metrics.ObservableDoubleGauge;
10+
import io.opentelemetry.api.metrics.ObservableDoubleMeasurement;
11+
import io.opentelemetry.api.metrics.ObservableLongCounter;
12+
import io.opentelemetry.api.metrics.ObservableLongGauge;
13+
import io.opentelemetry.api.metrics.ObservableLongMeasurement;
14+
import io.opentelemetry.api.metrics.ObservableLongUpDownCounter;
15+
import java.util.function.Consumer;
16+
17+
// This file is generated using weaver. Do not edit manually.
18+
19+
/** Metric definitions generated from a Weaver model. Do not edit manually. */
20+
public final class Metrics {
21+
22+
public static ObservableDoubleGauge createSystemMemoryUtilization(
23+
Meter meter, Consumer<ObservableDoubleMeasurement> callback) {
24+
return meter
25+
.gaugeBuilder("system.memory.utilization")
26+
.setUnit("1")
27+
.setDescription("System memory utilization")
28+
.buildWithCallback(callback);
29+
}
30+
31+
public static ObservableLongUpDownCounter createSystemMemoryUsage(
32+
Meter meter, Consumer<ObservableLongMeasurement> callback) {
33+
return meter
34+
.upDownCounterBuilder("system.memory.usage")
35+
.setUnit("By")
36+
.setDescription("System memory usage")
37+
.buildWithCallback(callback);
38+
}
39+
40+
public static ObservableLongCounter createSystemNetworkIo(
41+
Meter meter, Consumer<ObservableLongMeasurement> callback) {
42+
return meter
43+
.counterBuilder("system.network.io")
44+
.setUnit("By")
45+
.setDescription("System network IO")
46+
.buildWithCallback(callback);
47+
}
48+
49+
public static ObservableLongCounter createSystemNetworkPackets(
50+
Meter meter, Consumer<ObservableLongMeasurement> callback) {
51+
return meter
52+
.counterBuilder("system.network.packets")
53+
.setUnit("{packets}")
54+
.setDescription("System network packets")
55+
.buildWithCallback(callback);
56+
}
57+
58+
public static ObservableLongCounter createSystemNetworkErrors(
59+
Meter meter, Consumer<ObservableLongMeasurement> callback) {
60+
return meter
61+
.counterBuilder("system.network.errors")
62+
.setUnit("{errors}")
63+
.setDescription("System network errors")
64+
.buildWithCallback(callback);
65+
}
66+
67+
public static ObservableLongCounter createSystemDiskIo(
68+
Meter meter, Consumer<ObservableLongMeasurement> callback) {
69+
return meter
70+
.counterBuilder("system.disk.io")
71+
.setUnit("By")
72+
.setDescription("System disk IO")
73+
.buildWithCallback(callback);
74+
}
75+
76+
public static ObservableLongCounter createSystemDiskOperations(
77+
Meter meter, Consumer<ObservableLongMeasurement> callback) {
78+
return meter
79+
.counterBuilder("system.disk.operations")
80+
.setUnit("{operations}")
81+
.setDescription("System disk operations")
82+
.buildWithCallback(callback);
83+
}
84+
85+
public static ObservableLongUpDownCounter createRuntimeJavaMemory(
86+
Meter meter, Consumer<ObservableLongMeasurement> callback) {
87+
return meter
88+
.upDownCounterBuilder("runtime.java.memory")
89+
.setUnit("By")
90+
.setDescription("Runtime Java memory")
91+
.buildWithCallback(callback);
92+
}
93+
94+
public static ObservableLongGauge createRuntimeJavaCpuTime(
95+
Meter meter, Consumer<ObservableLongMeasurement> callback) {
96+
return meter
97+
.gaugeBuilder("runtime.java.cpu_time")
98+
.ofLongs()
99+
.setUnit("ms")
100+
.setDescription("Runtime Java CPU time")
101+
.buildWithCallback(callback);
102+
}
103+
104+
private Metrics() {}
105+
}

0 commit comments

Comments
 (0)