maaash.jp

what I create

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

してみる

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/perl

use strict;
use warnings;
use Unix::Lsof;
use Unix::PID;

my $pid = Unix::PID->new();
my $red5\_pid = $pid->get\_pidof(‘search for a process by this string’);  
unless ( $red5_pid ) {
print ’0′;  
exit;
}

my ( $output, $error ) = lsof( ‘-p’, $red5_pid, ‘-w’ );  
my @vals = values %{$output};
print scalar @{ $vals[0]{files} };

snmpd.conf に

1
2
3
exec fd\_mon /path/to/fd\_mon.pl[/code]

mrtg.cfg 

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
MaxBytes[fd]: 2000
YLegend[fd]: File Descriptors
ShortLegend[fd]:
LegendI[fd]: / File Descriptors
LegendO[fd]: /
Legend1[fd]: / File Descriptors
Legend2[fd]: /
Title[fd]: File Descriptors
PageTop[fd]:

File Descriptors

[/code]

Comments