snmp/mrtgでプロセスの開いているファイルディスクリプタ数を監視

Posted on 5月 30, 2008
Filed Under snmp, mrtg, perl |

してみる

PERL:
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Unix::Lsof;
  6. use Unix::PID;
  7.  
  8. my $pid = Unix::PID->new();
  9. my $red5_pid = $pid->get_pidof('search for a process by this string');
  10. unless ( $red5_pid ) {
  11.   print '0';
  12.   exit;
  13. }
  14.  
  15. my ( $output, $error ) = lsof( '-p', $red5_pid, '-w' );
  16. my @vals = values %{$output};
  17. print scalar @{ $vals[0]{files} };

snmpd.conf に

CODE:
  1. exec fd_mon   /path/to/fd_mon.pl

mrtg.cfg に

CODE:
  1. Target[fd]: .1.3.6.1.4.1.2021.8.1.101.1&.1.3.6.1.4.1.2021.8.1.101.1:public@localhost
  2. MaxBytes[fd]: 2000
  3. YLegend[fd]: File Descriptors
  4. ShortLegend[fd]:
  5. LegendI[fd]: / File Descriptors
  6. LegendO[fd]: /
  7. Legend1[fd]: / File Descriptors
  8. Legend2[fd]: /
  9. Title[fd]: File Descriptors
  10. PageTop[fd]:
  11. <h1>File Descriptors</h1>

Comments

One Response to “snmp/mrtgでプロセスの開いているファイルディスクリプタ数を監視”

  1. mash on 5月 30th, 2008 18:56

    mrtg-2.14.5ではログが更新されなくてちょいはまりしました,,
    mrtg-2.16.1にしたらok

Leave a Reply