Skip to content

Instantly share code, notes, and snippets.

View DazWorrall's full-sized avatar

Darren Worrall DazWorrall

  • UK
  • 16:57 (UTC +01:00)
View GitHub Profile
@DazWorrall
DazWorrall / cgroups.conf.j2
Created October 28, 2013 14:37
Collecting cgroup memory stats using collectd and ansible
LoadPlugin "table"
<Plugin table>
{% for vm in running_vms.list_vms %}
<Table "/sys/fs/cgroup/memory/libvirt/lxc/{{ vm }}/memory.stat">
Instance "{{ vm }}-memory"
Separator " \\n"
<Result>
Type gauge
InstancesFrom 0
ValuesFrom 1
@DazWorrall
DazWorrall / sig.py
Created July 29, 2013 10:22
What signal was I sent?
#!/usr/bin/env python
import time
import signal
import sys
SIGS = dict((k, v) for v, k in signal.__dict__.iteritems() if v.startswith('SIG'))
def sighandler(signum, frame):
print 'Signal handler called with signal', SIGS[signum]
sys.exit(1)
@DazWorrall
DazWorrall / plugin.conf
Created July 10, 2013 12:46
collectd segfault in curl_json against fpm's status page
LoadPlugin curl_json
<Plugin curl_json>
<URL "http://localhost/fpm-status?json">
Instance "fpm"
<Key "accepted conn">
Instance "accepted_conn"
Type "http_requests"
</Key>
<Key "listen queue len">
Instance "listen_queue_len"
@DazWorrall
DazWorrall / 2 vcpu KVM
Last active December 19, 2015 06:09
Ansible setup module and /proc/cpuinfo on an m1.xlarge ec2 instance - note the ansible_processor_cores count
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 2
model name : QEMU Virtual CPU version 0.12.3
stepping : 3
cpu MHz : 1596.068
cache size : 4096 KB
fpu : yes
fpu_exception : yes
@DazWorrall
DazWorrall / mytest.py
Last active December 17, 2015 08:59
Different value of `inject` in ansible lookup plugins. In the first case, `inject` is a dictionary with host/group/fact data, in the second case, its a function.
# Place in lookup_plugins/foo/mytest.py
from ansible import utils
class LookupModule(object):
def __init__(self, basedir=None, **kwargs):
self.basedir = basedir
def run(self, terms, inject=None, **kwargs):
---
- name: create logic volume
lvol: vg=$vol_group size=$vol_size lv={{ vol_name }} state=present
- name: check filesystem
command: tune2fs -l /dev/{{ vol_group }}/{{ vol_name }}
ignore_errors: True
register: result
- name: mkfs
@DazWorrall
DazWorrall / foo.py
Created April 6, 2013 12:10
SQLAlchemy 'or' operator
from flask import Flask, request
from flask.ext.sqlalchemy import SQLAlchemy
import unittest
app = Flask(__name__)
app.debug = True
db = SQLAlchemy()
db.init_app(app)
@DazWorrall
DazWorrall / test_salt.py
Last active December 14, 2015 13:09
Apply a salt state to the current machine using the internal api
import salt.config
opts = salt.config.minion_config('/tmp/foo') # Doesnt need to be present
opts['file_client'] = 'local' # I dont know if this is right. Not 'remote'
opts['cachedir'] = '/tmp/salt' # Needs to be writeable
d = {
'/tmp/bacon': {
'file': [
'directory',
@DazWorrall
DazWorrall / foo.sh
Created February 28, 2013 09:33
Useful varnishlog commands
varnishlog -c -m TxStatus:503 #Log client (not backend) requests that result in a 503 being returned to a client
@DazWorrall
DazWorrall / client.out
Created February 21, 2013 11:24
Script to reproduce failed login bug in pyftpdlib 1.0 using the multiprocess ftp server
Connected to 172.16.137.140.
220 pyftpdlib 1.0.0 ready.
Name (172.16.137.140:daz): bad
331 Username ok, send password.
Password:
421 Service not available, remote server timed out. Connection closed.
ftp: Login failed
ftp>