Nagios monitoring system memory

Source: Internet
Author: User
Linux memory mechanism: in linux, there is such an idea that the memory does not need to be white, so it tries its best to cache and buffer some data to facilitate the next use. But in fact, these memories can also be used immediately. So the idle memory free + buffers + cachedcheck_mem.sh monitoring script is found online.

Linux memory mechanism: in linux, there is such an idea that the memory does not need to be white, so it tries its best to cache and buffer some data to facilitate the next use. But in fact, these memories can also be used immediately. So idle memory =Free+ Buffers + cachEd

Check_mem.sh this monitoring script was found online. the obtained memory value is the three Mem: total userd free values from free-m. according to the above statement. this monitoring method is incorrect. so I modified the script. very simple. these two values are modified:

  1. # Total memory uSed
  2. Used = 'free-m | head-3 | tail-1 | awk '{print $3 }''
  3. # Calc total minus used
  4. Free = 'free-m | head-3 | tail-1 | awk '{print $4 }''

Check_mem.sh

  1. #! /Bin/bash
  2. USAGE = "'basename $ 0' [-w | -- warning] [-C | -- critical] "
  3. THRESHOLD_USAGE = "WARNING threshold must be greater than CRITICAL: 'basename $ 0' $ *"
  4. Calc =/tmp/meMcC
  5. Percent_free =/tmp/mempercent
  6. Critical = ""
  7. Warning = ""
  8. STATE_ OK = 0
  9. STATE_WARNING = 1
  10. STATE_CRITICAL = 2
  11. STATE_UNKNOWN = 3
  12. # Print usage
  13. If [[$ #-lt 4]
  14. Then
  15. Echo ""
  16. Echo "Wrong Syntax: 'basename $ 0' $ *"
  17. Echo ""
  18. Echo "Usage: $ USAGE"
  19. Echo ""
  20. ExIt 0
  21. Fi
  22. # Read input
  23. While [[$ #-gt 0]
  24. Do
  25. Case "$1" in
  26. -W | -- warning)
  27. Shift
  28. Warning = $1
  29. ;;
  30. -C | -- critical)
  31. Shift
  32. Critical = $1
  33. ;;
  34. Esac
  35. Shift
  36. Done
  37. # Verify input
  38. If [[$ warning-eq $ critical | $ warning-lt $ critical]
  39. Then
  40. Echo ""
  41. Echo "$ THRESHOLD_USAGE"
  42. Echo ""
  43. Echo "Usage: $ USAGE"
  44. Echo ""
  45. Exit 0
  46. Fi
  47. # Total memory available
  48. Total = 'free-m | head-2 | tail-1 | gawk '{print $2 }''
  49. # Total memory used
  50. Used = 'free-m | head-3 | tail-1 | awk '{print $3 }''
  51. # Calc total minus used
  52. Free = 'free-m | head-3 | tail-1 | awk '{print $4 }''
  53. # NoRmAl values
  54. # Echo "$ total" MB total
  55. # Echo "$ used" MB used
  56. # Echo "$ free" MB free
  57. # Make it into % percent free = (free mem/total mem) * 100)
  58. Echo "5"> $ calc # decimal accuracy
  59. Echo "k"> $ calc # commit
  60. Echo "100"> $ calc # multiply
  61. Echo "$ free"> $ calc # division integer
  62. Echo "$ total"> $ calc # division integer
  63. Echo "/"> $ calc # division sign
  64. Echo "*"> $ calc # multipliCatIon sign
  65. Echo "p"> $ calc # print
  66. Percent = '/usr/bin/dc $ calc |/bin/sed's/^ \./0./' |/usr/bin/Tr"." "|/Usr/bin/gawk {'print $1 '}'
  67. # Percent1 = '/usr/bin/dc $ calc'
  68. # Echo "$ percent1"
  69. If [["$ percent"-le $ critical]
  70. Then
  71. Echo "CRITICAL-$ free MB ($ percent %) Free Memory"
  72. Exit 2
  73. Fi
  74. If [["$ percent"-le $ warning]
  75. Then
  76. Echo "WARNING-$ free MB ($ percent %) Free Memory"
  77. Exit 1
  78. Fi
  79. If [["$ percent"-gt $ warning]
  80. Then
  81. Echo "OK-$ free MB ($ percent %) Free Memory"
  82. Exit 0
  83. Fi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.