-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfile_handles.sh
executable file
·31 lines (24 loc) · 1.18 KB
/
file_handles.sh
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
#!/bin/bash
# Author: Phil Dufault ([email protected])
# Date: April 2nd, 2014
# Use: collectd exec script to collect system file handle metrics
HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}"
INTERVAL="${COLLECTD_INTERVAL:-10}"
while sleep "$INTERVAL"; do
# Historically, the three values in file-nr denoted the number of
# * allocated file handles
# * the number of allocated but unused file handles
# * the maximum number of file handles.
# Linux 2.6 always reports 0 as the number of free file handles -- this is not an error, it just means that the number of allocated file handles exactly matches the number of used file handles.
# Grab the metrics
file_nr=($(cat /proc/sys/fs/file-nr))
allocated=${file_nr[0]}
allunused=${file_nr[1]}
max=${file_nr[2]}
# Output time
echo "PUTVAL $HOSTNAME/system-file_handles/gauge-file_handles_used interval=$INTERVAL N:$allocated"
echo "PUTVAL $HOSTNAME/system-file_handles/gauge-file_handles_allocatedunused interval=$INTERVAL N:$allunused"
echo "PUTVAL $HOSTNAME/system-file_handles/gauge-file_handles_max interval=$INTERVAL N:$max"
# putval format
# <instance-id>/<plugin>-<plugin_instance>/<type>-<type_instance>
done