elastic-apm 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81641cee86d90236fac69836ed6b6e4e858e0650d099c7cf0ab2fbc58e9d8550
4
- data.tar.gz: a8f13b6c5b4b430c4cba21f92167b784634bc151ef802472e9a4fc1af6f95c1b
3
+ metadata.gz: bc66ce3466effa6740c0b8c9dbb0d74358b54d9039ceebe2938674170e68662b
4
+ data.tar.gz: d3288b6cf41bbe33fb6594789371d36fcb66ccc2b9ec9d8d2f6aed08f4d212f7
5
5
  SHA512:
6
- metadata.gz: 3db0a577687ac11af79c29de68c3935cb0df9572bed2583c5d9666dd15aefabb97a0ab0a081b79fd41ee7e53e1e3319700d0ebd74a30883eaa55b45684ea9862
7
- data.tar.gz: a191284ee54fd8be1511927ff1af81f13bb129c6f282d2078099cf8a79fe124ec5f995243260d66a23920f6d82fdb1955614cdbe260b58413bb9863ee0226a3a
6
+ metadata.gz: 6fcdb201cf7b1824776fffff92e8fc538613928b4ae977f694f67239c15a9e10f14a1ceb4669248eb658c4b2fd439398d0badd231292367e8371655cd2bae738
7
+ data.tar.gz: 72fdb5641db042a4c7ccd6fcdfc97d43949d1f8ed0b561029e6beffa640262d04c2a639f5f75944b944c1283dae8b2c929f0a3aae14e7e2547af3e942e4307a8
data/CHANGELOG.asciidoc CHANGED
@@ -35,6 +35,14 @@ endif::[]
35
35
  [[release-notes-4.x]]
36
36
  === Ruby Agent version 4.x
37
37
 
38
+ [[release-notes-4.3.0]]
39
+ ==== 4.3.0
40
+
41
+ [float]
42
+ ===== Added
43
+
44
+ - Add JVM memory metrics {pull}1040[#1040]
45
+
38
46
  [[release-notes-4.2.0]]
39
47
  ==== 4.2.0
40
48
 
@@ -141,3 +141,95 @@ The total time spent in garbage collection.
141
141
 
142
142
  **NB:** You need to enable Ruby's GC Profiler for this to get reported.
143
143
  You can do this at any time when your application boots by calling `GC::Profiler.enable`.
144
+
145
+ [float]
146
+ [[metrics-jvm-metrics]]
147
+ === JVM Metrics
148
+
149
+ The following metrics are available when using JRuby. They use the ruby java API to gather metrics via MXBean.
150
+
151
+ [float]
152
+ [[metric-jvm.memory.heap.used]]
153
+ ==== `jvm.memory.heap.used`
154
+
155
+ * *Type:* Long
156
+ * *Format:* Bytes
157
+
158
+ The amount of used heap memory in bytes.
159
+
160
+ [float]
161
+ [[metric-jvm.memory.heap.committed]]
162
+ ==== `jvm.memory.heap.committed`
163
+
164
+ * *Type:* Long
165
+ * *Format:* Bytes
166
+
167
+ The amount of heap memory in bytes that is committed for the Java virtual machine to use. This amount of memory is
168
+ guaranteed for the Java virtual machine to use.
169
+
170
+ [float]
171
+ [[metric-jvm.memory.heap.max]]
172
+ ==== `jvm.memory.heap.max`
173
+
174
+ * *Type:* Long
175
+ * *Format:* Bytes
176
+
177
+ The amount of heap memory in bytes that is committed for the Java virtual machine to use. This amount of memory is
178
+ guaranteed for the Java virtual machine to use.
179
+
180
+ [float]
181
+ [[metric-jvm.memory.non_heap.used]]
182
+ ==== `jvm.memory.non_heap.used`
183
+
184
+ * *Type:* Long
185
+ * *Format:* Bytes
186
+
187
+ The amount of used non-heap memory in bytes.
188
+
189
+ [float]
190
+ [[metric-jvm.memory.non_heap.committed]]
191
+ ==== `jvm.memory.non_heap.committed`
192
+
193
+ * *Type:* Long
194
+ * *Format:* Bytes
195
+
196
+ The amount of non-heap memory in bytes that is committed for the Java virtual machine to use. This amount of memory is
197
+ guaranteed for the Java virtual machine to use.
198
+
199
+ [float]
200
+ [[metric-jvm.memory.non_heap.max]]
201
+ ==== `jvm.memory.non_heap.max`
202
+
203
+ * *Type:* Long
204
+ * *Format:* Bytes
205
+
206
+ The maximum amount of non-heap memory in bytes that can be used for memory management. If the maximum memory size is
207
+ undefined, the value is -1.
208
+
209
+ [float]
210
+ [[metric-jvm.memory.heap.pool.used]]
211
+ ==== `jvm.memory.heap.pool.used`
212
+
213
+ * *Type:* Long
214
+ * *Format:* Bytes
215
+
216
+ The amount of used memory in bytes of the memory pool.
217
+
218
+ [float]
219
+ [[metric-jvm.memory.heap.pool.committed]]
220
+ ==== `jvm.memory.heap.pool.committed`
221
+
222
+ * *Type:* Long
223
+ * *Format:* Bytes
224
+
225
+ The amount of memory in bytes that is committed for the memory pool. This amount of memory is guaranteed for this
226
+ specific pool.
227
+
228
+ [float]
229
+ [[metric-jvm.memory.heap.pool.max]]
230
+ ==== `jvm.memory.heap.pool.max`
231
+
232
+ * *Type:* Long
233
+ * *Format:* Bytes
234
+
235
+ The maximum amount of memory in bytes that can be used for the memory pool.
@@ -28,6 +28,10 @@ module ElasticAPM
28
28
  @platform ||= Gem::Platform.local.os.to_sym
29
29
  end
30
30
 
31
+ def self.os
32
+ @platform ||= RbConfig::CONFIG.fetch('host_os', 'unknown').to_sym
33
+ end
34
+
31
35
  # @api private
32
36
  class Registry
33
37
  include Logging
@@ -37,6 +41,7 @@ module ElasticAPM
37
41
  def initialize(config, &block)
38
42
  @config = config
39
43
  @callback = block
44
+ @sets = nil
40
45
  end
41
46
 
42
47
  attr_reader :config, :sets, :callback
@@ -51,14 +56,22 @@ module ElasticAPM
51
56
 
52
57
  # Only set the @sets once, in case we stop
53
58
  # and start again.
54
- @sets ||= {
55
- system: CpuMemSet,
56
- vm: VMSet,
57
- breakdown: BreakdownSet,
58
- transaction: TransactionSet
59
- }.each_with_object({}) do |(key, kls), sets|
60
- debug "Adding metrics collector '#{kls}'"
61
- sets[key] = kls.new(config)
59
+ if @sets.nil?
60
+ sets = {
61
+ system: CpuMemSet,
62
+ vm: VMSet,
63
+ breakdown: BreakdownSet,
64
+ transaction: TransactionSet
65
+ }
66
+ if defined?(JVMSet)
67
+ debug "Enabling JVM metrics collection"
68
+ sets[:jvm] = JVMSet
69
+ end
70
+
71
+ @sets = sets.each_with_object({}) do |(key, kls), _sets_|
72
+ debug "Adding metrics collector '#{kls}'"
73
+ _sets_[key] = kls.new(config)
74
+ end
62
75
  end
63
76
 
64
77
  @timer_task = Concurrent::TimerTask.execute(
@@ -136,6 +149,7 @@ require 'elastic_apm/metrics/set'
136
149
 
137
150
  require 'elastic_apm/metrics/cpu_mem_set'
138
151
  require 'elastic_apm/metrics/vm_set'
152
+ require 'elastic_apm/metrics/jvm_set' if defined?(JRUBY_VERSION)
139
153
  require 'elastic_apm/metrics/span_scoped_set'
140
154
  require 'elastic_apm/metrics/transaction_set'
141
155
  require 'elastic_apm/metrics/breakdown_set'
@@ -62,8 +62,8 @@ module ElasticAPM
62
62
  def initialize(config)
63
63
  super
64
64
 
65
- @sampler = sampler_for_platform(Metrics.platform)
66
- read! # set @previous on boot
65
+ @sampler = sampler_for_os(Metrics.os)
66
+ read! # set initial values to calculate deltas from
67
67
  end
68
68
 
69
69
  attr_reader :config
@@ -75,11 +75,11 @@ module ElasticAPM
75
75
 
76
76
  private
77
77
 
78
- def sampler_for_platform(platform)
79
- case platform
78
+ def sampler_for_os(os)
79
+ case os
80
80
  when :linux then Linux.new
81
81
  else
82
- warn "Disabling system metrics, unsupported platform '#{platform}'"
82
+ warn "Disabling system metrics, unsupported host OS '#{os}'"
83
83
  disable!
84
84
  nil
85
85
  end
@@ -0,0 +1,88 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+ #
18
+ # frozen_string_literal: true
19
+
20
+ require 'java'
21
+
22
+ module ElasticAPM
23
+ module Metrics
24
+ # @api private
25
+ class JVMSet < Set
26
+ include Logging
27
+
28
+ MAX_TRIES = 3
29
+
30
+ def initialize(*args)
31
+ super
32
+
33
+ @error_count = 0
34
+ end
35
+
36
+ def collect
37
+ read!
38
+ super
39
+ end
40
+
41
+ def read!
42
+ return if disabled?
43
+
44
+ heap = platform_bean.get_heap_memory_usage
45
+ non_heap = platform_bean.get_non_heap_memory_usage
46
+
47
+ gauge(:"jvm.memory.heap.used").value = heap.get_used
48
+ gauge(:"jvm.memory.heap.committed").value = heap.get_committed
49
+ gauge(:"jvm.memory.heap.max").value = heap.get_max
50
+
51
+ gauge(:"jvm.memory.non_heap.used").value = non_heap.get_used
52
+ gauge(:"jvm.memory.non_heap.committed").value = non_heap.get_committed
53
+ gauge(:"jvm.memory.non_heap.max").value = non_heap.get_max
54
+
55
+ pool_beans.each do |bean|
56
+ next unless bean.type.name == "HEAP"
57
+
58
+ tags = { name: bean.get_name }
59
+
60
+ gauge(:"jvm.memory.heap.pool.used", tags: tags).value = bean.get_usage.get_used
61
+ gauge(:"jvm.memory.heap.pool.committed", tags: tags).value = bean.get_usage.get_committed
62
+ gauge(:"jvm.memory.heap.pool.max", tags: tags).value = bean.get_usage.get_max
63
+ end
64
+ rescue Exception => e
65
+ error("JVM metrics encountered error: %s", e)
66
+ debug("Backtrace:") { e.backtrace.join("\n") }
67
+
68
+ @error_count += 1
69
+ if @error_count >= MAX_TRIES
70
+ disable!
71
+ error("Disabling JVM metrics after #{MAX_TRIES} errors", e)
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ def platform_bean
78
+ @platform_bean ||= java.lang.management.ManagementFactory.getPlatformMXBean(
79
+ java.lang.management.MemoryMXBean.java_class
80
+ )
81
+ end
82
+
83
+ def pool_beans
84
+ @pool_beans ||= java.lang.management.ManagementFactory.getMemoryPoolMXBeans()
85
+ end
86
+ end
87
+ end
88
+ end
@@ -18,5 +18,5 @@
18
18
  # frozen_string_literal: true
19
19
 
20
20
  module ElasticAPM
21
- VERSION = '4.2.0'
21
+ VERSION = '4.3.0'
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Malmberg
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-07 00:00:00.000000000 Z
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
- description:
41
+ description:
42
42
  email:
43
43
  - mikkel@elastic.co
44
44
  executables: []
@@ -165,6 +165,7 @@ files:
165
165
  - lib/elastic_apm/metrics.rb
166
166
  - lib/elastic_apm/metrics/breakdown_set.rb
167
167
  - lib/elastic_apm/metrics/cpu_mem_set.rb
168
+ - lib/elastic_apm/metrics/jvm_set.rb
168
169
  - lib/elastic_apm/metrics/metric.rb
169
170
  - lib/elastic_apm/metrics/set.rb
170
171
  - lib/elastic_apm/metrics/span_scoped_set.rb
@@ -257,7 +258,7 @@ licenses:
257
258
  - Apache-2.0
258
259
  metadata:
259
260
  source_code_uri: https://github.com/elastic/apm-agent-ruby
260
- post_install_message:
261
+ post_install_message:
261
262
  rdoc_options: []
262
263
  require_paths:
263
264
  - lib
@@ -272,8 +273,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
273
  - !ruby/object:Gem::Version
273
274
  version: '0'
274
275
  requirements: []
275
- rubygems_version: 3.0.3.1
276
- signing_key:
276
+ rubygems_version: 3.0.6
277
+ signing_key:
277
278
  specification_version: 4
278
279
  summary: The official Elastic APM agent for Ruby
279
280
  test_files: []