Skip to content

Instantly share code, notes, and snippets.

View salekseev's full-sized avatar

Stas Alekseev salekseev

View GitHub Profile
@salekseev
salekseev / iptables_lb_8125.sh
Last active April 27, 2017 15:48
Script to to do UDP load balancing using NetFilter
#!/bin/bash
# enable forwarding
echo 1 >| /proc/sys/net/ipv4/ip_forward
# get softirq sharing between CPU cores for Receive Packet Steering
# https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Guide/network-rps.html
for rxq in $(ls -1 /sys/class/net/*/queues/rx-*/rps_cpus)
do
echo $(taskset -p 1 | cut -d':' -f2 | tr -d '[:space:]') >| $rxq
@salekseev
salekseev / cf-stack-find-ips.sh
Created March 22, 2017 16:19
Script to find private IP addresses of all EC2 instances participating in the CloudFormation stack
#!/bin/bash
command -v aws >/dev/null 2>&1 || { echo >&2 "I require awscli but it's not installed. Aborting."; exit 1; }
command -v curl >/dev/null 2>&1 || { echo >&2 "I require curl but it's not installed. Aborting."; exit 1; }
# Find local instance_id
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
# Find cloudformation stack-id
STACK_ID=$(aws ec2 describe-instances --output text --instance-ids $INSTANCE_ID | grep -e 'TAGS\saws:cloudformation:stack-id' | awk '{print $3}')
@salekseev
salekseev / kafkastat.sh
Created February 24, 2017 14:55
Show incoming message rate for a Kafka topic
#!/bin/sh
kafkacat -t test -b localhost -u -q | pv -l > /dev/null
@salekseev
salekseev / spl-0.6.5.8-uek.patch
Last active January 23, 2017 19:40
Patches for ZfsOnLinux to build packages on OracleLinux with UEK kernels
diff -Naur spl-0.6.5.8.orig/rpm/generic/spl-dkms.spec.in spl-0.6.5.8/rpm/generic/spl-dkms.spec.in
--- spl-0.6.5.8.orig/rpm/generic/spl-dkms.spec.in 2017-01-23 14:36:09.403082000 -0500
+++ spl-0.6.5.8/rpm/generic/spl-dkms.spec.in 2017-01-23 14:36:23.151812000 -0500
@@ -18,7 +18,7 @@
Requires: dkms >= 2.2.0.2
Requires: gcc, make, perl
-Requires: kernel-devel
+Requires: kernel-uek-devel
Provides: %{module}-kmod = %{version}
@salekseev
salekseev / start-kopf-docker.sh
Created December 8, 2016 18:55
Script to start KOPF Elasticsearch app on OS X via Docker
#!/bin/bash
# elasticsearch url
elasticsearch_hosts="devesdatasa100.athenahealth.com:9251,devesdatasa101.athenahealth.com:9251,devesdatasa102.athenahealth.com:9251"
port=$(( ((RANDOM<<15)|RANDOM) % 63001 + 2000 ))
function usage()
{
@salekseev
salekseev / es-snapshots-cleanup.sh
Last active December 7, 2016 20:19
Script to clean up incomplete Elasticsearch snapshots (assuming fs)
#!/bin/bash
# repository for snapshots
snapshots_repo="es-snapshots"
# filesystem for snapshots
snapshots_fs="/es-snapshots"
# elasticsearch url
elasticsearch_url="http://esdatafb101.athenahealth.com:9210"
#!/bin/bash
index="epriorauth"
date="2016-08-23"
broker="kafka100"
topic="structured_log_all"
kafkacat -b $broker -t $topic -C -o beginning \
| jq --arg index "$index" --arg date "$date" -cM '{"@timestamp": .["@timestamp"], "@target_index": .["@target_index"]} | select(.["@target_index"]==$index) | select( .["@timestamp"] | startswith($date) )'
#!/bin/bash
# This script will check if there is unallocated space in the volume group
# and will attempt to expand logical volume and file system using resize2fs
# Author: Stas Alekseev <[email protected]>
fs_mount="/var"
vg_minfree_mb="100000"
lv_maxsize_mb="27000"
warn () {
@salekseev
salekseev / hdfs-ha-namenode-failback.sh
Last active October 15, 2017 20:22
Script to check that both NameNodes are alive in HDFS HA configuration and will force failover to the preferred NameNode
#!/bin/bash
#
# This script will check that both NameNodes are alive in HDFS HA
# configuration and will force failover to the preferred NameNode.
#
# Author: Stas Alekseev <[email protected]>
#
ACTIVE_NAMENODE=nn1
STANDBY_NAMENODE=nn2
@salekseev
salekseev / killparent.c
Created October 16, 2015 18:55 — forked from xylifyx2/killparent.c
Use in -XX:OnOutOfMemoryError="killparent"
#include <stdio.h>
#include <unistd.h>
int main()
{
printf ("kill -9 <parent>\n");
kill (getppid(), 9);
}