Skip to content

Instantly share code, notes, and snippets.

View zastari's full-sized avatar

Tyler Mitchell zastari

View GitHub Profile
@zastari
zastari / multigroup.py
Last active May 4, 2018 01:22
groupby + rollup for namedtuples
def multigroup(entries, items=None, groups=None, rollup=True):
"""Object grouping with multiple groups that supports optional rollup
:arg entries: A list of objects that supports `getattr` for each field in `items`
:arg items: Attribute fields to retrieve from entry namedtuples
:arg groups: Attribute fields to group by
:arg rollup: Whether to put common fields in a group in "_rollup"
:type entries: list
:type items: list or None
:type groups: list or None
:type rollup: bool
#!/bin/bash
# Estimate time to slave replication recovery using an accumulated average
time_interval=60
samples=0
delay_moving_average=0
delay="$(mysql -e 'SHOW SLAVE STATUS\G' | awk '/Seconds_Behind_Master:/ {print $2}')"
echo "Initial replication delay: ${delay} seconds. Polling recovery rate every ${time_interval} seconds."
@zastari
zastari / mts.sh
Last active August 29, 2015 14:27
#!/bin/bash
# Manage slave threads in a Multi-threaded slave without GTID
# Author: Tyler Mitchell
# Usage: mts.sh (disable|enable)
worker_file=/root/mts/slave_parallel_workers.count
# Function slave_sql_thread. Controls the running state of the Slave SQL_THREAD
# Args:
# $1: (stop|start|sync) [required]
#!/bin/bash
# refresh.sh - Quickly deploy some cloud servers on which to run playbooks
#
# Requires: rackspace-cli ( http://rackspace-cli.readthedocs.org/ )
# Usage: refresh.sh (create|destroy)
#
# Variables are read from this script instead of argv. Edit them until
# they match your environment
#
# BUG (possibly in rackspace-cli): Using --image-id with a custom image id
#!/bin/bash
#
# Usage: ${name} stop|start|status|help
#
# Manages an SSH tunnel between two servers. This script uses SSH sockets
# to multiplex a forwarded connection and allow interactive control of
# the tunnel
name="$(basename "${0}")"
#!/usr/bin/python
import pyrax
import ConfigParser
import sys
import getopt
class Config(ConfigParser.ConfigParser):
def __getitems__(self, section):
try:
@zastari
zastari / python-mysql-repl-monitor
Last active December 14, 2015 15:39
A basic MySQL replication monitor using python-bottle
#!/usr/bin/python
"""
python-bottle based MySQL replication monitor.
Configuration is specified via [server:<server_name>] and [bottle] directives
in /etc/rack_replmon/monitor.conf. The monitor will parse any entry that
begins with ^server as directives for a server to scan
Valid [server:<server_name>] directives:
host, port, user, passwd