Class: Fintop::ThreadsData

Inherits:
Object
  • Object
show all
Defined in:
lib/fintop/threads.rb

Overview

Container class for data gathered from a Finagle server’s thread-dump endpoint.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(admin_port) ⇒ ThreadsData

Initialize a ThreadsData object for a Finagle server’s on a given port’s “/admin/threads” endpoint.

Parameters:

  • admin_port (Fixnum)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fintop/threads.rb', line 18

def initialize(admin_port)
  json_str = Net::HTTP.get(
    URI.parse("http://localhost:#{admin_port}/admin/threads")
  )

  @threads = JSON.parse(json_str)['threads'].to_a
  @num_threads = @threads.size

  @num_runnable = @threads.count { |tid, thread|
    thread['state'] == 'RUNNABLE'
  }

  @num_waiting = @threads.count { |tid, thread|
    thread['state'] == 'WAITING'
  }

  @num_timed_waiting = @threads.count { |tid, thread|
    thread['state'] == 'TIMED_WAITING'
  }

  @num_non_daemon = @threads.count { |tid, thread|
    thread['daemon'] == false
  }
end

Instance Attribute Details

#num_non_daemonObject (readonly)

Returns the value of attribute num_non_daemon.



12
13
14
# File 'lib/fintop/threads.rb', line 12

def num_non_daemon
  @num_non_daemon
end

#num_runnableObject (readonly)

Returns the value of attribute num_runnable.



9
10
11
# File 'lib/fintop/threads.rb', line 9

def num_runnable
  @num_runnable
end

#num_threadsObject (readonly)

Returns the value of attribute num_threads.



8
9
10
# File 'lib/fintop/threads.rb', line 8

def num_threads
  @num_threads
end

#num_timed_waitingObject (readonly)

Returns the value of attribute num_timed_waiting.



11
12
13
# File 'lib/fintop/threads.rb', line 11

def num_timed_waiting
  @num_timed_waiting
end

#num_waitingObject (readonly)

Returns the value of attribute num_waiting.



10
11
12
# File 'lib/fintop/threads.rb', line 10

def num_waiting
  @num_waiting
end