Last active
February 18, 2017 02:01
-
-
Save eugeneius/9fe6e5c3aa9f9461a00a9b2a1fc76f6a to your computer and use it in GitHub Desktop.
Open a Pry session and examine Datadog dashboard and monitors.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'thor' | |
require 'dogapi' | |
require 'pry' | |
class DatadogPry < Thor | |
DatadogDashboard = Struct.new(:name, :queries) | |
DatadogMonitor = Struct.new(:name, :queries) | |
option :api_key, required: true | |
option :application_key, required: true | |
desc "cli", "Open a pry console to inspect dashboards and monitors" | |
def cli | |
Pry.config.should_load_plugins = false | |
binding.pry | |
; # required for pry to work | |
end | |
no_commands do | |
def client | |
Dogapi::Client.new(options[:api_key], options[:application_key]) | |
end | |
def dashboards | |
@dashboards ||= client.get_dashboards.last['dashes'].map { |d| d['id'] }.map do |dashboard_id| | |
dashboard = client.get_dashboard(dashboard_id).last['dash'] | |
queries = dashboard['graphs'].flat_map do |g| | |
g['definition']['requests'] | |
end.map { |r| r['q'] } | |
DatadogDashboard.new(dashboard['title'], queries) | |
end | |
end | |
def monitors | |
@monitors ||= client.get_all_monitors.last.map { |m| DatadogMonitor.new(m['name'], [m['query']]) } | |
end | |
end | |
end | |
DatadogPry.start(ARGV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment