Display open file handles
Moderators: Developers, Moderators
Display open file handles
Hi,
is there any way to monitor the number of open file handles on the linux system?
Regards,
Oliver
is there any way to monitor the number of open file handles on the linux system?
Regards,
Oliver
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
If you have a script that simply returns this wanted value or an OID for that, the answer ist: YES. There's a way to implement this script at http://www.cacti.net/downloads/docs/htm ... thods.html
Reinhard
Reinhard
I made this script:
--------------------------------------------------------------------------------
#!/bin/bash
TEMP=`ls /proc/`
TEMP=`echo $TEMP | sed "s/[a-zA-Z]//g" | sed "s/[.]//g"`
NR_HANDLES=0
for PID in $TEMP;
do
NR_PID=`/usr/sbin/lsof -p $PID | wc -l`
NR_HANDLES=$[$NR_HANDLES+$NR_PID]
done
echo $NR_HANDLES
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
#!/bin/bash
TEMP=`ls /proc/`
TEMP=`echo $TEMP | sed "s/[a-zA-Z]//g" | sed "s/[.]//g"`
NR_HANDLES=0
for PID in $TEMP;
do
NR_PID=`/usr/sbin/lsof -p $PID | wc -l`
NR_HANDLES=$[$NR_HANDLES+$NR_PID]
done
echo $NR_HANDLES
--------------------------------------------------------------------------------
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
Well, seems nice, but has problems with processes like sysrq-trigger (the "-" sign!). You'll have to define a Data Input Method for that, a Data Template and a Graph Template as described in http://www.cacti.net/downloads/docs/htm ... thods.html
Reinhard
Reinhard
I changed to a new solution:
#!/bin/bash
TEMP=`ls /proc/`
PID_EXCLUDE=$[$$+1]
TEMP=`echo $TEMP | sed "s/[a-zA-Z]//g" | sed "s/[.]//g" | sed "s/$PID_EXCLUDE//g"`
NR_HANDLES=0
for PIDS in $TEMP;
do
FD_COUNTER=0
for FD in $(ls /proc/$PIDS/fd/);
do
FD_COUNTER=$[FD_COUNTER+1]
done
FD_COUNTER_ALL=$[FD_COUNTER_ALL+FD_COUNTER]
done
echo $FD_COUNTER_ALL
because lsof generates high load on the server....
#!/bin/bash
TEMP=`ls /proc/`
PID_EXCLUDE=$[$$+1]
TEMP=`echo $TEMP | sed "s/[a-zA-Z]//g" | sed "s/[.]//g" | sed "s/$PID_EXCLUDE//g"`
NR_HANDLES=0
for PIDS in $TEMP;
do
FD_COUNTER=0
for FD in $(ls /proc/$PIDS/fd/);
do
FD_COUNTER=$[FD_COUNTER+1]
done
FD_COUNTER_ALL=$[FD_COUNTER_ALL+FD_COUNTER]
done
echo $FD_COUNTER_ALL
because lsof generates high load on the server....
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
Yes, it's a lot faster. But three runs on my host (laptop) yielded the follwoing
Reinhard
So there has to be some more error handling, I suppose ...ls: /proc/4962/fd/: No such file or directory
ls: /proc/4963/fd/: No such file or directory
ls: /proc/-/fd/: No such file or directory
1162
[root@gandalf scripts]# . lvm_file_handles.sh
ls: /proc/5193/fd/: No such file or directory
ls: /proc/5194/fd/: No such file or directory
ls: /proc/-/fd/: No such file or directory
2324
[root@gandalf scripts]# . lvm_file_handles.sh
ls: /proc/5422/fd/: No such file or directory
ls: /proc/5423/fd/: No such file or directory
ls: /proc/-/fd/: No such file or directory
3486
Reinhard
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
Don't bother for that, just thought it would make the script more stable to work on that. My system runs:
Reinhard
Did not find time to debug this on my own yet...Linux 2.6.9-5.EL #1 Wed Jan 5 19:22:18 EST 2005 i686 GNU/Linux
0.8.6g
CACTID 0.8.6f Copyright 2002-2005 by The Cacti Group
PHP 4.3.9 (cgi) (built: Aug 17 2005 10:22:19)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
RRDtool 1.2.11 Copyright 1997-2005 by Tobias Oetiker <tobi@oetiker.ch>
mysql Ver 14.7 Distrib 4.1.10a, for redhat-linux-gnu (i386)
gcc (GCC) 3.4.3 20050227 (Red Hat 3.4.3-22.1)
Reinhard
-
- Posts: 1
- Joined: Wed Feb 27, 2008 8:42 am
Thank you for your script.
I have some entries in /proc/ which contain a '-' (dash) sign. These won't get replaced by sed. (sysrq-trigger, key-users) which result in a '-' sign as given directory and thus giving an error. If you add a dash to the sed script it works really well.
So the TEMP line would become like this:
UPDATE:
I modified the script a bit. I hope you don't mind:
Because Cacti was running as www-data I had to add the sudo part to be able to list the contents of the fd dirs. The line in /etc/sudoers looks like this:
www-data ALL=(root) NOPASSWD:/bin/ls /proc/*/fd/
I attached the xml file for your convenience. (Exported with Version 0.8.6i)
I have some entries in /proc/ which contain a '-' (dash) sign. These won't get replaced by sed. (sysrq-trigger, key-users) which result in a '-' sign as given directory and thus giving an error. If you add a dash to the sed script it works really well.
So the TEMP line would become like this:
Code: Select all
TEMP=`echo $TEMP | sed "s/[a-zA-Z-]//g" | sed "s/[.]//g" | sed "s/$PID_EXCLUDE//g"`
I modified the script a bit. I hope you don't mind:
Code: Select all
#!/bin/bash
NR_HANDLES=0
for PIDS in $(ls /proc/ | sed "s/[^0-9]//g");
do
if [ -d /proc/$PIDS ]; then
NR_HANDLES=$[NR_HANDLES+$(sudo ls /proc/$PIDS/fd/ | wc -w)]
fi
done
echo -n $NR_HANDLES
www-data ALL=(root) NOPASSWD:/bin/ls /proc/*/fd/
I attached the xml file for your convenience. (Exported with Version 0.8.6i)
- Attachments
-
- file_handles.xml
- (6.33 KiB) Downloaded 831 times
Re: Display open file handles
So I tried this one and the command worked fine in the shell, but on the graph it was way off:
Thanks
Does anything stand out?./file_handles.sh
1644
Thanks
- Attachments
-
- error_cacti-wrong-values-gtemplate.PNG (42.8 KiB) Viewed 4158 times
-
- error_cacti-wrong-values-data_template.PNG (70.09 KiB) Viewed 4158 times
-
- error_cacti-wrong-values.PNG (17.24 KiB) Viewed 4158 times
Who is online
Users browsing this forum: No registered users and 6 guests