Module: Pgbus::CLI::Dashboard
- Defined in:
- lib/pgbus/cli/dashboard.rb
Overview
Prints the vendored AppSignal dashboard definitions as import-ready
JSON. The files ship in the automated-dashboard format used by
appsignal/public_config (a metric_keys trigger wrapping a
dashboard object); AppSignal's "Import dashboard" dialog wants the
inner object only, so this command unwraps it:
pgbus dashboard # main dashboard
pgbus dashboard health # one of the extra dashboards
pgbus dashboard --list # available names and titles
Class Method Summary collapse
-
.available ⇒ Object
The main dashboard plus the extras, keyed by their short CLI name (pgbus_health.json => "health").
- .definition(path) ⇒ Object
- .list ⇒ Object
- .start(args) ⇒ Object
Class Method Details
.available ⇒ Object
The main dashboard plus the extras, keyed by their short CLI name (pgbus_health.json => "health").
40 41 42 43 44 45 46 47 |
# File 'lib/pgbus/cli/dashboard.rb', line 40 def available require "pgbus/integrations/appsignal" extras = Dir[File.join(Integrations::Appsignal::DASHBOARDS_DIR, "*.json")].to_h do |path| [File.basename(path, ".json").delete_prefix("pgbus_"), path] end { "main" => Integrations::Appsignal::DASHBOARD_PATH }.merge(extras) end |
.definition(path) ⇒ Object
49 50 51 |
# File 'lib/pgbus/cli/dashboard.rb', line 49 def definition(path) JSON.parse(File.read(path)).fetch("dashboard") end |
.list ⇒ Object
32 33 34 35 36 |
# File 'lib/pgbus/cli/dashboard.rb', line 32 def list available.each do |name, path| puts format("%-12s %s", name, definition(path)["title"]) end end |
.start(args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pgbus/cli/dashboard.rb', line 19 def start(args) name = args.first || "main" return list if ["--list", "list"].include?(name) path = available[name] unless path warn "Unknown dashboard: #{name.inspect} (available: #{available.keys.join(", ")})" exit 1 end puts JSON.pretty_generate(definition(path)) end |