Skip to content

Instantly share code, notes, and snippets.

@jderrett
jderrett / VI and tab completion irb bindings OSX
Created October 15, 2009 01:45
.editrc file for irb vi bindings and tab completion
# ~/.editrc
bind -v
bind \\t rl_complete
@jderrett
jderrett / librato_source_counter.rb
Last active August 29, 2015 14:04
librato_source_counter.rb
require 'librato/metrics'
# Estimate the number of sources for each metric
Librato::Metrics.authenticate 'my-email@example.com', 'api token'
Librato::Metrics.metrics.each do |m|
# Grab last 4 hours at hourly resolution
puts [m['name'], Librato::Metrics.get_measurements(m['name'], resolution: 3600, count: 4).keys.size]
end
@jderrett
jderrett / librato_chart_example.html
Last active August 29, 2015 14:04
librato_chart_example.html
<!DOCTYPE html>
<head>
<!-- They'll need there own version of jquery or whatever -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://sdk.librato.com/librato-sdk-v0.5.1-min.js"></script>
</head>
<body>
<div id="thegraph">
</div>
var express = require('express')
var app = express();
var librato = require('librato-node')
var sleep = require('sleep')
librato.configure({
email: 'me@example.com',
token: 'abc1234',
@jderrett
jderrett / copy_librato_instrument.rb
Last active August 29, 2015 14:15
Copy a Librato instrument
#!/usr/bin/env ruby
require 'faraday'
require 'faraday_middleware'
require 'json'
require 'pry'
class LibratoApi
ENDPOINT = 'https://metrics-api.librato.com/v1'
@jderrett
jderrett / librato_active_alerts.sh
Last active August 29, 2015 14:16
Librato active alerts with service counts (using jq)
# Required:
# http://stedolan.github.io/jq/
# brew install jq
LIBRATO_USER="justin@example.com"
LIBRATO_TOKEN="<your api token>"
LIBRATO_AUTH="$LIBRATO_USER:$LIBRATO_TOKEN"
ALERTS_ENDPOINT="https://metrics-api.librato.com/v1/alerts?version=2"
@jderrett
jderrett / librato_api.sh
Last active August 29, 2015 14:16
Grab last N hours from Librato API using httpie and jq
HOURS_BACK=3
http GET https://metrics-api.librato.com/v1/metrics \
compose='s("AWS.EC2.CPUUtilization", "*", {period: "3600"})' \
resolution=3600 \
start_time=$(echo "$(date +'%s')-$HOURS_BACK*3600" | bc) \
| jq '[.measurements[].series[]]'
@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)
@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 / 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