Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4416 from alphagov/add_filehandles_collectd
Browse files Browse the repository at this point in the history
Add filehandles to collectd
  • Loading branch information
deanwilson committed May 17, 2016
2 parents 276e060 + 01a7d54 commit e099b6a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
33 changes: 33 additions & 0 deletions modules/collectd/files/usr/lib/collectd/file_handles.sh
@@ -0,0 +1,33 @@
#!/bin/bash
# Author: Phil Dufault (phil@dufault.info)
# https://raw.githubusercontent.com/pdufault/collectd-exec-file_handles/master/file_handles.sh
# Commit 76e100799ae4d1cc231d0d343bd930f28d8d90c5
# 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
1 change: 1 addition & 0 deletions modules/collectd/manifests/config.pp
Expand Up @@ -36,6 +36,7 @@
source => 'puppet:///modules/collectd/etc/collectd/conf.d/network.conf.client',
}

include ::collectd::plugin::file_handles
# Always collect basic processlist info.
include ::collectd::plugin::processes
include ::collectd::plugin::tcpconns
Expand Down
22 changes: 22 additions & 0 deletions modules/collectd/manifests/plugin/file_handles.pp
@@ -0,0 +1,22 @@
# == Class: collectd::plugin::file_handles
#
# Monitors the number of file handles in use on a system
#
class collectd::plugin::file_handles(
) {

@file { '/usr/lib/collectd/file_handles.sh':
ensure => 'present',
mode => '0755',
owner => 'root',
group => 'root',
content => file('collectd/usr/lib/collectd/file_handles.sh'),
tag => 'collectd::plugin',
}

@collectd::plugin { 'file_handles':
content => template('collectd/etc/collectd/conf.d/file_handles.conf.erb'),
require => File['/usr/lib/collectd/file_handles.sh'],
}

}
@@ -0,0 +1,5 @@
LoadPlugin exec

<Plugin exec>
Exec nobody "/usr/lib/collectd/file_handles.sh"
</Plugin>

0 comments on commit e099b6a

Please sign in to comment.