Skip to content

Instantly share code, notes, and snippets.

@alistairncoles
Created March 21, 2016 19:43
Show Gist options
  • Save alistairncoles/4b66e256b5f8ebdcf70f to your computer and use it in GitHub Desktop.
Save alistairncoles/4b66e256b5f8ebdcf70f to your computer and use it in GitHub Desktop.
Monitoring swift container sync traffic
#!/bin/bash
# could be smarter and read these ports from the server conf files...
OBJ_SERVER_PORTS="6010 6020 6030 6040"
PROXY_SERVER_PORT=8080
setup_rules() {
# $1 should be -A to set, -D to unset
OP=$1
# the order we set the rules dictates the order they are displayed.
# bytes from obj servers...
for PORT in $OBJ_SERVER_PORTS
do
iptables $OP INPUT -p tcp --sport $PORT
done
# bytes to proxy server ...
iptables $OP INPUT -p tcp --dport $PROXY_SERVER_PORT
# bytes to object servers...
for PORT in $OBJ_SERVER_PORTS
do
iptables $OP INPUT -p tcp --dport $PORT
done
}
set() {
setup_rules -A
}
unset() {
setup_rules -D
}
show() {
iptables -nvxL INPUT
}
reset() {
iptables -Z INPUT
}
cmd=$0
if [[ -z $1 ]];
then
echo "$cmd [set|unset|reset|show]"
exit
fi
$1
echo "$1 rules on ports $PROXY_SERVER_PORT $OBJ_SERVER_PORTS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment