zombocom / puma_worker_killer

Automatically restart Puma cluster workers based on max RAM available
748 stars 77 forks source link

Adds `on_calculation` callback. #51

Closed tobypinder closed 5 years ago

tobypinder commented 7 years ago

Description

See discussion on #50

Adds on_calculation callback which can be used to perform custom functionality every time PWK calculates memory usage. The configured lambda receives the memory used in megabytes as an argument.

Usage

An example usage in the config is

config.on_calculation = ->(mb) do
  puts "Memory usage: #{mb}"
end

which works similar to the default reaper_status_logs. In my case, I can use this function to record application usage to eg Datadog

# Before: statsd = Datadog::Statsd.new('localhost', 8125) or whatever

config.on_calculation = ->(mb) do
  statsd.histogram('puma.memory_usage', mb)
end

This principle extends to any logging/monitoring solutions.

tobypinder commented 5 years ago

Any interest in this? We've been using it in production for over a year without issues on our PR fork.

We used it to publish metrics to Datadog as mentioned in the example above - this proves useful for alerting / monitoring etc

Datadog

schneems commented 5 years ago

Thanks!