Skip to content

Instantly share code, notes, and snippets.

View kamermans's full-sized avatar
😏

Steve Kamerman kamermans

😏
View GitHub Profile
@kamermans
kamermans / parse_storcli.py
Last active February 20, 2023 08:23
Script to parse storcli (replaced megacli) output for use in monitoring applications like Nagios, Zabbix, etc
#!/usr/bin/env python
#
# Parses the output of storcli:
# storcli /c0 show all J
import sys
import json
output_dir = "."
data = json.load(sys.stdin)
@kamermans
kamermans / result.txt
Created October 26, 2015 23:34
PHP time() vs microtime() vs microtime(true) benchmark
PHP
--------------------------------------------------------------
Total Iterations: 10,000,000
time(): 0.73976612091064 seconds (13,517,785/sec)
microtime(): 4.2245488166809 seconds (2,367,116/sec)
microtime(true): 1.2555038928986 seconds (7,964,929/sec)
HHVM
--------------------------------------------------------------
Total Iterations: 10,000,000
@kamermans
kamermans / set_php_fpm_affinity.sh
Created June 11, 2015 05:29
Set PHP-FPM pool workers CPU affinity so each worker gets one CPU core
#!/bin/bash
# Set PHP-FPM pool workers CPU affinity so each worker gets one CPU core
# Note that FPM recycles threads, so you'll need to run this on cron periodically
# Author: Steve Kamerman
CPUS=$(grep -c CPU /proc/cpuinfo)
FPM_PIDS=$(ps auxw | grep php-fpm | grep pool | awk '{ print $2; }')
if [ "$FPM_PIDS" = "" ]; then
@kamermans
kamermans / docker_ephemeral_create.sh
Last active September 22, 2022 18:32
AWS EC2 script to mount Instance Store 0 and 1 as Docker temp and volume storage
#!/bin/sh -e
# This script will DESTROY /dev/xvdb and /dev/xvdc and remount them
# for Docker temp and volume storage.
# It is intended for EC2 instances with 2 ephemeral SSD instance stores
# like the c3.xlarge instance type.
service docker stop || true
# Setup Instance Store 0 for Docker Temp
# (set in /etc/default/docker)
@kamermans
kamermans / docker-functions.sh
Last active June 12, 2022 21:45
Bash functions for dealing with Docker containers in an unknown state (starting, stopping, removing, checking if they exist, etc)
# Helper functions for dealing with Docker containers
# Returns "missing", "stopped" or "running"
get_container_state() {
local CONTAINER_NAME=$1
# Faster check to see if the container *might* exist
CONTAINER_MISSING=$(container_does_not_exist "$CONTAINER_NAME")
if [[ $CONTAINER_MISSING = "true" ]]; then
echo -n "missing"
@kamermans
kamermans / mockedS3Client.go
Created February 25, 2020 03:04
Thread-Safe AWS S3 Mock for Golang (works with GetObject, PutObject, DeleteObject, HeadBucket)
package something
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"net/url"
"path"
"sync"
@kamermans
kamermans / hash_benchmark.php
Created October 21, 2018 05:43
Compute the performance of every hashing function in PHP
<?php
$loops = 100000;
$str = "whois foobar";
$algos = hash_algos();
$algo_padding = array_reduce($algos, function($carry, $val) {
$len = strlen($val);
if ($len > $carry) {
$carry = $len;
}
@kamermans
kamermans / analyze_haproxy_performance.pl
Created April 6, 2012 15:41
HAProxy log analyzer to show response latency distribution from the console
#!/usr/bin/perl
# HAProxy Performance Statistics
# by Steve Kamerman
#
# To use, pipe your HAProxy log with timing information (like "0/0/1/1/3 200") to
# this script. It will output min, max, med, avg and a latency distribution graph.
#
# Info on timing logging in HAProxy: http://code.google.com/p/haproxy-docs/wiki/TimingEvents
#
@kamermans
kamermans / parse_nginx_stats.py
Last active September 18, 2021 02:56
Simple nginx stats aggregation without NGINX Plus, Lua or NginScript - all you need is Python3!
#!/usr/bin/env python3
# Start this script before you start NGINX, so it is ready and waiting for log data.
# You should start it in the background with & or run it from supervisord or something.
# If the port is above 1024, you can run this script as a non-root user (recommended).
#
# It listens for raw Syslog data over UDP, parses is, aggregates it, and writes
# it to a file every flush_interval seconds. The output file format looks like this:
# key<TAB>value
# Here is an example (note that the delimiter is actually TAB, not a space):
@kamermans
kamermans / .bash_git.sh
Created May 22, 2015 19:04
A better bash-git prompt using git-prompt
# A better bash-git prompt using git-prompt
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
LIGHT_WHITE="\[\033[1;37m\]"
WHITE="\[\033[0;37m\]"
GRAY="\[\033[1;30m\]"
BLACK="\[\033[0;30m\]"
RED="\[\033[0;31m\]"
LIGHT_RED="\[\033[1;31m\]"
GREEN="\[\033[0;32m\]"