PageRenderTime 28ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/perl/dev/SLE/proc_zstate-00001.pl

http://server-diagnostic-patterns.googlecode.com/
Perl | 138 lines | 83 code | 8 blank | 47 comment | 0 complexity | 2020a288c8f507b8668f590c889afa3c MD5 | raw file
  1. #!/usr/bin/perl -w
  2. #<<BEGIN PATTERN METADATA>>
  3. #META-CATEGORY = SLE
  4. #META-REVISION = 1.0.8
  5. #META-TITLE = Basic Health Check - Zombie Processes
  6. #META-DESCRIPTION = Checks for excessive zombie processes
  7. #META-PRODUCT = Basic
  8. #META-OS = SUSE
  9. #META-DISTRO = SLE
  10. #META-ARCH = All
  11. #META-LINK-TID = http://www.suse.com/support/kb/doc.php?id=7002724
  12. #<<END PATTERN METADATA>>
  13. ##############################################################################
  14. # WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  15. # This pattern uses deprecated functions. Do not use as an example.
  16. ##############################################################################
  17. ##############################################################################
  18. # Copyright (C) 2009 Novell, Inc.
  19. ##############################################################################
  20. #
  21. # This program is free software; you can redistribute it and/or modify
  22. # it under the terms of the GNU General Public License as published by
  23. # the Free Software Foundation; version 2 of the License.
  24. #
  25. # This program is distributed in the hope that it will be useful,
  26. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. # GNU General Public License for more details.
  29. #
  30. # You should have received a copy of the GNU General Public License
  31. # along with this program; if not, write to the Free Software
  32. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  33. #
  34. # Authors/Contributors:
  35. # Jason Record (jrecord@suse.com) - original BASH script
  36. # Douglas Kimball (dkimball@novell.com) - translated to this Perl script
  37. #
  38. # Creation Date: 2009 Feb 4
  39. # Last Modified Date: 2009 Jul 28
  40. #
  41. ##############################################################################
  42. ##############################################################################
  43. # Module Definition
  44. ##############################################################################
  45. use strict;
  46. use warnings; # should be same as -w command option
  47. use SDP::Core;
  48. use SDP::SUSE;
  49. ##############################################################################
  50. # Constants
  51. ##############################################################################
  52. use constant LIMIT_OPT_PROCZRED => 10; # Number of Z state proceses; red
  53. use constant LIMIT_OPT_PROCZYEL => 5; # Number of Z state proceses; yellow
  54. use constant OPEN_FILE_ERROR => "ERROR: Couldn't open file: ";
  55. use constant SECTION_PROCS => "egrep";
  56. use constant PATTERN_GREP => ".*?";
  57. use constant PROPERTY_NAME_PROCZ => 'PROCZ';
  58. ##############################################################################
  59. # Overriden (eventually or in part) from SDP::Core Module
  60. ##############################################################################
  61. $META_CATEGORY = "SLE"; #Assign it the same as the META_CATEGORY above
  62. $PRIMARY_LINK = "META-LINK-TID";
  63. @PATTERN_RESULTS = (
  64. PROPERTY_NAME_CATEGORY."=$META_CATEGORY",
  65. PROPERTY_NAME_PATTERN_ID."=$PATTERN_ID",
  66. PROPERTY_NAME_PRIMARY_LINK."=$PRIMARY_LINK",
  67. PROPERTY_NAME_OVERALL."=$GSTATUS",
  68. PROPERTY_NAME_OVERALL_INFO."=None"
  69. );
  70. $ARCH_FILE = "basic-health-check.txt";
  71. ##############################################################################
  72. # Feature Subroutines
  73. ##############################################################################
  74. # Check Free Memory and Disk Swapping
  75. sub check_proc_zstate() {
  76. print("Zombie Processes\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG;
  77. print("Using: $SRC_FILE1\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG;
  78. # df -h display mounted file systems
  79. my @ALL_VMSTAT_LINES = SDP::Core::grep_section_lines_wrap(SECTION_PROCS, PATTERN_GREP);
  80. my @VMSTAT_LINE = ();
  81. my $Z_COUNT = 0; # number of Z state processes
  82. print("Line count: ".$#ALL_VMSTAT_LINES."\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG;
  83. foreach my $i (0 .. $#ALL_VMSTAT_LINES) {
  84. @VMSTAT_LINE = @{$ALL_VMSTAT_LINES[$i]};
  85. print("@VMSTAT_LINE\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG;
  86. print(" $VMSTAT_LINE[7]\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG && $VMSTAT_LINE[7];
  87. if($VMSTAT_LINE[7] && $VMSTAT_LINE[7] eq 'Z') {
  88. $Z_COUNT++;
  89. print("$Z_COUNT\n") if $OPT_LOGLEVEL >= LOGLEVEL_DEBUG;
  90. }
  91. }
  92. # check against thresholds for status and message
  93. if ( $Z_COUNT >= LIMIT_OPT_PROCZRED ) {
  94. SDP::Core::update_status(STATUS_CRITICAL, PROPERTY_NAME_PROCZ, "$Z_COUNT meets or exceeds ".LIMIT_OPT_PROCZRED." zombie processes");
  95. }
  96. elsif ( $Z_COUNT >= LIMIT_OPT_PROCZYEL ) {
  97. SDP::Core::update_status(STATUS_WARNING, PROPERTY_NAME_PROCZ, "$Z_COUNT meets or exceeds ".LIMIT_OPT_PROCZYEL." zombie processes");
  98. }
  99. else {
  100. SDP::Core::initialize_status(STATUS_SUCCESS, "Observed $Z_COUNT zombie processes");
  101. SDP::Core::update_status(STATUS_SUCCESS, PROPERTY_NAME_PROCZ, "Observed $Z_COUNT zombie processes");
  102. }
  103. }
  104. ##############################################################################
  105. # Program execution subroutine
  106. ##############################################################################
  107. sub main() {
  108. SDP::Core::process_options(); # process any usage of command line options (such as -c for conf file)
  109. $SRC_FILE1 = $ARCH_PATH . $ARCH_FILE;
  110. # load_conf_file(); # load conf file based on process_options or default setting of $PATTERN_CONF
  111. SDP::Core::init_file_sections(); # core init
  112. check_proc_zstate();
  113. SDP::Core::print_pattern_results();
  114. }
  115. # call the main driver/subroutine then exit clean
  116. main();
  117. exit;