Skip to content

Instantly share code, notes, and snippets.

@plockaby
plockaby / Client.pm
Created January 16, 2022 19:28
Database connector for Perl
# this should go into a directory called "Tools/Database" and be called "Client.pm"
package Tools::Database::Client;
use strict;
use warnings FATAL => 'all';
use Try::Tiny;
use Tools::Database;
use Carp;
@plockaby
plockaby / decoder.py
Last active January 2, 2022 20:01
collectd Network Decoder
# Copyright © 2009 Adrian Perez <aperez@igalia.com>
#
# Distributed under terms of the GPLv2 license.
#
# Updated by Rami Sayar for Collectd 5.1. Added DERIVE handling.
# Updated by Grégory Starck with few enhancements.
# Updated by Paul Lockaby with only cosmetic changes.
import logging
import struct
@plockaby
plockaby / database.py
Last active January 7, 2024 15:49
Python Flask Connection Pool
import logging
import psycopg2
from psycopg2.extras import RealDictCursor
from psycopg2.extensions import TRANSACTION_STATUS_UNKNOWN, TRANSACTION_STATUS_IDLE
from flask import g
import threading
import tenacity
import uuid
import pwd
import os
@plockaby
plockaby / haproxy-stats
Created August 28, 2019 22:29 — forked from alq666/haproxy-stats
HAProxy metrics
0. pxname [LFBS]: proxy name
1. svname [LFBS]: service name (FRONTEND for frontend, BACKEND for backend,
any name for server/listener)
2. qcur [..BS]: current queued requests. For the backend this reports the
number queued without a server assigned.
3. qmax [..BS]: max value of qcur
4. scur [LFBS]: current sessions
5. smax [LFBS]: max sessions
6. slim [LFBS]: configured session limit
7. stot [LFBS]: cumulative number of connections
@plockaby
plockaby / volume-to-ami.sh
Created July 28, 2019 02:34
Converts an AWS Volume to AWS AMI
#!/bin/bash
# This script require the following EC2 APIs:
# DescribeSnapshots
# CreateSnapshot
# RegisterImage
# runtime overridable defaults:
AMI_VIRT_TYPE=hvm
AMI_ARCH=x86_64
AMI_RELEASE=buster
@plockaby
plockaby / eventlistener.py
Last active June 10, 2019 17:59
A Supervisord eventlistener that does nothing.
import os
import io
import sys
import logging
import select
from threading import Event
import signal
import argparse
# this configuration file was originally provided to me by Lloyd Albin
# from Fred Hutch. he runs the SEAPUG Seattle PostgreSQL Users Group.
# thanks Lloyd!
LoadPlugin postgresql
<Plugin postgresql>
<Query connections>
Statement "SELECT count(*) AS connections FROM pg_stat_activity;"
<Result>
Type pg_conns
@plockaby
plockaby / show_object_privileges.sql
Last active May 23, 2019 03:32
Show ownership of everything in a PostgreSQL database except databases and "large objects".
SELECT z.schema,
z.name,
z.owner,
z.type,
z.objuser,
z.privilege_aggregate,
z.privilege,
CASE z.privilege
WHEN '*'::text THEN 'GRANT'::text
WHEN 'r'::text THEN 'SELECT'::text