Skip to content

Instantly share code, notes, and snippets.

@lcarstensen
lcarstensen / awk_netstat.sh
Created May 21, 2019 23:12 — forked from staaldraad/awk_netstat.sh
AWK to get details from /proc/net/tcp and /proc/net/udp when netstat and lsof are not available
# Gawk version
# Remote
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($3,index($3,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($3,i,2))}{print x":"strtonum("0x"substr($3,index($3,":")+1,4))}'
# Local
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($2,index($2,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($2,i,2))}{print x":"strtonum("0x"substr($2,index($2,":")+1,4))}'
# No Gawk
# Local
grep -v "rem_address" /proc/net/tcp | awk 'function hextodec(str,ret,n,i,k,c){
@lcarstensen
lcarstensen / latency.txt
Last active August 29, 2015 14:21 — forked from jboner/latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@lcarstensen
lcarstensen / docker-zookeeper.service
Created May 15, 2015 19:34
gareth/garethr-docker generated systemd service file that doesn't work due to spaces in SERVERLIST environment variable
# This file is managed by Puppet and local changes
# may be overwritten
[Unit]
Description=Daemon for zookeeper
After=docker.service
Requires=docker.service
[Service]
Restart=on-failure
@lcarstensen
lcarstensen / docker-rm-test.sh
Created April 12, 2014 01:23
Simple "docker rm" stability test
#!/bin/bash
for i in {1..100}; do
( docker run -d --name $i cirros sleep 3600 ) &
done
for i in {1..100}; do
( sleep $((RANDOM%120+60)) ; docker rm -f $i ) &
done