Skip to content

Instantly share code, notes, and snippets.

@gaffneyc
Created February 15, 2024 13:57
Show Gist options
  • Save gaffneyc/86556b98e0dc1bcc757bbe6e891b21a6 to your computer and use it in GitHub Desktop.
Save gaffneyc/86556b98e0dc1bcc757bbe6e891b21a6 to your computer and use it in GitHub Desktop.
Check Fly.io standby status
require "json"
require "terminal-table"
fly_app = ARGV[0]
if fly_app.nil?
warn "Usage: check.rb [fly app name]"
exit 1
end
Machine = Struct.new(:config) do
def process
pg = config.dig("config", "env", "FLY_PROCESS_GROUP")
standby? ? "#{pg}†" : pg
end
def id = config["id"]
def region = config["region"]
def primary_id = config.dig("config", "standbys", 0)
def standby? = !primary_id.nil?
def autoscale? = config.dig("config", "services")&.any? { |s| s["autostop"] }
end
def red(txt) = "\033[31;40m#{txt}\033[0m"
def green(txt) = "\033[32;32m#{txt}\033[0m"
machines =
JSON.parse(`fly m list -a "#{fly_app}" -j`)
.map { |c| [ c["id"], Machine.new(c) ] }
.to_h
table = Terminal::Table.new do |t|
t << [ "Process", "ID", "Region", "Primary", "Standby"]
t << :separator
machines.each_value.lazy.sort_by(&:process).each do |m|
standbys = machines.each_value
.select { |v| v.primary_id == m.id }
.map(&:id)
.join(", ")
.strip
t << [
m.process,
m.id,
m.region,
m.standby? && machines.key?(m.primary_id) ? green(m.primary_id) : red(m.primary_id),
if standbys.empty?
m.primary_id || m.autoscale? ? "" : red(" MISSING ")
else
green(standbys)
end,
]
end
end
puts table
+------------+----------------+--------+----------------+----------------+
| Process | ID | Region | Primary | Standby |
+------------+----------------+--------+----------------+----------------+
| kafka | aeec27dd0eeb0c | iad | | MISSING |
| kafka | 080e7b96d82fbf | iad | | MISSING |
| kafka | ffc6b3e9241458 | iad | | 94e732e6e3f749 |
| kafka | ad83014b7a94c7 | iad | | MISSING |
| kafka† | 244e5cf59a3fef | iad | e784e2edced2e8 | |
| kafka† | 5df8824441b64f | ewr | e784e2d4a31d18 | |
| kafka† | 94e732e6e3f749 | iad | 91851d9c44d968 | |
| kafka† | 3e40bfa8a636d8 | iad | 9080e333b12058 | |
| scheduler | 9ddc176f2d3ab5 | iad | | MISSING |
| scheduler† | 24be4471b86e7c | iad | e78492ec1e7e83 | |
| web | 68d321d91a47c9 | iad | | |
| web | 9db081062cbd6d | ewr | | |
| web | d9d5470c3ada8b | ewr | | |
| web | a701a3f1fa7cb1 | iad | | |
| worker | ca5efa47246f91 | iad | | MISSING |
| worker | 9c16502c1ab58e | iad | | MISSING |
| worker | 82b8546fd6ef83 | iad | | MISSING |
| worker | a9800e6cb343fc | iad | | MISSING |
| worker† | a58bd3b158eb3d | iad | 3287436dbdd598 | |
| worker† | 82c1042c253668 | ewr | 4d891146f22568 | |
| worker† | 366e1a996b5aeb | iad | 4d891146f22568 | |
+------------+----------------+--------+----------------+----------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment