This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4416 from alphagov/add_filehandles_collectd
Add filehandles to collectd
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'], | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
modules/collectd/templates/etc/collectd/conf.d/file_handles.conf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
LoadPlugin exec | ||
|
||
<Plugin exec> | ||
Exec nobody "/usr/lib/collectd/file_handles.sh" | ||
</Plugin> |