+1 vote
3.7k views
in Cloud by
retagged by
I need a plugins for nagios to check the ram load and present the percentage of usage

1 Answer

0 votes
by
edited by

create a file check_mem and make it executable chmod +x check_mem then paste the below content, wow!! your plugin is ready
 

#!/bin/bash

# Nagios plugin to check RAM usage percentage

# Exit codes: 0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN

# Default thresholds (percentage)

WARNING=90

CRITICAL=93

# Parse arguments

while getopts "w:c:" opt; do

  case $opt in

    w) WARNING=$OPTARG ;;

    c) CRITICAL=$OPTARG ;;

    *) echo "Usage: $0 [-w warning%] [-c critical%]"; exit 3 ;;

  esac

done

# Get memory info

total=$(grep MemTotal /proc/meminfo | awk '{print $2}')

available=$(grep MemAvailable /proc/meminfo | awk '{print $2}')

if [[ -z $total ]] || [[ -z $available ]]; then

  echo "UNKNOWN: Could not get memory info"

  exit 3

fi

# Calculate usage

used=$((total - available))

used_percent=$(echo "scale=2; $used*100/$total" | bc)

# Determine status

status="OK"

exit_code=0

if (( $(echo "$used_percent >= $CRITICAL" | bc -l) )); then

  status="CRITICAL"

  exit_code=2

elif (( $(echo "$used_percent >= $WARNING" | bc -l) )); then

  status="WARNING"

  exit_code=1

fi

# Output clean result

echo "RAM Usage: ${status}: ${used_percent}% | used=${used_percent}%;$WARNING;$CRITICAL;0;100"

exit $exit_code
...