Class: RailsOrbit::Kamal::StatsCollector

Inherits:
Object
  • Object
show all
Includes:
SSHKit::DSL
Defined in:
lib/rails_orbit/kamal/stats_collector.rb

Instance Method Summary collapse

Instance Method Details

#collect(host:, user:, ssh_key_path:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rails_orbit/kamal/stats_collector.rb', line 6

def collect(host:, user:, ssh_key_path:)
  require "sshkit"
  require "sshkit/dsl"

  output = nil
  on(SSHKit::Host.new("#{user}@#{host}")) do
    output = capture(:docker, "stats", "--no-stream", "--format",
                     "{{.Name}} {{.CPUPerc}} {{.MemPerc}}")
  end
  parse(output, host: host)
rescue SSHKit::Command::Failed, SocketError => e
  Rails.logger.error "[rails_orbit] SSH stats failed for #{host}: #{e.message}"
  []
rescue => e
  Rails.logger.error "[rails_orbit] SSH stats failed for #{host}: #{e.class} - #{e.message}"
  []
end