Sha256: 0a76dea5ca492439c08c179e61ded85af664e87a84b74ee709b8f7b394852f5f

Contents?: true

Size: 1.21 KB

Versions: 11

Compression:

Stored size: 1.21 KB

Contents

require 'java'

java_import 'java.lang.management.ManagementFactory'

class FrenzyBunnies::Health::Providers::Jvm
  def initialize(opts)
    # init beans
    @opts = opts
    @memorymx = ManagementFactory.memory_mx_bean
    @threadmx = ManagementFactory.thread_mx_bean
    @threadmx_thread_info = @threadmx.java_method :getThreadInfo, [Java::long, Java::int]
    @runtimemx = ManagementFactory.runtime_mx_bean
  end

  def report
    h = {}
    heap = @memorymx.heap_memory_usage
    h[:heap_usage_used_bytes] = heap.used
    h[:heap_usage_max_bytes] = heap.max
    h[:heap_usage_committed_bytes] = heap.committed
    h[:heap_usage_human] = heap.to_s

    h[:jvm_uptime_ms] = @runtimemx.uptime

    ids = @threadmx.all_thread_ids
    h[:threads] = ids.map do |id|
      info = @threadmx_thread_info.call(id, 10)
      if info && info.thread_name =~ @opts[:threadfilter]
        {
          :name => info.thread_name,
          :stack_trace => info.stack_trace.to_a.inject([]){|a,s| a<<s.to_s },
          :state => info.thread_state.to_s
        }
      else
        nil
      end
    end.compact

    ids.map{|i| @threadmx_thread_info.call(i, 10) }.compact.map {|inf| inf.stack_trace.to_a.inject([]){|a,s| a<<s.to_s }}
    
    h
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
boardintel_frenzy_bunnies-0.0.17-java lib/frenzy_bunnies/health/providers/jvm.rb
boardintel_frenzy_bunnies-0.0.16 lib/frenzy_bunnies/health/providers/jvm.rb
boardintel_frenzy_bunnies-0.0.15 lib/frenzy_bunnies/health/providers/jvm.rb
boardintel_frenzy_bunnies-0.0.14 lib/frenzy_bunnies/health/providers/jvm.rb
boardintel_frenzy_bunnies-0.0.13 lib/frenzy_bunnies/health/providers/jvm.rb
boardintel_frenzy_bunnies-0.0.12 lib/frenzy_bunnies/health/providers/jvm.rb
boardintel_frenzy_bunnies-0.0.11 lib/frenzy_bunnies/health/providers/jvm.rb
boardintel_frenzy_bunnies-0.0.9 lib/frenzy_bunnies/health/providers/jvm.rb
frenzy_bunnies-0.0.8 lib/frenzy_bunnies/health/providers/jvm.rb
frenzy_bunnies-0.0.7 lib/frenzy_bunnies/health/providers/jvm.rb
frenzy_bunnies-0.0.6 lib/frenzy_bunnies/health/providers/jvm.rb