Skip to content

Instantly share code, notes, and snippets.

@thecarlhall
Last active December 12, 2015 01:08
Show Gist options
  • Save thecarlhall/4688247 to your computer and use it in GitHub Desktop.
Save thecarlhall/4688247 to your computer and use it in GitHub Desktop.
Riak status shell function
riak_ping() {
NODES=$(dig +short A production-reporting-source-129485720.us-east-1.elb.amazonaws.com)
for n in $NODES; do
echo "Server ${n}: $(curl --connect-timeout 3 -s -k https://${n}:8080/ping)" &
done
}
alias riak_ping=riak_ping
riak_status() {
NODES=$(dig +short A production-reporting-source-129485720.us-east-1.elb.amazonaws.com)
NAME="hostname"
RIAK_PROCS="ps ax | grep -v grep | grep beam\.smp | wc -l"
MONIT_PROCS="ps ax | grep -v grep | grep monit | wc -l"
UL_SOFT="ulimit -Sn"
UL_HARD="ulimit -Hn"
OPEN_FILES_RIAK="sudo lsof | grep riak | wc -l"
OPEN_FILES_TOTAL="sudo lsof | wc -l"
MEMORY_FREE="free | head -n 3 | tail -n 1 | awk '{print \$4 / (\$3 + \$4) * 100}'"
MEMORY_USED="free | head -n 3 | tail -n 1 | awk '{print \$3 / (\$3 + \$4) * 100}'"
for n in $NODES; do
limits=$(ssh ubuntu@$n -t "(${RIAK_PROCS}) && (${MONIT_PROCS}) && (${UL_SOFT}) && (${UL_HARD}) && (${OPEN_FILES_RIAK}) && (${OPEN_FILES_TOTAL}) && (${MEMORY_FREE}) && (${NAME})")
echo "Name: $(echo "$limits" | head -n 8 | tail -n 1)"
echo "Status: $(curl --connect-timeout 3 -s -k https://${n}:8080/ping)"
echo "Riak Processes: $(echo "$limits" | head -n 1)"
echo "Monit Processes: $(echo "$limits" | head -n 2 | tail -n 1)"
echo "ulimit (soft): $(echo -n "$limits" | head -n 3 | tail -n 1)"
echo "ulimit (hard): $(echo -n "$limits" | head -n 4 | tail -n 1)"
echo "Open Files (riak): $(echo -n "$limits" | head -n 5 | tail -n 1)"
echo "Open Files (total): $(echo -n "$limits" | head -n 6 | tail -n 1)"
echo "Free memory (%): $(echo "$limits" | head -n 7 | tail -n 1)"
echo "====="
done
}
alias riak_status=riak_status
@thecarlhall
Copy link
Author

This is what the output looks like for riak_status:

$ riak_status 
Connection to 23.22.149.216 closed.
Name: prod-riak-005
Status: OK
Riak Processes: 1
Monit Processes: 1
ulimit (soft): 1024
ulimit (hard): 4096
Open Files (riak): 1260
Open Files (total): 2032
Free memory (%): 66.7511
=====
Connection to 107.22.120.253 closed.
Name: prod-riak-003
Status: OK
Riak Processes: 1
Monit Processes: 1
ulimit (soft): 1024
ulimit (hard): 4096
Open Files (riak): 1309
Open Files (total): 2080
Free memory (%): 58.5052
=====
Connection to 23.20.222.15 closed.
Name: prod-riak-004
Status: OK
Riak Processes: 1
Monit Processes: 1
ulimit (soft): 1024
ulimit (hard): 4096
Open Files (riak): 1249
Open Files (total): 2020
Free memory (%): 27.3779
=====
Connection to 184.73.3.12 closed.
Name: prod-riak-001
Status: OK
Riak Processes: 1
Monit Processes: 1
ulimit (soft): 1024
ulimit (hard): 4096
Open Files (riak): 1227
Open Files (total): 2217
Free memory (%): 25.0746
=====
Connection to 50.16.48.166 closed.
Name: prod-riak-002
Status: OK
Riak Processes: 1
Monit Processes: 1
ulimit (soft): 1024
ulimit (hard): 4096
Open Files (riak): 1132
Open Files (total): 1903
Free memory (%): 94.7266
=====

@thecarlhall
Copy link
Author

This is what the output looks like for riak_ping:

Server 50.16.216.xxx: OK
Server 54.225.186.xxx: OK
Server 50.19.236.xxx: OK
Server 184.73.249.xxx: OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment