Skip to content

Instantly share code, notes, and snippets.

View aerostitch's full-sized avatar

aerostitch aerostitch

View GitHub Profile
@aerostitch
aerostitch / extract_clients_from_tcpdump.sh
Last active August 29, 2015 14:26
awk to extract the IPs of the clients connecting to a host who's IP is 10.0.0.1 from the result of a tcpdump -n -l 'port 1234'
# awk to extract the IPs of the clients connecting to a host who's IP is 10.0.0.1
# from the result of a:
# tcpdump -n -l 'port 1234' > mytcpdump.dump
awk '$5 ~ /10\.0\.0\.1/ {split($3, a, "."); ip=sprintf("%d.%d.%d.%d",a[1],a[2],a[3],a[4]); array[ip]=ip }
END {for(i in array) {print array[i]}}' mytcpdump.dump | sort
@aerostitch
aerostitch / vertica_gather_full_statistics.sh
Last active September 18, 2015 00:52
Bash script to gather statistics (at 100%) on the tables of a Vertica database. It will stop starting new statistics collections after 2 hours here.
#!/bin/bash
# Gathering full statistics at 100% on all tables in Vertica.
# The tables with no row will always appear to have null statistics but that's ok.
# When a statistics ends it checks if the script has been running for more than
# 2 hours. If it's the case it stops.
#
# Prerequisites:
# a credentials file that looks like this:
#
# VERTICA_USER=MyUser
@aerostitch
aerostitch / aws_create_tag_attach_volume.sh
Last active February 23, 2017 22:40
Little script that creates volumes, tag them and attach the volumes to several instances
# Little script that creates volumes, tag them and attach the volumes to several instances
for i in {1..4} ; do
for srv in db0$i db0$i ; do
srvid=$(aws ec2 describe-instances --filters "Name=tag:hostname,Values=${srv}" 'Name=vpc-id,Values=vpc-123456' --output text --query 'Reservations[].Instances[].InstanceId')
for dev in f g ; do
volid=$(aws ec2 create-volume --size 1024 --availability-zone us-east-1d --volume-type standard --output json | jq '.VolumeId' | tr -d '"')
aws ec2 create-tags --resources ${volid} --tags Key=hostname,Value=${srv} Key=vpc-id,Value=vpc-123456 Key=device,Value=/dev/sd${dev}
while true ; do
status=$(aws ec2 describe-volumes --volume-id ${volid} --query 'Volumes[].State' --output text)
if [ "${status}" = "available" ] ; then
@aerostitch
aerostitch / HazelcastMetrics.java
Last active December 5, 2015 23:01
This script does a basic benchmark and retrieves some queue size and map size in Hazelcast locally.
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.monitor.LocalMapStats;
import com.hazelcast.monitor.NearCacheStats;
import com.hazelcast.core.IQueue;
import com.hazelcast.monitor.LocalQueueStats;
@aerostitch
aerostitch / haproxy_stats_from_local_socket.py
Last active August 31, 2021 14:24
This scripts issues a "show stats" command (the '\n' at the end is mandatory to make it work) in a local haproxy socket file and prints the returned data.
import socket
import os, os.path
# This scripts issues a "show stats" command (the '\n' at the end is mandatory to make it work)
# in a local haproxy socket file and prints the returned data.
sock_path="/var/run/haproxy-4.sock"
sock_cmd='show stat\n'
def getDataFromSocket(socket_path, cmd):
"""
Connects to a socket using the the local file given in socket_path,
@aerostitch
aerostitch / connections_by_status_and_ipport.sh
Last active June 10, 2022 12:43
Sorting the connections to a linux server by its status and bu combination of source/destination IP and port
# By status
netstat -an | awk '$6 ~ /^[A-Z_]+[1-2]*$/{a[$6]++} END {for (i in a) print a[i], "\t", i}' | sort -n
# By source IP:port
netstat -an | awk '$4 ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+$/{a[$4]++} END {for (i in a) print a[i], "\t", i}' | sort -n
# By destination IP:port
netstat -an | awk '$5 ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+$/{a[$5]++} END {for (i in a) print a[i], "\t", i}' | sort -n
# Just by destination IP
netstat -an | awk '$5 ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+$/{a[gensub(/^(.+):.+$/, "\\1", "g", $5)]++} END {for (i in a) print a[i], "\t", i}' | sort -n
@aerostitch
aerostitch / jinja2_template_validator.py
Last active February 10, 2016 14:20
This script tests if one or multiple templates can be rendered. It also can check the expected output difference. It populates the variables in for the jinja templates using yaml files.
# -*- coding: utf-8 -*-
'''
This script tests if one or multiple templates can be rendered using Jinja2.
It also can check the expected output difference.
It populates the variables in for the jinja templates using yaml files.
Arguments:
-r, --root-dir:
Root directory to scan for *.tmpl files. Ignored with -t option.
#!/usr/bin/env python
import urllib2
import base64
import json
try:
url = 'https://localhost:15671/api/overview'
username = 'rabbitmquser'
password = 'rabbitmqpwd'
request = urllib2.Request(url)
@aerostitch
aerostitch / collectd_metrics_from_json.py
Last active April 22, 2016 00:34
For when you cannot use the Digest because you have a too old version and that you cannot upgrade collectd! :)
#!/usr/bin/env python
import base64
import urllib2
import json
import collectd
'''
Plugin config example:
----------------------
awk 'match($0, /^([0-9]*-[0-9]*-[0-9]*) [0-9:, ]* \[ERROR\] \[[a-z\-0-9]+\] ([^ ]*) - (.*)$/, arr) {k=sprintf("%s %s - %s",arr[1], arr[2], arr[3]) ; if(k in counter){counter[k]++}else{counter[k]=1}} END {for(i in counter){printf "%d \t %s\n",counter[i],i}}' my_java_app.log | sort -k 1 -n | tail -20
# Apache access log
awk 'match($0, /^([0-9\.\:]*) [^ ]* [^ ]* \[([0-9/a-zA-Z]*):.*/, arr) {k=sprintf("%s - %s\n", arr[1], arr[2]); if(k in counter){counter[k]++}else{counter[k]=1}} END {for(i in counter){printf "%d \t %s\n",counter[i],i}}' access.log| sort -k 1 -n | tail -20