Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include GC.stat metrics for each puma process #18

Open
liaden opened this issue Mar 15, 2021 · 0 comments
Open

Include GC.stat metrics for each puma process #18

liaden opened this issue Mar 15, 2021 · 0 comments

Comments

@liaden
Copy link

liaden commented Mar 15, 2021

Goal

For a preloaded puma application, I'd like to capture GC.stat with an index tag applied based on which puma child process (and some default value for the parent process).

Opening an issue to at least share my experience and approach incase it helps others.

Solution (within Rails app)

I defined a puma plugin:

Puma::Plugin.create do
  # 1. configure yabeda puma plugin
  # 2. override the index tag value that is done in the Yabeda.configure block
  # 3. spin up background thread to collect ruby process metrics for forked workers
  def start(launcher)
    launcher.config.configure do |puma_config|
      # add yabeda plugin (these couple of lines aren't that relevant)
      puma_config.activate_control_app
      puma_config.plugin :yabeda

      if launcher.options[:workers] > 0
        puma_config.on_worker_boot do |worker_index|
          Yabeda.default_tag :index, worker_index

          Thread.new do
            labels = {}

            loop do
              sleep 1

              Yabeda.thread_count.set(labels, Thread.list.select(&:alive?).size)

              GC.stat.each do |key, value|
                Yabeda.send("ruby_vm_stats_#{key}").set(labels, value)
              end
            end
          end
        end

        Yabeda.default_tag :index, -1
      else
        Yabeda.default_tag :index, 0
      end
    end
  end
end

Additionally, added a default_tag to the yabeda configure block.

For the stats to be available from the parent process, we are using the direct file storage as recommended here.

Alternative

Update https://github.com/ianks/yabeda-gc/ to handle this. It may be more suitable given things such as sidekiq swarm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant