Skip to content

Instantly share code, notes, and snippets.

View gmr's full-sized avatar
:octocat:
🐘 🐇 🐍

Gavin M. Roy gmr

:octocat:
🐘 🐇 🐍
View GitHub Profile
@gmr
gmr / timespent_ranking.py
Created January 5, 2012 22:09
Reads in a minecraft server log ranking users by time spent
"""
Minecraft Server Log Time Spent Ranking
"""
__author__ = 'Gavin M. Roy'
__email__ = 'gavinmroy@gmail.com'
__since__ = '2012-01-05'
import datetime
import operator
@gmr
gmr / node_report.erl
Created August 7, 2012 19:14
Get the current runtime state of a RabbitMQ node from the cli in erlang
%% -*- erlang -*-
main(_) ->
net_kernel:start([procount, shortnames]),
{_, Hostname} = inet:gethostname(),
Remote = lists:concat(["rabbit@", Hostname]),
io:format("status report ~s~n", [Remote]),
Node = erlang:list_to_atom(Remote),
MemEts = rpc:call(Node, erlang, memory, [ets]),
MemBinary = rpc:call(Node, erlang, memory, [binary]),
MemProc = rpc:call(Node, erlang, memory, [processes]),
@gmr
gmr / clogger.py
Created January 2, 2013 18:19
Rewrite Cobbler's clogger.py module to be a wrapper for the Python stdlib logging.Logger class while keeping almost the same behavior. Add in a format that provides more traceback information. Note line #39 should be super(Logger, self).__init__(__name__, level) but I was getting a weird exception I did not want to dig into.
"""
Python standard logging doesn't super-intelligent and won't expose filehandles,
which we want. So we're not using it.
Copyright 2009, Red Hat, Inc and Others
Michael DeHaan <michael.dehaan AT gmail>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
@gmr
gmr / whisper-sync.py
Last active January 12, 2017 13:14
Load missing datapoints on a remote graphite instance from the WHISPER_DIR on a graphite instance. Use threads to allow for multiple files to be processed at the same time to improve throughput.
#!/usr/bin/env python
import logging
import os
import random
import requests
import socket
import sys
import threading
import time
import whisper
@gmr
gmr / custom-handler-example.py
Last active September 20, 2016 18:08
Code example from "Become a Logging Expert in 30 Minutes" at PyCon 2013
from logging import handlers
import logging
from tornado import ioloop, web
MAX_SIZE = 10485760 # 10 MB
class BufferedLogHandler(handlers.BufferingHandler):
"""The BufferedLogHandler keeps a rolling buffer of log data in
memory. When the buffer size has been exceeded, the oldest log
@gmr
gmr / 0_simple_publisher.py
Last active December 15, 2015 12:28
A comparison of publishing with rmqid, amqplib and pika
import rmqid
rmqid.publish('amqp://guest:guest@localhost:5672/%2f',
exchange='test',
routing_key='example',
body='Test message')
@gmr
gmr / README.md
Last active April 12, 2020 22:06
Chef + Cobbler Integration files

Note: These work for us with Cobbler 2.2.3 and Chef 11.4.0 on CentOS

Quick Install

These are our install steps on CentOS 6:

mkdir -p ~/.chef/plugins/knife/
curl -o ~/.chef/plugins/knife/set_environment.rb https://gist.github.com/gmr/5339326/raw/5bd498d25bc2f4d17f029cdc4a34ed38e461fec2/set_environment.rb
curl -o /usr/lib/python2.6/site-packages/cobbler/modules/install_pre_chef.py https://gist.github.com/gmr/5339326/raw/0b248a8b40e5bac5673bd7df7cfd60185af778bc/install_pre_chef.py

curl -o /usr/lib/python2.6/site-packages/cobbler/modules/delete_post_chef.py https://gist.github.com/gmr/5339326/raw/ae71362ae721c0391f0be2f4b2166f3806e90a91/delete_post_chef.py

@gmr
gmr / riemann.config.clj
Created April 23, 2013 02:06
Example riemann config
; -*- mode: clojure; -*-
; vim: filetype=clojure
(logging/init :file "/var/log/riemann/riemann.log")
; Listen on the local interface over TCP (5555), UDP (5555), and websockets
; (5556)
(let [host "0.0.0.0"]
(tcp-server :host host)
(udp-server :host host)
@gmr
gmr / fix_nrp_manifest.py
Last active December 19, 2015 22:59
This script removes erroneous entries in the newrelic_plugin_agent installation manifest file that if unsanitized, will unintentionally remove everything under / (and /var).
import os
from os import path
import site
# Check to see if the previous version was installed and clean up
# installed-files.txt
prune = ['var/', 'var/run/', 'var/log/']
package_directories = site.PREFIXES
if site.USER_SITE:
@gmr
gmr / 0-auto-manged-chef-repo.md
Last active February 8, 2018 22:45
This gist has files that are used to automate chef repository submodules used for roles, data bags, cookbooks and environments, ultimately uploading the maintained chef repository to chef via knife using Jenkins and Github.

The files in this gist are for having Jenkins automatically manage a chef repository using git submodules. This allows for clean, clutter free management of individual cookbooks, and individual respositories for roles, environments and data bags in our chef-repo.

The process relies on using Github (we use Github Enterprise) and Jenkins in combination with the Jenkins Github plugin to notify Jenkins when a repository has changed.

Our chef-repo directory looks something like:

chef-repo
    - cookbooks
          - Each cookbook is a git submodule managed by Jenkins
    - data_bags (git submodule managed by Jenkins)