1 Reply Latest reply on Aug 19, 2005 5:32 AM by burakbayramli

    Monitoring Script Example

    rubbish

      #!/usr/bin/perl
      #
      #########################
      # Author: Ryan Ruebusch
      # 06/23/05
      # JBossMonitor.sh
      #########################
      #
      ##################################
      # Function: Monitor Connection Pool, Active Threads
      # and Memory, if any fail, restart JBoss and notify
      #
      # Things to change if you use this script:
      # * yourapp
      # * JAVA_HOME path
      # * JBossBin path
      # * Then, just use the sendmail function you have
      # and your JBoss restart script
      ##################################
      #
      #
      ####################
      # Define variables
      ####################
      #
      $ENV{"JAVA_HOME"} = "/opt/j2sdk1.4.2_08";
      $JBossBin = "/opt/jboss-4.0.1sp1/bin";

      #
      ##########################
      # Run Twiddle to grab the stuff we need
      ##########################
      #
      $freeram=`$JBossBin/twiddle.sh get jboss.system:type=ServerInfo FreeMemory | cut -f2 -d"="`;
      $maxram=`$JBossBin/twiddle.sh get jboss.system:type=ServerInfo MaxMemory | cut -f2 -d"="`;
      $activethreads=`$JBossBin/twiddle.sh get jboss.system:type=ServerInfo ActiveThreadCount | cut -f2 -d"="`;
      $yourappDS=`$JBossBin/twiddle.sh get jboss.jca:name=ds/yourapp,service=ManagedConnectionPool AvailableConnectionCount | cut -f2 -d"="`;

      #
      #############
      # Now use the stuff
      #############
      #
      $percentRAM=int(($freeram/$maxram) * 100);

      if ($percentRAM < 30)
      {
      `/home/myUID/jbossbin/sendemail.sh mykey "ALERT: yourapp-Server RAM is low!" "Available RAM at $percentRAM %. Investigate now."`;
      }

      if ($activethreads > 300)
      {
      `/home/myUID/jbossbin/sendemail.sh mykey "ALERT: JBoss Thread Count is High" "Thread count at $activethreads. Investigate now."`;
      }

      if ($yourappDS < 10)
      {
      `/home/myUID/jbossbin/sendemail.sh mykey "ALERT: yourapp-Server Connection Pool is Low" "Available Connections at $yourappDS . Investigate now."`;
      }

      #
      ################################
      # Restart if yourapp DS connections don't restore
      ################################

      $strikes = 0;
      if ($yourappDS < 1)
      {
      for ($i = 1; $i <=3; $i++)
      {
      `sleep 20`;
      if ($yourappDS < 3)
      {
      $strikes++;
      }
      }
      if ($strikes = 3)
      {
      `/home/myUID/jbossbin/sendemail.sh mykey "Production yourapp Emergency Restart Was Needed" "yourapp Restart was required! Please verify application comes back up. Available connections stayed at $yourappDS for 1 minute."`;
      `/home/myUID/jbossbin/restartJBoss.sh`;
      }
      }



      Keywords: monitor monitoring script scripts perl unix example sample JMX twiddle restart notify