Skip to content

Instantly share code, notes, and snippets.

View davidbirdsong's full-sized avatar

david birdsong davidbirdsong

  • san francisco, ca
View GitHub Profile
@davidbirdsong
davidbirdsong / sessions_decoder.lua
Last active January 8, 2022 17:20
general purpose session log decoder, everything but haproxy ripped out
local l = require('lpeg')
local clf = require('common_log_format')
local util = require('util')
l.locale(l)
local dt = require "date_time"
local integer = l.digit^1 / tonumber
local double = l.digit^1 * "." * l.digit^1 / tonumber
local lat_long = l.P"-"^-1 * l.digit^1 * ("." * l.digit^1)^-1 / tonumber
@davidbirdsong
davidbirdsong / haproxy_prom.txt
Created October 30, 2019 21:09
haproxy-prometheus example
# HELP haproxy_process_nbthread Configured number of threads.
# TYPE haproxy_process_nbthread gauge
haproxy_process_nbthread 4
# HELP haproxy_process_nbproc Configured number of processes.
# TYPE haproxy_process_nbproc gauge
haproxy_process_nbproc 1
# HELP haproxy_process_relative_process_id Relative process id, starting at 1.
# TYPE haproxy_process_relative_process_id gauge
haproxy_process_relative_process_id 1
# HELP haproxy_process_start_time_seconds Start time in seconds.
@davidbirdsong
davidbirdsong / haproxy-compile
Created October 29, 2019 18:58
haproxy compile
HA-Proxy version 2.0.8 2019/10/23 - https://haproxy.org/
Build options :
TARGET = linux-glibc
CPU = generic
CC = gcc
CFLAGS = -O2 -g -fno-strict-aliasing -Wdeclaration-after-statement -fwrapv -Wno-unused-label -Wno-sign-compare -Wno-unused-parameter -Wno-old-style-declaration -Wno-ignored-qualifiers -Wno-clobbered -Wno-missing-field-initializers -Wtype-limits
OPTIONS = USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_TFO=1 USE_NS=1 USE_SYSTEMD=1
Feature list : +EPOLL -KQUEUE -MY_EPOLL -MY_SPLICE +NETFILTER +PCRE -PCRE_JIT -PCRE2 -PCRE2_JIT +POLL -PRIVATE_CACHE +THREAD -PTHREAD_PSHARED -REGPARM -STATIC_PCRE -STATIC_PCRE2 +TPROXY +LINUX_TPROXY +LINUX_SPLICE +LIBCRYPT +CRYPT_H -VSYSCALL +GETADDRINFO +OPENSSL -LUA +FUTEX +ACCEPT4 -MY_ACCEPT4 +ZLIB -SLZ +CPU_AFFINITY +TFO +NS +DL +RT -DEVICEATLAS -51DEGREES -WURFL +SYSTEMD -OBSOLETE_LINKER +PRCTL +THREAD_DUMP -EVPORTS
@davidbirdsong
davidbirdsong / hap-do-resolve
Created October 29, 2019 18:56
do-resolve woes
global
log stdout local0
defaults
mode http
resolvers main_resolver
nameserver dns1 8.8.8.8:53
frontend fe_forwarder
@davidbirdsong
davidbirdsong / repilcate_file
Created October 17, 2017 23:19
replicate endpoint
local http = require('ext.resty.http')
local c = require('imgix.hwy.common')
local cjson = require('cjson')
local _ngx = ngx
if _ngx.req.get_method() ~= 'REPLICATE' then
_ngx.status = _ngx.HTTP_NOT_ALLOWED
local e = string.format('unsupported method: %s', _ngx.req.get_method())
_ngx.say(e)
_ngx.log(_ngx.ERR, e)
@davidbirdsong
davidbirdsong / tls_byte_buffer
Created May 3, 2016 21:17
tls allocations
[david@sjc1-b4-8 ~]$ go tool pprof $HOME/bin/hwy-fetcher http://localhost:6060/debug/pprof/heap
Fetching profile from http://localhost:6060/debug/pprof/heap
Saved profile in /home/david/pprof/pprof.hwy-fetcher.localhost:6060.inuse_objects.inuse_space.062.pb.gz
Entering interactive mode (type "help" for commands)
(pprof) top
12612.08MB of 14824.44MB total (85.08%)
Dropped 799 nodes (cum <= 74.12MB)
Showing top 10 nodes out of 87 (cum >= 201.56MB)
flat flat% sum% cum cum%
6202.85MB 41.84% 41.84% 6202.85MB 41.84% crypto/tls.(*block).reserve
@davidbirdsong
davidbirdsong / spigot_segv
Created April 6, 2017 21:13
spigot segv backtrace
*** Segmentation fault
Register dump:
RAX: 000000000e0b2270 RBX: 00007f6d21771ae0 RCX: 000000004108f810
RDX: 0000000041366b88 RSI: 0000000000000002 RDI: fffffffb411b4378
RBP: 0000000040ac6710 R8 : 0000000001ca19c0 R9 : 0000000001ca19c0
R10: 00000000401bd490 R11: 0000000000000000 R12: 0000000040cac460
R13: 00007ffc4d750ca0 R14: 00000000411b6da8 R15: 000000004045cdf0
RSP: 00007ffc4d6e45e0
@davidbirdsong
davidbirdsong / Future_illustrate
Created June 25, 2013 19:01
use ioloop.IOLoop.instance().add_future to create a callback for a completed Future object
from concurrent.futures import ThreadPoolExecutor
from tornado.concurrent import run_on_executor, Future
from tornado import httpclient,ioloop,web,gen
import request
import sys
httpclient.AsyncHTTPClient.configure('tornado.curl_httpclient.CurlAsyncHTTPClient', max_clients=10)
# TODO: remove
class Foo(Exception): pass
def dot():
51 yes
52 no
53 no
54 yes
55 no
56 no
57 yes
58 yes
59 no
60 no
global
pidfile /var/run/haproxy.pid
stats socket /var/run/haproxy.sock mode 600 level admin
maxconn 10240
user produser
group produser
log-tag gp_proxy
# daemon
description general purpose proxy, no image traffic through here