Created
April 11, 2012 09:30
-
-
Save masiulaniec/2358239 to your computer and use it in GitHub Desktop.
parallelism with xargs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -z "$1" ] | |
then | |
# Query N load balancers in parallel. | |
xargs -P 10 -n 1 -d '\n' $0 poll <<EOF | |
10.0.0.1 community101 dc=foo1 host=lb01.foo.com | |
10.0.0.2 community101 dc=foo1 host=lb02.foo.com | |
10.0.0.3 community101 dc=foo1 host=lb03.foo.com | |
EOF | |
exit | |
fi | |
if [ "$1" != "poll" ] | |
then | |
echo >&2 "usage: $0" | |
echo >&2 " $0 poll <addr> <password> <tags>" | |
exit 1 | |
fi | |
set -- $* | |
shift | |
addr=$1; shift | |
pass=$1; shift | |
tags=$* | |
datadir=$(mktemp -d /tmp/netscaler.XXXXXX) || exit | |
cd $datadir || exit | |
http=".1.3.6.1.4.1.5951.4.1.1.48" | |
comp=".1.3.6.1.4.1.5951.4.1.1.50" | |
ssl=".1.3.6.1.4.1.5951.4.1.1.47" | |
tcp=".1.3.6.1.4.1.5951.4.1.1.46" | |
# | |
# The code section between t0 and t1 is time-critical. | |
# This justifies job control tricks. | |
# | |
t0=$(date +%s) | |
snmpwalk -v2c -c $pass -Oneq $addr $http >a & | |
snmpwalk -v2c -c $pass -Oneq $addr $comp >b & | |
snmpwalk -v2c -c $pass -Oneq $addr $ssl >c & | |
snmpwalk -v2c -c $pass -Oneq $addr $tcp >d & | |
wait; wait; wait; wait | |
t1=$(date +%s) | |
cat a b c d >data | |
delta=$(expr $t1 - $t0) | |
if [ $delta -gt 1 ] | |
then | |
echo >&2 "$addr: query took $delta seconds" | |
fi | |
# V looks up specified oid value in snmp data dump. | |
v() { | |
_v=$(sed -n "s/^$1 //p" < data) | |
if [ -z "$_v" ] | |
then | |
echo >&2 "$addr: missing oid $1" | |
fi | |
echo $_v | |
} | |
echo "netscaler.http.request.received $t0 $(v $http.45.0) $tags type=get" | |
echo "netscaler.http.request.received $t0 $(v $http.46.0) $tags type=put" | |
echo "netscaler.http.request.received $t0 $(v $http.47.0) $tags type=other" | |
echo "netscaler.http.request.bytes $t0 $(v $http.48.0) $tags" | |
echo "netscaler.http.request.errors $t0 $(v $http.57.0) $tags type=HeaderTooLong" | |
echo "netscaler.http.response.sent $t0 $(v $http.53.0) $tags" | |
echo "netscaler.http.response.bytes $t0 $(v $http.51.0) $tags" | |
echo "netscaler.http.response.chunking $t0 $(v $http.62.0) $tags chunked=true" | |
echo "netscaler.http.response.chunking $t0 $(v $http.63.0) $tags chunked=false" | |
echo "netscaler.http.response.compressed $t0 $(v $comp.1.0) $tags" | |
echo "netscaler.http.response.errors $t0 $(v $http.58.0) $tags type=HeaderTooLong" | |
echo "netscaler.http.response.errors $t0 $(v $http.61.0) $tags type=5yz" | |
echo "netscaler.ssl.sessions $t0 $(v $ssl.205.0) $tags version=ssl2" | |
echo "netscaler.ssl.sessions $t0 $(v $ssl.206.0) $tags version=ssl3" | |
echo "netscaler.ssl.sessions $t0 $(v $ssl.207.0) $tags version=tls1" | |
echo "netscaler.ssl.transactions $t0 $(v $ssl.201.0) $tags version=ssl2" | |
echo "netscaler.ssl.transactions $t0 $(v $ssl.202.0) $tags version=ssl3" | |
echo "netscaler.ssl.transactions $t0 $(v $ssl.203.0) $tags version=tls1" | |
echo "netscaler.ssl.bytes $t0 $(v $ssl.312.0) $tags mode=encrypt" | |
echo "netscaler.ssl.bytes $t0 $(v $ssl.309.0) $tags mode=decrypt" | |
echo "netscaler.ssl.events $t0 $(v $ssl.209.0) $tags type=SessionCreate" | |
echo "netscaler.ssl.events $t0 $(v $ssl.210.0) $tags type=SessionReuse" | |
echo "netscaler.ssl.events $t0 $(v $ssl.208.0) $tags type=SessionExpiry" | |
echo "netscaler.ssl.events $t0 $(v $ssl.213.0) $tags type=Renegotiation version=ssl3" | |
echo "netscaler.ssl.events $t0 $(v $ssl.214.0) $tags type=Renegotiation version=tls1" | |
echo "netscaler.ssl.events $t0 $(v $ssl.219.0) $tags type=ClientAuth version=ssl3" | |
echo "netscaler.ssl.events $t0 $(v $ssl.220.0) $tags type=ClientAuth version=tls1" | |
echo "netscaler.tcp.conns $t0 $(v $tcp.11.0) $tags state=Opening lbend=front" | |
echo "netscaler.tcp.conns $t0 $(v $tcp.12.0) $tags state=Established lbend=front" | |
echo "netscaler.tcp.conns $t0 $(v $tcp.9.0) $tags state=Closing lbend=front" | |
echo "netscaler.tcp.conns $t0 $(v $tcp.72.0) $tags state=Invalid" | |
echo "netscaler.tcp.packets $t0 $(v $tcp.61.0) $tags direction=in" | |
echo "netscaler.tcp.packets $t0 $(v $tcp.63.0) $tags direction=out" | |
echo "netscaler.tcp.bytes $t0 $(v $tcp.62.0) $tags direction=in" | |
echo "netscaler.tcp.bytes $t0 $(v $tcp.64.0) $tags direction=out" | |
echo "netscaler.tcp.events $t0 $(v $tcp.21.0) $tags type=SynReceived" | |
echo "netscaler.tcp.events $t0 $(v $tcp.25.0) $tags type=SynReceivedAtTimeWait" | |
echo "netscaler.tcp.events $t0 $(v $tcp.24.0) $tags type=FinReceived" | |
echo "netscaler.tcp.events $t0 $(v $tcp.28.0) $tags type=TimeoutIdleHandshake lbend=front" | |
echo "netscaler.tcp.events $t0 $(v $tcp.26.0) $tags type=TimeoutIdleClientOrServer lbend=front" | |
echo "netscaler.tcp.events $t0 $(v $tcp.30.0) $tags type=TimeoutIdleServerAfterClientFin lbend=back" | |
echo "netscaler.tcp.events $t0 $(v $tcp.32.0) $tags type=TimeoutIdleClientAfterServerFin lbend=front" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.34.0) $tags type=ReceivedIncorrectChecksum" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.81.0) $tags type=ReceivedDataAfterFin" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.35.0) $tags type=ReceivedMultipleSynsAtHandshake" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.38.0) $tags type=ReceivedInvalidAckAtHandshake" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.36.0) $tags type=ReceivedSynAfterHandshake" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.42.0) $tags type=ReceivedDuplicateFin" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.44.0) $tags type=ReceivedRstForUnknownConn" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.45.0) $tags type=ReceivedRstOutOfWindow" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.46.0) $tags type=ReceivedRstAtTimewait" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.83.0) $tags type=ReceivedDataOutOfWindow" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.49.0) $tags type=ReceivedRetryFullPacket" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.50.0) $tags type=ReceivedRetryPartialPacket" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.48.0) $tags type=ReceivedRetry lbend=front" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.47.0) $tags type=ReceivedRetry lbend=back" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.52.0) $tags type=ReceivedUnorderedPacket lbend=front" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.51.0) $tags type=ReceivedUnorderedPacket lbend=back" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.39.0) $tags type=SentSynRetry" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.74.0) $tags type=SentDataRetry attempt=1" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.75.0) $tags type=SentDataRetry attempt=2" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.76.0) $tags type=SentDataRetry attempt=3" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.77.0) $tags type=SentDataRetry attempt=4" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.78.0) $tags type=SentDataRetry attempt=5" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.79.0) $tags type=SentDataRetry attempt=6" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.80.0) $tags type=SentDataRetry attempt=7" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.73.0) $tags type=SentDataRetry" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.40.0) $tags type=SentFinRetry" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.71.0) $tags type=SentRst" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.37.0) $tags type=TerminationSynRetryFailure" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.60.0) $tags type=TerminationDataRetryFailure" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.41.0) $tags type=TerminationFinRetryFailure" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.43.0) $tags type=TerminationReceivedRst" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.68.0) $tags type=TerminationTimeWaitProfusion" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.66.0) $tags type=QueueSyn lbend=back" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.67.0) $tags type=DropSynQueueEviction lbend=back" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.84.0) $tags type=DropSynCongestion" | |
echo "netscaler.tcp.errors $t0 $(v $tcp.82.0) $tags type=DropRstRateLimit" | |
# group port allocation failures | |
a=$(v $tcp.69.0) | |
b=$(v $tcp.70.0) | |
total=$(expr $a + $b) | |
echo "netscaler.tcp.errors $t0 $total $tags type=DropSynPortAllocError lbend=back" | |
# group syncookie failures | |
a=$(v $tcp.55.0) | |
b=$(v $tcp.56.0) | |
c=$(v $tcp.57.0) | |
d=$(v $tcp.58.0) | |
total=$(expr $a + $b + $c + $d) | |
echo "netscaler.tcp.errors $t0 $total $tags type=ReceivedInvalidSynCookie" | |
cd / | |
rm -r $datadir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment