7 Replies Latest reply on Sep 2, 2014 4:03 PM by Bill Robinson

    Need to Create NSH script in BSA 8.5


      Hi All

       

       

      As am facing issue in CPU utilization 100% in Application server i need to automat it such that i will get the mail when ever the Utilization of CPU goes to 100% , please help me in automating it. Need to know how to create NSH script and impliment it for the same issue.

       

      Specification

       

                BSA : 8.5

                OS : Windows 2008

        • 1. Re: Need to Create NSH script in BSA 8.5
          Aryan Anantwar

          Hi Yashaswi,

           

          the case you mentioned:

          "should get the mail when ever the Utilization of CPU goes to 100%"

          it is the part of monitoring not the automation.

          For such mechanism you should use Monitoring tools like, BPPM, Patrol etc.

          Yes, a NSH script can be written & used for the same, but it's not the functioning for which BSA is known for.

           

          Regards,

          Aryan Anantwar

          • 2. Re: Need to Create NSH script in BSA 8.5
            Joe Piotrowski

            As Aryan stated, our agents are not active (real time), they are passive. They do nothing until sent instructions from the application server. You need a real time monitoring tool/agent to accomplish what you're looking to do.

            1 of 1 people found this helpful
            • 3. Re: Need to Create NSH script in BSA 8.5
              Monoj Padhy

              As Aryan and Joe mentioned, BSA is not meant for such monitoring activity. use some monitoring tool to perform such things. Until you have such tool in place try something like below and since you will never able to get real time status use 80 or 90 % as your check point and once cpu reach that level perform the required task to lower down the same.

               

              cd //target_host

              result= nexec -i -e top -bn2 | grep "Cpu(s)" | \
                sed
              "s/.*, *\([0-9.]*\)%* id.*/\1/" | \
                awk
              '{print 100 - $1}'


              store the result of above command. Now

              if [ $result -gt  80 ]

              then

              blcli_execute Email sendMail sender_Mail receipient_Mail "subject" "CPU utilization is $result%"


              Now schedule this NSH job as you need. As BSA agent is passive in nature you might wish to execute this in frequently. You need to consider load on appserver and target server.

              HTH


              You may find below dicussion helpful

              NSH command to retrieve CPU utilization

              1 of 1 people found this helpful
              • 4. Re: Need to Create NSH script in BSA 8.5

                HI All ,

                 

                Thanks for your valuable feed back i just wanted to know

                 

                Do we have free monitoring tool to check ?

                 

                Regards

                YASH

                • 5. Re: Need to Create NSH script in BSA 8.5
                  Bill Robinson

                  ‘we’ being who ?  and to check what ?

                  • 6. Re: Need to Create NSH script in BSA 8.5

                    Hi Bill ,

                     

                    Its Just and Automating with out using the other tools

                    i have created the powershell script , where our application server are Windows 2008

                     

                    Please find below powershell script;

                     

                     

                    ####### Creating the folder in the C
                    Drive for giving the server values ##########

                     

                     

                    New-Item
                    -ItemType directory -Path C:\Scripts

                     

                     

                    ####### Declaring the variables
                    ###############

                     

                     

                    $ServerListFile = "C:\Scripts \ServerList.txt”  

                     

                     

                    $ServerList = Get-Content $ServerListFile –ErrorAction
                    SilentlyContinue 

                     

                     

                    $Result = @() 

                     

                     

                    ###### Logical implementation of the
                    script #######

                     

                     

                    ForEach($computername in $ServerList) 

                     

                     

                    {

                     

                     

                    $AVGProc = Get-WmiObject –computername $computername
                    win32_processor | 

                     

                     

                    Measure-Object –property LoadPercentage –Average | Select
                    Average

                     

                     

                    $OS = gwmi –Class win32_operatingsystem –computername
                    $computername |

                     

                     

                    Select-Object @{Name = “MemoryUsage”; Expression = {“{0:N2}”
                    –f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/
                    $_.TotalVisibleMemorySize) }}

                     

                     

                    $vol = Get-WmiObject –Class win32_Volume –ComputerName
                    $computername –Filter “DriveLetter = ‘C:’” |

                     

                     

                    Select-object @{Name = “C PercentFree”; Expression =
                    {“{0:N2}” –f  (($_.FreeSpace /
                    $_.Capacity)*100) } }

                     

                     

                    ################
                    Output Result Display Logic  ###############

                     

                     

                    $result += [PSCustomObject] @{ 

                     

                     

                            ServerName = “$computername”

                     

                     

                            CPULoad = “$($AVGProc.Average)%”

                     

                     

                            MemLoad = “$($OS.MemoryUsage)%”

                     

                     

                            Cdrive = “$($vol.’C
                    PercentFree’)%”

                     

                     

                        }

                     

                     

                    }

                     

                     

                     

                     

                     

                     

                     

                     

                    ################
                    Display Type ###############

                     

                     

                      $Outputreport = “<HTML><TITLE>
                    Server Health Report </TITLE>

                     

                     

                                       
                    <BODY background-color:peachpuff>

                     

                     

                                       
                    <font color =””#99000”” face=””Microsoft Tai le””>

                     

                     

                                       
                    <H2> Server Health Report </H2></font>

                     

                     

                                       
                    <Table border=1 cellpadding=0 cellspacing=0>

                     

                     

                                       
                    <TR bgcolor=gray align=center>

                     

                     

                                         
                    <TD><B>Server Name</B></TD>

                     

                     

                                         
                    <TD><B>Avrg.CPU Utilization</B></TD>

                     

                     

                                         
                    <TD><B>Memory Utilization</B></TD>

                     

                     

                                         
                    <TD><B>C Drive Utilizatoin</B></TD></TR>”

                     

                     

                     

                     

                     

                                           

                     

                     

                        Foreach($Entry in
                    $Result) 

                     

                     

                                 { 

                     

                     

                              if((($Entry.CpuLoad)
                    –or ($Entry.memload)) –ge “80”) 

                     

                     

                              { 

                     

                     

                              
                    $Outputreport += “<TR bgcolor=red>” 

                     

                     

                              } 

                     

                     

                              else

                     

                     

                               {

                     

                     

                              
                    $Outputreport += “<TR>” 

                     

                     

                              }

                     

                     

                            

                     

                     

                     

                     

                     

                    $Outputreport += “<TD>$($Entry.Servername)</TD><TD
                    align=center>$($Entry.CPULoad)</TD><TD
                    align=center>$($Entry.MemLoad)</TD><TD
                    align=center>$($Entry.Cdrive)</TD></TR>” 

                     

                     

                            }

                     

                     

                         $Outputreport += “</Table></BODY></HTML>” 

                     

                     

                          

                     

                     

                    ################
                    Creating file and displaying the result in it  ###############

                     

                     

                     

                     

                     

                    $Outputreport | out-file
                    C:\Scripts\Health_Check.htm 

                     

                     

                    Invoke-Expression C:\Scripts\
                    Health_Check.htm

                    • 7. Re: Need to Create NSH script in BSA 8.5
                      Bill Robinson

                      there are a lot of free monitoring tools available.  i've heard nagios is popular as is zabbix and i'm sure there are many others.  running a script as a job every minute or two via bsa is not the most efficient way to get this done.