monitor Thread count in linux

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
[email protected]
Posts: 66
Joined: Tue Aug 07, 2018 2:24 am

monitor Thread count in linux

Post by [email protected] »

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.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: monitor Thread count in linux

Post by ssax »

I was unable to find an existing plugin that does this, you can try this:

Examples:

Code: Select all

check_linux_user_threadcount.sh -w X -c X
check_linux_user_threadcount.sh -c X
check_linux_user_threadcount.sh

Code: 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
Locked