Skip to content

Instantly share code, notes, and snippets.

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

Gavin M. Roy gmr

:octocat:
🐘 🐇 🐍
View GitHub Profile
{% set nodes = ['%s:%s' % (r['Address'], r['ServicePort']) for r in consul.catalog.service('memcached')] %}
[main_cluster]
servers = {{ ','.join(nodes) }}
[dev_cluster]
servers = {{ ','.join(nodes) }}
import rabbitpy
import uuid
import time
COUNT = 100000
with rabbitpy.Connection('amqp://localhost:5672/%2f') as conn:
with conn.channel() as channel:
exchange = rabbitpy.DirectExchange(channel, 'benchmark')
import rabbitpy
import time
COUNT = 100000
start_time = time.time()
for iteration in range(0, COUNT):
rabbitpy.publish(exchange='benchmark',
routing_key='example',
body={'foo': 'bar'})
@gmr
gmr / consul.lua
Created July 14, 2014 17:03
Dynamic Nginx upstream nodes using Consul
module("resty.consul", package.seeall)
_VERSION = '0.1.0'
function service_nodes(service)
local http = require "resty.http"
local json = require "cjson"
local hc = http:new()
local upstream = ""
Vagrant VM 1: (server)
public IP: 192.168.50.101
Container:
Consul: 172.17.0.2
Vagrant VM 2: (agent only)
public IP: 192.168.35.8
When joining VM 1's server:
#cloud-config
coreos:
etcd:
discovery: https://discovery.etcd.io/7dc0971c7e6a060a3755d99bb8e10dd1
addr: $public_ipv4:4001
peer-addr: $public_ipv4:7001
units:
- name: etcd.service
command: start
@gmr
gmr / timeouts.py
Last active August 29, 2015 14:04
import time
while True:
with open('/proc/net/netstat') as netstat:
labels = netstat.readline()
values = netstat.readline()
l = labels.split(' ')
v = values.split(' ')
x = dict()
@gmr
gmr / dns.go
Last active August 29, 2015 14:05
consul service protocol + srv diffs
diff --git a/command/agent/dns.go b/command/agent/dns.go
index b832437..2fe0e5c 100644
--- a/command/agent/dns.go
+++ b/command/agent/dns.go
@@ -266,17 +266,20 @@ PARSE:
goto INVALID
}
+ // Extract the protocol
+ protocol := labels[n-2]
gmr-aw-mbp[~/Source/go/src/github.com/hashicorp/consul]: dig @localhost -p 8600 -t SRV appdb.service.consul
; <<>> DiG 9.8.3-P1 <<>> @localhost -p 8600 -t SRV appdb.service.consul
; (3 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40341
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
@gmr
gmr / dns.go
Last active August 29, 2015 14:05
diff adding SRV
diff --git a/command/agent/dns.go b/command/agent/dns.go
index b832437..cda6237 100644
--- a/command/agent/dns.go
+++ b/command/agent/dns.go
@@ -262,21 +262,34 @@ PARSE:
}
switch labels[n-1] {
case "service":
- if n == 1 {
+ switch n {