Hi team,
is there any plugin to monitor user process thread from linux server ( Ubuntu)
ex: uer1 thread count, user2 thread count
I am not looking process thread count looking for user thread count.
monitor Thread count in linux
Re: monitor Thread count in linux
I was unable to find an existing plugin that does this, you can try this:
Examples:
Examples:
Code: Select all
check_linux_user_threadcount.sh -w X -c X
check_linux_user_threadcount.sh -c X
check_linux_user_threadcount.shCode: Select all
# check_linux_user_threadcount.sh -w XX -c XX
#!/bin/bash
# Define input vars
while getopts "w:c:" option; do
case $option in
w) WARNING=$OPTARG ;;
c) CRITICAL=$OPTARG ;;
*) exit 3 ;;
esac
done
# Function taken from here: https://stackoverflow.com/a/17841619
function join_by { local d=${1-} f=${2-}; if shift 2; then printf %s "$f" "${@/#/$d}"; fi; }
THREADS=$(ps ax -o ruser=,nlwp=)
USERS=($(echo -n "$THREADS" | awk '{print $1}' | sort | uniq))
OUTPUTARRAY=()
for USER in "${USERS[@]}"; do
THREADCOUNT=$(echo -n "$THREADS" | grep "^$USER.*" | awk '{ threads += $2 } END { print threads }')
if [[ $THREADCOUNT -gt $THREADCOUNTHIGHEST ]]; then
THREADCOUNTHIGHEST=$THREADCOUNT
fi
OUTPUTARRAY+=("$USER $THREADCOUNT")
done
if [[ ! -z $CRITICAL ]] && [[ $THREADCOUNTHIGHEST -gt $CRITICAL ]]; then
STATE='CRITICAL'
EXITCODE=2
elif [[ ! -z $WARNING ]] && [[ $THREADCOUNTHIGHEST -gt $WARNING ]]; then
STATE='WARNING'
EXITCODE=1
else
STATE='OK'
EXITCODE=0
fi
OUTPUTFINAL="$(join_by ', ' "${OUTPUTARRAY[@]}")"
echo "$STATE - $OUTPUTFINAL"
exit $EXITCODE