You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: instrumentation/jmx-metrics/javaagent/README.md
+43-17
Original file line number
Diff line number
Diff line change
@@ -320,10 +320,10 @@ If such a conversion is not available, then an error is reported during JMX metr
320
320
Currently available unit conversions:
321
321
322
322
| `sourceUnit` | `unit` |
323
-
|--------------|-------|
324
-
| ms | s |
325
-
| us | s |
326
-
| ns | s |
323
+
|--------------|--------|
324
+
| ms | s |
325
+
| us | s |
326
+
| ns | s |
327
327
328
328
Example of defining unit conversion in yaml file:
329
329
```yaml
@@ -341,6 +341,29 @@ rules:
341
341
```
342
342
`sourceUnit`can also be defined on rule level (see [Making shortcuts](#making-shortcuts))
343
343
344
+
### Filtering negative values
345
+
346
+
Sometimes a negative value is returned by the MBean implementation when a metric is not available or not supported.
347
+
For example, [`OperatingSystemMXBean.getProcessCpuLoad`](https://docs.oracle.com/javase/7/docs/jre/api/management/extension/com/sun/management/OperatingSystemMXBean.html#getProcessCpuLoad()) can return a negative value.
348
+
349
+
In this case, it is recommended to filter out the negative values by setting the `dropNegativeValues` metric (or rule) property to `true`, it is set to `false` by default.
350
+
351
+
```yaml
352
+
rules:
353
+
- bean: java.lang:type=OperatingSystem
354
+
# can also be set at rule-level (with lower priority)
355
+
dropNegativeValues: false
356
+
mapping:
357
+
# jvm.cpu.recent_utilization
358
+
ProcessCpuLoad:
359
+
metric: jvm.cpu.recent_utilization
360
+
type: gauge
361
+
unit: '1'
362
+
# setting dropNegativeValues at metric level has priority over rule level.
363
+
dropNegativeValues: true
364
+
desc: Recent CPU utilization for the process as reported by the JVM.
365
+
```
366
+
344
367
### General Syntax
345
368
346
369
Here is the general description of the accepted configuration file syntax. The whole contents of the file is case-sensitive, with exception for `type` as described in the table below.
@@ -356,12 +379,14 @@ rules: # start of list of configuration rules
unit: <UNIT> # optional, redefines the default unit for the whole rule
358
381
type: <TYPE> # optional, redefines the default type for the whole rule
382
+
dropNegativeValues: <BOOL> # optional, redefines if negative values are dropped for the whole rule
359
383
mapping:
360
384
<BEANATTR1>: # an MBean attribute name defining the metric value
361
385
metric: <METRIC_NAME1> # metric name will be <METRIC_NAME_PREFIX><METRIC_NAME1>
362
386
type: <TYPE> # optional, the default type is gauge
363
387
desc: <DESCRIPTION1> # optional
364
388
unit: <UNIT1> # optional
389
+
dropNegativeValues: <BOOL> # optional, defines if negative values are dropped for the metric
365
390
metricAttribute: # optional, will be used in addition to the shared metric attributes above
366
391
<ATTRIBUTE3>: const(<STR>) # direct value for the metric attribute
367
392
<BEANATTR2>: # use a.b to get access into CompositeData
@@ -381,19 +406,20 @@ rules: # start of list of configuration rules
381
406
382
407
The following table explains the used terms with more details.
383
408
384
-
| Syntactic Element | Description |
385
-
| ---------------- | --------------- |
386
-
| OBJECTNAME | A syntactically valid string representing an ObjectName (see [ObjectName constructor](https://docs.oracle.com/javase/8/docs/api/javax/management/ObjectName.html#ObjectName-java.lang.String-)). |
387
-
| ATTRIBUTE | Any well-formed string that can be used as a metric [attribute](https://opentelemetry.io/docs/reference/specification/common/#attribute) key. |
388
-
| ATTR | A non-empty string used as a name of the MBean attribute. The MBean attribute value must be a String, otherwise the specified metric attribute will not be used. |
389
-
| PARAM | A non-empty string used as a property key in the ObjectName identifying the MBean which provides the metric value. If the ObjectName does not have a property with the given key, the specified metric attribute will not be used. |
390
-
| METRIC_NAME_PREFIX | Any non-empty string which will be prepended to the specified metric (instrument) names. |
391
-
| METRIC_NAME | Any non-empty string. The string, prefixed by the optional prefix (see above) must satisfy [instrument naming rule](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-naming-rule). |
392
-
| TYPE | One of `counter`, `updowncounter`, or `gauge`. The default is `gauge`. This value is case insensitive. |
393
-
| DESCRIPTION | Any string to be used as human-readable [description](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-description) of the metric. If the description is not provided by the rule, an attempt will be made to extract one automatically from the corresponding MBean. |
394
-
| UNIT | A string identifying the [unit](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-unit) of measurements reported by the metric. Enclose the string in single or double quotes if using unit annotations. |
395
-
| STR | Any string to be used directly as the metric attribute value. |
396
-
| BEANATTR | A non-empty string representing the MBean attribute defining the metric value. The attribute value must be a number. Special dot-notation _attributeName.itemName_ can be used to access numerical items within attributes of [CompositeType](https://docs.oracle.com/javase/8/docs/api/javax/management/openmbean/CompositeType.html). If a dot happens to be an integral part of the MBean attribute name, it must be escaped by backslash (`\`). |
| OBJECTNAME | A syntactically valid string representing an ObjectName (see [ObjectName constructor](https://docs.oracle.com/javase/8/docs/api/javax/management/ObjectName.html#ObjectName-java.lang.String-)). |
412
+
| ATTRIBUTE | Any well-formed string that can be used as a metric [attribute](https://opentelemetry.io/docs/reference/specification/common/#attribute) key. |
413
+
| ATTR | A non-empty string used as a name of the MBean attribute. The MBean attribute value must be a String, otherwise the specified metric attribute will not be used. |
414
+
| PARAM | A non-empty string used as a property key in the ObjectName identifying the MBean which provides the metric value. If the ObjectName does not have a property with the given key, the specified metric attribute will not be used. |
415
+
| METRIC_NAME_PREFIX | Any non-empty string which will be prepended to the specified metric (instrument) names. |
416
+
| METRIC_NAME | Any non-empty string. The string, prefixed by the optional prefix (see above) must satisfy [instrument naming rule](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-naming-rule). |
417
+
| TYPE | One of `counter`, `updowncounter`, or `gauge`. The default is `gauge`. This value is case insensitive. |
418
+
| DESCRIPTION | Any string to be used as human-readable [description](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-description) of the metric. If the description is not provided by the rule, an attempt will be made to extract one automatically from the corresponding MBean. |
419
+
| UNIT | A string identifying the [unit](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-unit) of measurements reported by the metric. Enclose the string in single or double quotes if using unit annotations. |
420
+
| STR | Any string to be used directly as the metric attribute value. |
421
+
| BEANATTR | A non-empty string representing the MBean attribute defining the metric value. The attribute value must be a number. Special dot-notation _attributeName.itemName_ can be used to access numerical items within attributes of [CompositeType](https://docs.oracle.com/javase/8/docs/api/javax/management/openmbean/CompositeType.html). If a dot happens to be an integral part of the MBean attribute name, it must be escaped by backslash (`\`). |
422
+
| BOOL | A boolean value, either `true` or `false` |
Copy file name to clipboardExpand all lines: instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanAttributeExtractor.java
Copy file name to clipboardExpand all lines: instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/MetricStructure.java
+11
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@
13
13
importjava.util.List;
14
14
importjava.util.Locale;
15
15
importjava.util.Map;
16
+
importjavax.annotation.Nullable;
16
17
17
18
/**
18
19
* An abstract class containing skeletal info about Metrics:
@@ -48,6 +49,7 @@ abstract class MetricStructure {
Copy file name to clipboardExpand all lines: instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/RuleParser.java
0 commit comments