root / plugins / disk / du @ 16d38264
Historique | Voir | Annoter | Télécharger (2,34 ko)
| 1 | a6ddf6c8 | _KaszpiR_ | #!/bin/bash |
|---|---|---|---|
| 2 | |||
| 3 | ################################################################# |
||
| 4 | # |
||
| 5 | # Plugin to monitor the size of the specified directory |
||
| 6 | # |
||
| 7 | ################################################################# |
||
| 8 | # |
||
| 9 | # Parameters understood: |
||
| 10 | # |
||
| 11 | # config (required) |
||
| 12 | # autoconf (optional - checks if the path exists etc, not so advanced feature) |
||
| 13 | # |
||
| 14 | ################################################################# |
||
| 15 | # |
||
| 16 | # Requirements |
||
| 17 | # - bash (or change first line to sh instead of bash or any other shell) |
||
| 18 | # - existing and readable directory to scan |
||
| 19 | 17f78427 | Lars Kruse | # - du command, it exists on most of the *nix operating systems |
| 20 | a6ddf6c8 | _KaszpiR_ | # |
| 21 | ################################################################# |
||
| 22 | 17f78427 | Lars Kruse | # |
| 23 | a6ddf6c8 | _KaszpiR_ | # Configuration |
| 24 | # |
||
| 25 | # directory to check |
||
| 26 | DIR="/var/cache/apache2/" |
||
| 27 | |||
| 28 | fba800ae | Veres Lajos | # unique id, just in case you got multiple such scripts, change id as needed (i guess it should be obsolete, not tested) |
| 29 | a6ddf6c8 | _KaszpiR_ | ID=1; |
| 30 | |||
| 31 | fba800ae | Veres Lajos | # - make sure that user/group that executes this script has access to the directory you have configured |
| 32 | a6ddf6c8 | _KaszpiR_ | # otherwise run it as another user, edit plugins-conf.d/munin-node and stuff it with example below code (not suggested) |
| 33 | fba800ae | Veres Lajos | # remember to remove hashes from the beginning of the lines |
| 34 | a6ddf6c8 | _KaszpiR_ | # |
| 35 | # [du] |
||
| 36 | # user root |
||
| 37 | # |
||
| 38 | 8589c6df | klemens | # - by default the value is in MegaBytes, to change it you should edit below line in the script to something else, recognizable by du (see man du) |
| 39 | a6ddf6c8 | _KaszpiR_ | # du -sm $DIR in MB |
| 40 | # du -sk $DIR in KB |
||
| 41 | # |
||
| 42 | ################################################################# |
||
| 43 | # |
||
| 44 | # Changelog |
||
| 45 | # |
||
| 46 | # Revision 0.1 Tue 03 Feb 2009 02:16:02 PM CET _KaszpiR_ |
||
| 47 | 17f78427 | Lars Kruse | # - initial release, |
| 48 | # |
||
| 49 | a6ddf6c8 | _KaszpiR_ | ################################################################# |
| 50 | 8713eb37 | Lars Kruse | # Magick markers (optional - used by munin-config and some installation |
| 51 | a6ddf6c8 | _KaszpiR_ | # scripts): |
| 52 | #%# family=auto |
||
| 53 | #%# capabilities=autoconf |
||
| 54 | |||
| 55 | ################################################################# |
||
| 56 | ################################################################# |
||
| 57 | |||
| 58 | if [ "$1" = "autoconf" ]; then |
||
| 59 | if [ -d $DIR ]; then |
||
| 60 | echo "yes" |
||
| 61 | else |
||
| 62 | echo "no (check your path)" |
||
| 63 | fi |
||
| 64 | e4cd049b | Lars Kruse | exit 0 |
| 65 | a6ddf6c8 | _KaszpiR_ | fi |
| 66 | |||
| 67 | if [ "$1" = "config" ]; then |
||
| 68 | |||
| 69 | echo "graph_title Directory size: $DIR" |
||
| 70 | echo "graph_vlabel size MB" |
||
| 71 | echo "graph_category disk" |
||
| 72 | echo "graph_info Size of $DIR" |
||
| 73 | echo "dir$ID.label size" |
||
| 74 | echo "dir$ID.min 0" |
||
| 75 | echo "dir$ID.info Shows du -sm for specified directory" |
||
| 76 | |||
| 77 | exit 0 |
||
| 78 | fi |
||
| 79 | |||
| 80 | echo -n "dir$ID.value " |
||
| 81 | if [ -d $DIR ]; then |
||
| 82 | SIZE=`du -sm $DIR | cut -f1` |
||
| 83 | echo $SIZE |
||
| 84 | exit 0 |
||
| 85 | else |
||
| 86 | echo "U" |
||
| 87 | exit 1 |
||
| 88 | fi |
