monitoring linux processes using metric extensions · 2014-02-19 ·...

10
Monitoring Linux processes using Metric Extensions in EM12c Date: Feb 1 st 2014 Author: Rob Zoeteweij http://oemgc.wordpress.com EM12c come with many Out of the Box metrics that can be used to monitor events within your datacentre or application landscape. You might however run into situations that are not fully covered by these Out of Box Metrics. I situation I run into recently was the demand to monitor the presence of a certain OS process on Linux. This article gives a description of how to create a Metric Extension for this. We will create a Metric Extension called ME$Process_Status that uses the following perl script: #!/usr/local/bin/perl # # linuxprocess_collector.pl # # NAME # linuxprocess_collector.pl - Script to get Linux Process state up/down # # DESCRIPTION # This script returns the up/down status of a Linux Process # # NOTES # - # MODIFIED (MM/DD/YY) # robztw 09/03/11 # use File::Temp qw/ tempfile tempdir /; my $status; $numArgs = $#ARGV + 1; if ($numArgs==0) {print "\nYou must provide the name of the Linux Process!\n"; exit 1;} foreach $argnum (0 .. $#ARGV) { if ($argnum > 0) {$WinService = $WinService . " "}; $LinuxProcess = $LinuxProcess . $ARGV[$argnum]; } my ($fh, $filename) = tempfile(); $syscmd = 'ps -elf | grep "' . $LinuxProcess . '" | grep -v grep | grep -v perl > "' . $filename . '"'; open($fh, $filename) or die("Can't open $filename"); system($syscmd); $status=0; # Init while(my $line = <$fh>) { print $line; if($line =~ m/$LinuxProcess/) {$status=1;} } close $fh; print "em_result=$status";

Upload: others

Post on 22-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Monitoring Linux processes using Metric Extensions · 2014-02-19 · We!leave!the!delimiter!as!is!and!indicate!that!the!return!value!fromthe!script!will!start! with‘em_result

Monitoring  Linux  processes  using    Metric  Extensions  in  EM12c  Date:  Feb  1st  2014  Author:  Rob  Zoeteweij    http://oemgc.wordpress.com    EM12c  come  with  many  Out  of  the  Box  metrics  that  can  be  used  to  monitor  events  within  your  datacentre  or  application  landscape.    You  might  however  run  into  situations  that  are  not  fully  covered  by  these  Out  of  Box  Metrics.  I  situation  I  run  into  recently  was  the  demand  to  monitor  the  presence  of  a  certain  OS  process  on  Linux.    This  article  gives  a  description  of  how  to  create  a  Metric  Extension  for  this.    We  will  create  a  Metric  Extension  called  ME$Process_Status  that  uses  the  following  perl  script:    

#!/usr/local/bin/perl # # linuxprocess_collector.pl # # NAME # linuxprocess_collector.pl - Script to get Linux Process state up/down # # DESCRIPTION # This script returns the up/down status of a Linux Process # # NOTES # - # MODIFIED (MM/DD/YY) # robztw 09/03/11 # use File::Temp qw/ tempfile tempdir /; my $status; $numArgs = $#ARGV + 1; if ($numArgs==0) {print "\nYou must provide the name of the Linux Process!\n"; exit 1;} foreach $argnum (0 .. $#ARGV) { if ($argnum > 0) {$WinService = $WinService . " "}; $LinuxProcess = $LinuxProcess . $ARGV[$argnum]; } my ($fh, $filename) = tempfile(); $syscmd = 'ps -elf | grep "' . $LinuxProcess . '" | grep -v grep | grep -v perl > "' . $filename . '"'; open($fh, $filename) or die("Can't open $filename"); system($syscmd); $status=0; # Init while(my $line = <$fh>) { print $line; if($line =~ m/$LinuxProcess/) {$status=1;} } close $fh; print "em_result=$status";

Page 2: Monitoring Linux processes using Metric Extensions · 2014-02-19 · We!leave!the!delimiter!as!is!and!indicate!that!the!return!value!fromthe!script!will!start! with‘em_result

The  creation  of  the  Metric  Extension  goes  as  follows:  From  the  Enterprise  menu  select  Monitoring  à  Metric  Extensions    

   From  the  Metric  Extension  page  click  [Create]    

   We  will  name  the  Metric  Extension  ME$Process_Status,  chose  for  Target  Type    ‘Host’,  give  it  a  Display  Name  and  Description.  We  will  use  the  ‘OS  Command  –  Multiple  Columns’  Adapter.  

Page 3: Monitoring Linux processes using Metric Extensions · 2014-02-19 · We!leave!the!delimiter!as!is!and!indicate!that!the!return!value!fromthe!script!will!start! with‘em_result

 We  will  leave  the  Collection  Schedule  as  it  is  and  press  [Next]    

 At  the  Adapter  page  we  use  %perlBin%/perl  as  we  are  using  a  perl  script  to  be  executed    The  script  is  called  linuxprocess_collector.pl  and  is  uploaded  using  the  [+Add]  icon    Note  that  the  name  of  the  Linux  process  syslogd  is  entered  as  argument  to  the  script.    

Page 4: Monitoring Linux processes using Metric Extensions · 2014-02-19 · We!leave!the!delimiter!as!is!and!indicate!that!the!return!value!fromthe!script!will!start! with‘em_result

We  leave  the  delimiter  as  is  and  indicate  that  the  return  value  from  the  script  will  start  with  ‘em_result=’.  When  you  check  the  perl  script  at  the  beginning  of  this  article  you  will  notice  that  this  is  the  case.    Press  [Next]    

   The  Metric  will  be  using  a  Column  to  communicate  the  Metric  result.    In  this  example  we  create  Column  process_status  that  will  be  used  as  Data  Column  of  type  Number.      We  select  ‘=’  as  the  Comparison  Operator  for  this  Metric  and  enter  0  as  the  Critical  Threshold  value,  as  this  is  the  value  that  will  be  returned  by  the  script  in  case  the  process  is  not  found  running.    Notice  that  we  entered  ‘Process  syslogd  is  down’  as  the  message  text  we  want  to  be  displayed  when  the  Metric  Extension  is  violated.    Press  [OK]      Press  [Next]    

Page 5: Monitoring Linux processes using Metric Extensions · 2014-02-19 · We!leave!the!delimiter!as!is!and!indicate!that!the!return!value!fromthe!script!will!start! with‘em_result

   The  Metric  will  be  using  the  Default  Monitoring  Credentials    Press  [Next]    

   In  the  Test  page  we  add  a  Host  where  we  will  test  our  Metric  Extension    Press  [Run  Test]  and  as  you  will  notice  the  test  result  is  value  1  as  the  process  we  are  checking  syslogd,  is  actually  running.    To  make  sure  the  Metric  Extension  is  functioning  properly  to  do  a  ‘negative’  test  by  changing  the  argument  to  the  name  of  a  process  we  know  is  not  running.    

Page 6: Monitoring Linux processes using Metric Extensions · 2014-02-19 · We!leave!the!delimiter!as!is!and!indicate!that!the!return!value!fromthe!script!will!start! with‘em_result

 We  change  the  name  of  the  process  to  check  to  syslogdx  (or  any  other  name  of  a  non  existing  process)  and  proceed  to  the  Test  page  to  rerun  the  test    

 Notice  that  the  Metric  now  returns  value  0  as  the  given  process  is  not  found.    After  resetting  the  name  of  the  process  to  check  to  syslogd  we  precede  to  the  last  page:    

Page 7: Monitoring Linux processes using Metric Extensions · 2014-02-19 · We!leave!the!delimiter!as!is!and!indicate!that!the!return!value!fromthe!script!will!start! with‘em_result

   After  being  sure  everything  was  entered  properly  we  press  [Finish]  to  complete  the  creation  of  the  Metric  Extension    

 To  allow  for  further  testing  we  will  save  the  Metric  as  a  Deployable  Draft    

 Just  select  Save  as  Deployable  Draft  from  the  Action  menu    

Page 8: Monitoring Linux processes using Metric Extensions · 2014-02-19 · We!leave!the!delimiter!as!is!and!indicate!that!the!return!value!fromthe!script!will!start! with‘em_result

 Next  we  want  to  deploy  the  Metric  Extension  to  a  target  by  selecting  Deploy  To  Targets  from  the  Action  menu    

 By  pressing  [Add]  and  selecting  a  Host  and  pressing  [Submit]  we  schedule  the  deployment  to  the  Host    

 As  you  notice  the  deployment  of  the  Metric  Extension  is  scheduled    

Page 9: Monitoring Linux processes using Metric Extensions · 2014-02-19 · We!leave!the!delimiter!as!is!and!indicate!that!the!return!value!fromthe!script!will!start! with‘em_result

 Next  we  navigate  to  the  Host  and  from  the  Target  menu  select  All  Metrics    

 At  the  left  side  pane  we  now  see  the  Metric  Extension  being  displayed    We  will  now  stop  the  syslogd  process  to  check  the  Metric  Extension  for  proper  functioning    

 

Page 10: Monitoring Linux processes using Metric Extensions · 2014-02-19 · We!leave!the!delimiter!as!is!and!indicate!that!the!return!value!fromthe!script!will!start! with‘em_result

 After  just  some  seconds  waiting  the  Metric  shows  that  the  syslogd  process  is  down.