Created
December 17, 2018 07:55
-
-
Save guycall/f7d9ff92099db11cff36c667f87f0bd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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