Skip to content

Instantly share code, notes, and snippets.

View samuel's full-sized avatar

Samuel Stauffer samuel

View GitHub Profile
@samuel
samuel / backup.py
Created November 8, 2010 22:42
A script to automate freezing XFS and locking MongoDB and snapshotting EBS volumes
#!/usr/bin/env python
from __future__ import with_statement
import contextlib
import logging
import os
import sys
import urllib2
from boto.ec2.connection import EC2Connection
@samuel
samuel / pagerduty_munin.py
Created November 30, 2010 00:48
PagerDuty script for Munin
#!/usr/bin/env python
try:
import json
except ImportError:
import simplejson as json
import sys
from pagerduty import PagerDuty
def parse(txt):
@samuel
samuel / kafka_simple_consumer.py
Created December 2, 2010 22:59
Simple consumer example in Jython for Kafka
#!/usr/bin/env jython
import os
import sys
sys.path.extend(["lib/"+x for x in os.listdir("lib") if x.endswith('.jar')])
sys.path.extend(["dist/"+x for x in os.listdir("dist") if x.endswith('.jar')])
import jarray
from kafka.api import FetchRequest
from kafka.consumer import SimpleConsumer
@samuel
samuel / supervisor-errmail.py
Created December 17, 2010 02:50
Supervisor event listener that emails on a proces writing to stderr
#!/usr/bin/env python
import os
import smtplib
import sys
import time
from optparse import OptionParser
from supervisor import childutils
#!/usr/bin/env python
from __future__ import division
import os
import sys
import time
def seconds_to_hms(sec):
return "%d:%.2d:%.2d" % (sec // (60*60), sec // 60 % 60, sec % 60)
@samuel
samuel / logstats.py
Created March 8, 2011 18:51
Log file tailer to send events to statsd
#!/usr/bin/env python
from __future__ import with_statement
import random
import re
import select
import socket
import time
from optparse import OptionParser
@samuel
samuel / memcached-tool.py
Created March 23, 2011 00:56
Memcached introspection
#!/usr/bin/env python
from __future__ import division
import socket
class LineSocket(object):
def connect(self, host, port):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((host, port))
@samuel
samuel / regex-service.py
Created May 17, 2011 00:17
Regular expression search and replace as an OS X service
#!/usr/bin/env python
import re
import sys
import subprocess
def osascript(script):
p = subprocess.Popen("osascript", stdout=subprocess.PIPE, stdin=subprocess.PIPE)
stdout = p.communicate(script)[0]
if p.returncode != 0:
@samuel
samuel / check_redis.py
Last active October 19, 2019 11:16
Redis health and memory check for Nagios
#!/usr/bin/python
#
# LICENSE: MIT
#
# Copyright (C) 2014 Samuel Stauffer
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation
@samuel
samuel / gotestcolorize.py
Created December 6, 2013 00:31
Go test colorizer
#!/usr/bin/env python
import sys
COLOR_BRIGHT_WHITE = "\033[1;97m"
COLOR_BOLD_RED = "\033[1;31m"
COLOR_GREEN = "\033[0;32m"
COLOR_YELLOW = "\033[0;33m"
COLOR_NORMAL = "\033[0m"
CHECK_MARK = "\xe2\x9c\x93"