Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jderrett on github.
  • I am jdirt (https://keybase.io/jdirt) on keybase.
  • I have a public key ASApU96LyfxAE9Wlm1lS8FMvxieJnyo0E1H8m44eYRRTpwo

To claim this, I am signing this object:

@jderrett
jderrett / getLambdaSourceCode.sh
Last active January 18, 2024 19:18
Bash script to download Lambda function source code to zip files via AWS CLI assuming credentials and assuming jq is installed
#!/bin/bash
# Script to download AWS Lambda function code to zip files
# This assumes that AWS CLI, curl, and jq are installed
# List all functions in your account
for fnName in $( aws lambda list-functions | jq -r '.Functions[].FunctionName' ); do
# Get code location (zip file format)
codeLocation=$( aws lambda get-function --function-name $fnName | jq -r '.Code.Location' )
# echo codeLocation: $codeLocation
# Actually download the code (zip file)
fileName="$fnName.zip"
@jderrett
jderrett / readme.md
Last active August 16, 2017 20:47
python readme scratch

python-librato

Build Status

A Python wrapper for the Librato Metrics API.

Source-based Librato Users

NOTE: Starting in version 3, we have deprecated Dashboards and Instruments in favor of Spaces and Charts.

@jderrett
jderrett / copy_librato_space.rb
Last active August 30, 2017 19:05
Copy a Librato Space from one account to another (or same account)
require 'faraday'
require 'faraday_middleware'
require 'json'
require 'pry'
class SpacesApi
LIBRATO_API = 'https://metrics-api.librato.com'
LIBRATO_API_VERSION = 'v1'
ENDPOINT = [LIBRATO_API, LIBRATO_API_VERSION].join('/')
@jderrett
jderrett / copy_librato_dashboard.rb
Created February 29, 2016 19:32
Copy Librato Dashboard from one account to another
require 'faraday'
require 'faraday_middleware'
require 'json'
class DashboardApi
LIBRATO_API = 'https://metrics-api.librato.com'
LIBRATO_API_VERSION = 'v1'
ENDPOINT = [LIBRATO_API, LIBRATO_API_VERSION].join('/')
attr_accessor :username
@jderrett
jderrett / take_librato_snapshot.rb
Last active May 17, 2017 20:35
Ruby script to take a snapshot of a Librato chart
#!/usr/bin/env ruby
require 'faraday'
require 'json'
conn = Faraday.new(url: "https://metrics-api.librato.com/v1/") do |f|
f.basic_auth ENV['LIBRATO_USER'], ENV['LIBRATO_TOKEN']
# f.response :logger
f.adapter Faraday.default_adapter
end
@jderrett
jderrett / update_chart_streams.py
Created October 16, 2015 17:06
Update the source on all streams inside a set of Librato Spaces
import requests, json
username = 'me@example.com
token = 'abcd1234'
api = "https://metrics-api.librato.com"
# Find spaces
search = 'string to search'
url = api + "/v1/spaces?name=%s" % search
@jderrett
jderrett / librato_find_ec2_low_cpu.py
Created August 26, 2015 02:00
Find Librato EC2 CPUUtilization where box is below a threshold for a certain amount of time
import librato
username = 'foo@example.com'
token = '1234abcd'
api = librato.connect(username, token)
metric_name = 'AWS.EC2.CPUUtilization'
source = '*' # Use source name or display name here to filter stuff
@jderrett
jderrett / librato_get_alert_status.rb
Last active September 23, 2015 22:09
Get Librato Alerts with Status and optionally clear triggered alerts
require 'librato/metrics'
require 'json'
c = Librato::Metrics
c.authenticate 'you@example.com', 'token'
alerts = JSON.parse(c.connection.get('/v1/alerts?version=2').body)['alerts']
alert_ids = alerts.map {|a| a['id']}
show_ok_alerts = true
@jderrett
jderrett / get_all_measurements.rb
Last active August 29, 2015 14:21
Get N measurements for a Librato metric using the Ruby wrapper (and do some calcs)
require 'librato/metrics'
Librato::Metrics.authenticate 'justin@example.com', 'token'
months_ago = 2
metric_name = 'AWS.EC2.CPUUtilization'
resolution = 84600 # Daily
source_matcher = "us-east-1*" # Set to nil for all sources
next_time = Time.now.to_i - (months_ago * 730 * 3600)