summaryrefslogtreecommitdiff
path: root/files/munin/tor_openfds
blob: 69f63bccf91e136ad043e6e48acb773771e36f50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl -w
# https://lists.torproject.org/pipermail/tor-talk/2006-June/010486.html

use strict;

# Script to monitor the amount of FDs used by
# the Tor process (var/run/tor/tor.pid)

if ($ARGV[0] and $ARGV[0] =~ /^\s*config\s*$/i)
{
        print "graph_title Open file descriptors for Tor\n";
        print "graph_args --base 1000 -l 0\n";
        print "graph_vlabel open FDs\n";
        print "graph_category network\n";
        print "count.label TorFDs\n";
        exit 0;
}

open (PID, "/var/run/tor/tor.pid") or exit 1;
my $pid = <PID>;
close PID;
chomp $pid;

$pid =~ /^[0-9]+$/ or exit 1;

opendir (FDS, "/proc/$pid/fd") or exit 1;
my @fds = readdir(FDS);
closedir FDS;

my $count = scalar @fds - 2;

print "count.value $count\n";