Last active
August 29, 2015 13:57
-
-
Save lilithmooncohen/9794015 to your computer and use it in GitHub Desktop.
Simple script to return TCP memory settings and actual usage.
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/bash | |
# Author: Ryan C Koch - ryanckoch@gmail.com | |
# Purpose: Returns TCP Memory settings and Usage | |
# Arguments: low - Return Low Threshold Setting | |
# mem - Return Memory Pressure Setting | |
# out - Return Out of Socket Setting | |
# use - Return Actual Usage | |
# use_thresh - Check Usage Against Settings and Return Threshold | |
SETTINGS=$(cat /proc/sys/net/ipv4/tcp_mem) | |
USAGE=$(cat /proc/net/sockstat | awk 'NR==2' | sed 's/TCP.*mem\ //') | |
LOWTHRESHOLD=$(echo $SETTINGS | awk '{print $1}') | |
MEMORYPRESSURE=$(echo $SETTINGS | awk '{print $2}') | |
OUTOFSOCKET=$(echo $SETTINGS | awk '{print $3}') | |
if [ $# -eq 0 ] ; then | |
# Return all settings and actual usage if no arguments received | |
echo 'LOW_THRESHOLD_SETTING: '$LOWTHRESHOLD | |
echo 'MEMORY_PRESSURE_SETTING: '$MEMORYPRESSURE | |
echo 'OUT_OF_SOCKET_SETTING: '$OUTOFSOCKET | |
# Check usage against settings | |
if (("$USAGE" < "$MEMORYPRESSURE")) ; then | |
echo 'USAGE: '$USAGE | |
echo 'LOW_THRESHOLD' | |
elif (("$USAGE" >= "$MEMORYPRESSURE")) && (("$USAGE" < "$OUTOFSOCKET")) ; then | |
echo 'USAGE: '$USAGE | |
echo 'MEMORY_PRESSURE' | |
elif (("$USAGE" >= "$OUTOFSOCKET")) ; then | |
echo 'USAGE: '$USAGE | |
echo 'OUT_OF_SOCKET' | |
else | |
echo 'ERROR' | |
fi | |
elif [ $# -eq 1 ]; then | |
# Return specific info based on argument. | |
if [ $1 = "low" ] ; then | |
echo $LOWTHRESHOLD | |
elif [ $1 = "mem" ]; then | |
echo $MEMORYPRESSURE | |
elif [ $1 = "out" ]; then | |
echo $OUTOFSOCKET | |
elif [ $1 = "use" ]; then | |
echo $USAGE | |
elif [ $1 = "use_thresh" ]; then | |
if (("$USAGE" < "$MEMORYPRESSURE")) ; then | |
echo 'LOW_THRESHOLD' | |
elif (("$USAGE" >= "$MEMORYPRESSURE")) && (("$USAGE" < "$OUTOFSOCKET")) ; then | |
echo 'MEMORY_PRESSURE' | |
elif (("$USAGE" >= "$OUTOFSOCKET")) ; then | |
echo 'OUT_OF_SOCKET' | |
else | |
echo 'ERROR' | |
fi | |
else | |
echo 'INVALID ARGUMENT' | |
fi | |
else | |
echo 'INCORRECT NUMBER OF ARGUMENTS' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment