Skip to content

Commit

Permalink
[receiver/elasticsearch] add jvm heap percentage usage metric (open-t…
Browse files Browse the repository at this point in the history
…elemetry#16173)

* feat: add jvm heap percentage usage metric
  • Loading branch information
aboguszewski-sumo committed Nov 10, 2022
1 parent 3d5875d commit 5f44412
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .chloggen/elastic-jvm-heap-percent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: elasticsearchreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: add jvm heap percentage usage metric

# One or more tracking issues related to the change
issues: [14635]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
1 change: 0 additions & 1 deletion receiver/elasticsearchreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ The following metric are available with versions:
- `elasticsearch.cluster.state_update.time` >= [7.16.0](https://www.elastic.co/guide/en/elasticsearch/reference/7.16/release-notes-7.16.0.html)

Details about the metrics produced by this receiver can be found in [metadata.yaml](./metadata.yaml)

[beta]:https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]:https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
1 change: 1 addition & 0 deletions receiver/elasticsearchreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ These are the metrics available for this scraper.
| **jvm.memory.heap.committed** | The amount of memory that is guaranteed to be available for the heap | By | Gauge(Int) | <ul> </ul> |
| **jvm.memory.heap.max** | The maximum amount of memory can be used for the heap | By | Gauge(Int) | <ul> </ul> |
| **jvm.memory.heap.used** | The current heap memory usage | By | Gauge(Int) | <ul> </ul> |
| jvm.memory.heap.utilization | Fraction of heap memory usage | 1 | Gauge(Double) | <ul> </ul> |
| **jvm.memory.nonheap.committed** | The amount of memory that is guaranteed to be available for non-heap purposes | By | Gauge(Int) | <ul> </ul> |
| **jvm.memory.nonheap.used** | The current non-heap memory usage | By | Gauge(Int) | <ul> </ul> |
| **jvm.memory.pool.max** | The maximum amount of memory can be used for the memory pool | By | Gauge(Int) | <ul> <li>memory_pool_name</li> </ul> |
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions receiver/elasticsearchreceiver/internal/model/nodestats.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ type JVMMemoryInfo struct {
NonHeapUsedInBy int64 `json:"non_heap_used_in_bytes"`
MaxHeapInBy int64 `json:"heap_max_in_bytes"`
HeapCommittedInBy int64 `json:"heap_committed_in_bytes"`
HeapUsedPercent int64 `json:"heap_used_percent"`
NonHeapComittedInBy int64 `json:"non_heap_committed_in_bytes"`
MemoryPools JVMMemoryPools `json:"pools"`
}
Expand Down
7 changes: 7 additions & 0 deletions receiver/elasticsearchreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,13 @@ metrics:
value_type: int
attributes: []
enabled: true
jvm.memory.heap.utilization:
description: Fraction of heap memory usage
unit: 1
gauge:
value_type: double
attributes: []
enabled: false
jvm.memory.heap.committed:
description: The amount of memory that is guaranteed to be available for the heap
unit: By
Expand Down
2 changes: 2 additions & 0 deletions receiver/elasticsearchreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ func (r *elasticsearchScraper) scrapeNodeMetrics(ctx context.Context, now pcommo
r.mb.RecordJvmMemoryHeapMaxDataPoint(now, info.JVMInfo.JVMMemoryInfo.MaxHeapInBy)
r.mb.RecordJvmMemoryHeapUsedDataPoint(now, info.JVMInfo.JVMMemoryInfo.HeapUsedInBy)
r.mb.RecordJvmMemoryHeapCommittedDataPoint(now, info.JVMInfo.JVMMemoryInfo.HeapCommittedInBy)
// Elasticsearch sends this data in percent, but we want to represent it as a number between 0 and 1, so we need to divide.
r.mb.RecordJvmMemoryHeapUtilizationDataPoint(now, float64(info.JVMInfo.JVMMemoryInfo.HeapUsedPercent)/100)

r.mb.RecordJvmMemoryNonheapUsedDataPoint(now, info.JVMInfo.JVMMemoryInfo.NonHeapUsedInBy)
r.mb.RecordJvmMemoryNonheapCommittedDataPoint(now, info.JVMInfo.JVMMemoryInfo.NonHeapComittedInBy)
Expand Down
2 changes: 2 additions & 0 deletions receiver/elasticsearchreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func TestScraper(t *testing.T) {
config.Metrics.ElasticsearchNodeOperationsGetCompleted.Enabled = true
config.Metrics.ElasticsearchNodeOperationsGetTime.Enabled = true

config.Metrics.JvmMemoryHeapUtilization.Enabled = true

config.Metrics.ElasticsearchIndexOperationsMergeSize.Enabled = true
config.Metrics.ElasticsearchIndexOperationsMergeDocsCount.Enabled = true
config.Metrics.ElasticsearchIndexSegmentsCount.Enabled = true
Expand Down
14 changes: 14 additions & 0 deletions receiver/elasticsearchreceiver/testdata/expected_metrics/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,20 @@
},
"name": "jvm.threads.count",
"unit": "1"
},
{
"description": "Fraction of heap memory usage",
"gauge": {
"dataPoints": [
{
"asDouble": "0.56",
"startTimeUnixNano": "1661811689941624000",
"timeUnixNano": "1661811689943245000"
}
]
},
"name": "jvm.memory.heap.utilization",
"unit": "1"
}
],
"scope": {
Expand Down

0 comments on commit 5f44412

Please sign in to comment.