Class: Atatus::Metrics::JVMSet Private

Inherits:
Set
  • Object
show all
Includes:
Logging
Defined in:
lib/atatus/metrics/jvm_set.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

MAX_TRIES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

3

Constants included from Logging

Logging::LEVELS, Logging::PREFIX

Constants inherited from Set

Set::DISTINCT_LABEL_LIMIT

Instance Attribute Summary

Attributes inherited from Set

#metrics

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Methods inherited from Set

#counter, #disable!, #disabled?, #gauge, #metric, #timer

Constructor Details

#initialize(*args) ⇒ JVMSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of JVMSet.



30
31
32
33
34
# File 'lib/atatus/metrics/jvm_set.rb', line 30

def initialize(*args)
  super

  @error_count = 0
end

Instance Method Details

#collectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
39
# File 'lib/atatus/metrics/jvm_set.rb', line 36

def collect
  read!
  super
end

#read!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/atatus/metrics/jvm_set.rb', line 41

def read!
  return if disabled?

  heap = platform_bean.get_heap_memory_usage
  non_heap = platform_bean.get_non_heap_memory_usage

  gauge(:"jvm.memory.heap.used").value = heap.get_used
  gauge(:"jvm.memory.heap.committed").value = heap.get_committed
  gauge(:"jvm.memory.heap.max").value = heap.get_max

  gauge(:"jvm.memory.non_heap.used").value = non_heap.get_used
  gauge(:"jvm.memory.non_heap.committed").value = non_heap.get_committed
  gauge(:"jvm.memory.non_heap.max").value = non_heap.get_max

  pool_beans.each do |bean|
    next unless bean.type.name == "HEAP"

    tags = { name: bean.get_name }

    gauge(:"jvm.memory.heap.pool.used", tags: tags).value = bean.get_usage.get_used
    gauge(:"jvm.memory.heap.pool.committed", tags: tags).value = bean.get_usage.get_committed
    gauge(:"jvm.memory.heap.pool.max", tags: tags).value = bean.get_usage.get_max
  end
rescue Exception => e
  error("JVM metrics encountered error: %s", e)
  debug("Backtrace:") { e.backtrace.join("\n") }

  @error_count += 1
  if @error_count >= MAX_TRIES
    disable!
    error("Disabling JVM metrics after #{MAX_TRIES} errors", e)
  end
end