Skip to content

Instantly share code, notes, and snippets.

@guycall
Created December 17, 2018 07:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guycall/f7d9ff92099db11cff36c667f87f0bd7 to your computer and use it in GitHub Desktop.
Save guycall/f7d9ff92099db11cff36c667f87f0bd7 to your computer and use it in GitHub Desktop.
module PumaCapacityToCloudwatch
require 'puma_capacity_to_cloudwatch/utilization'
require 'puma_capacity_to_cloudwatch/publish'
class Error < StandardError; end
def self.run
sleep 10 # wait for puma to boot up
return unless defined?(Puma)
Thread.new do
started_at = Time.current
stats_samples = []
loop do
begin
stats_samples << Utilization.new(Puma.stats).utilization
if Time.current > (started_at + 1.minute)
Publish.new(stats_samples).run
started_at = Time.current
stats_samples = []
end
end
sleep 1
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment