root / plugins / disk / file_age @ 09b88141
Historique | Voir | Annoter | Télécharger (2,87 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
|
| 3 |
. $MUNIN_LIBDIR/plugins/plugin.sh |
| 4 |
|
| 5 |
case $1 in |
| 6 |
config) |
| 7 |
GRAPH_ORDER="" |
| 8 |
COUNTER=1 |
| 9 |
while [ $COUNTER -gt 0 ]; do |
| 10 |
FILE_PATH="file${COUNTER}_path"
|
| 11 |
|
| 12 |
# Is the path for this file specified? |
| 13 |
eval FILE=\$$FILE_PATH |
| 14 |
if [ "$FILE" == "" ]; then |
| 15 |
break; |
| 16 |
fi |
| 17 |
|
| 18 |
# It is! Add it to the graphs. |
| 19 |
GRAPH_ORDER="$GRAPH_ORDER file_$COUNTER" |
| 20 |
|
| 21 |
# Does this file have a specified label? |
| 22 |
LABEL_COUNTER="file${COUNTER}_label"
|
| 23 |
eval LABEL=\$$LABEL_COUNTER |
| 24 |
if [ "$LABEL" == "" ]; then |
| 25 |
LABEL=`basename $FILE` |
| 26 |
fi |
| 27 |
|
| 28 |
# Associated warning level? |
| 29 |
WARNING="file${COUNTER}_warning"
|
| 30 |
eval WARNING=\$$WARNING |
| 31 |
if [ "$WARNING" != "" ]; then |
| 32 |
echo "file_$COUNTER.warning $WARNING" |
| 33 |
fi |
| 34 |
|
| 35 |
# Associated critical level? |
| 36 |
CRITICAL="file${COUNTER}_critical"
|
| 37 |
eval CRITICAL=\$$CRITICAL |
| 38 |
if [ "$CRITICAL" != "" ]; then |
| 39 |
echo "file_$COUNTER.critical $CRITICAL" |
| 40 |
fi |
| 41 |
|
| 42 |
echo "file_$COUNTER.label $LABEL" |
| 43 |
echo "file_$COUNTER.type GAUGE" |
| 44 |
echo "file_$COUNTER.min 0" |
| 45 |
let COUNTER=COUNTER+1 |
| 46 |
done; |
| 47 |
|
| 48 |
echo "graph_order $GRAPH_ORDER" |
| 49 |
echo "graph_title File age" |
| 50 |
echo 'graph_args --base 1000 -l 0' |
| 51 |
echo 'graph_vlabel seconds' |
| 52 |
echo 'graph_category disk' |
| 53 |
|
| 54 |
exit 0 |
| 55 |
;; |
| 56 |
esac |
| 57 |
|
| 58 |
|
| 59 |
COUNTER=1 |
| 60 |
while [ $COUNTER -gt 0 ]; do |
| 61 |
FILE_COUNTER="file${COUNTER}_path"
|
| 62 |
eval FILE=\$$FILE_COUNTER |
| 63 |
if [ "$FILE" == "" ]; then |
| 64 |
break; |
| 65 |
fi |
| 66 |
|
| 67 |
# If the file isn't readable, say it's zero. |
| 68 |
if [ ! -r "$FILE" ]; then |
| 69 |
VALUE=0 |
| 70 |
else |
| 71 |
VALUE=$(($(date +%s) - $(stat -c '%Y' "$FILE"))) |
| 72 |
fi |
| 73 |
|
| 74 |
echo "file_$COUNTER.value $VALUE" |
| 75 |
let COUNTER=COUNTER+1 |
| 76 |
done; |
| 77 |
exit |
| 78 |
|
| 79 |
# -*- sh -*- |
| 80 |
|
| 81 |
: << =cut |
| 82 |
|
| 83 |
=head1 NAME |
| 84 |
|
| 85 |
file_age - Monitors the age of files. |
| 86 |
|
| 87 |
=head1 CONFIGURATION |
| 88 |
|
| 89 |
Since there is no way for the plugin to guess which files you want monitored, you're going to have to set each file up separately. Put the following in a file in your plugin-conf.d directory. |
| 90 |
|
| 91 |
[file_age] |
| 92 |
user root # May not be necessary, depending on which files you want monitored. |
| 93 |
|
| 94 |
env.file1_path /var/log/syslog # Mandatory, complete path to file. |
| 95 |
env.file1_label System syslog # Optional label if you don't want the file name to be displayed. |
| 96 |
env.file1_warning 86400 # Optional warning level. Measured in seconds. 86400 is one day of seconds. |
| 97 |
env.file1_critical 864000 # Optional critical level. Measured in seconds. |
| 98 |
|
| 99 |
Continue with file2, file3, etc... |
| 100 |
|
| 101 |
Here, have some seconds: |
| 102 |
|
| 103 |
3600 One hour |
| 104 |
7300 Two hours |
| 105 |
10800 Three hours |
| 106 |
21600 Six hours |
| 107 |
43200 Twelve hours |
| 108 |
86400 One day |
| 109 |
172800 Two days |
| 110 |
259200 Three days |
| 111 |
604800 One week |
| 112 |
|
| 113 |
=head1 AUTHOR |
| 114 |
|
| 115 |
Edward Plainview <it@sverigedemokraterna.se> |
| 116 |
|
| 117 |
=head1 DONATIONS |
| 118 |
|
| 119 |
If you wish to donate money for this plugin, please read https://it.sverigedemokraterna.se/donera/ |
| 120 |
|
| 121 |
=head1 LICENSE |
| 122 |
|
| 123 |
GPLv3 |
| 124 |
|
| 125 |
=head1 MAGIC MARKERS |
| 126 |
|
| 127 |
#%# family=auto |
| 128 |
|
| 129 |
=head1 VERSION |
| 130 |
|
| 131 |
1.0 released 2012-02-26 |
| 132 |
|
| 133 |
=cut |
