Module: Monus::BuiltInMetric::EmThreadpool

Extended by:
EmThreadpool
Included in:
EmThreadpool
Defined in:
lib/monus/built_in_metrics/em_threadpool.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/monus/built_in_metrics/em_threadpool.rb', line 2

def activate
  @interval = Monus.options.dig(:em_threadpool_metric_options, :interval) || 1

  threadpool = nil

  Monus.engine.every @interval do
    threadpool ||= EM.send(:instance_variable_get, :@threadpool)

    if threadpool
      by_status = threadpool.group_by(&:status).transform_values(&:size)
      by_status.default = 0

      total = threadpool.size
      run = by_status['run']
      load_percent = run.to_f / total
      broken = total - run - by_status['sleep']

      Monus.write em_threadpool_load: load_percent,
                  em_threadpool_run: run,
                  em_threadpool_total: total,
                  em_threadpool_broken: broken
    end
  end
end