#!/usr/bin/perl # # MoveCeiling v0.2 written 061206:1122 by BJP # # MoveCeiling will watch and automatically increase the size of an AIX + filesystem # given user-specified parameters. # # Usage: moveceiling <ceiling in MB> <filesystem> <increment size> <sl +eep time> <space to preserve> <notify counter> <email address> # Example: moveceiling 500 /tmp 64 30 3200 5 foo@bar.com # English: Keep 500MB free in /tmp. If you have to add space, add it i +n 64MB chunks. Check out the situation every 30 seconds. Preserve 320 +0MB in the volume group. Remind me every 5 times you have to increase + space, and send that reminder to foo@bar.com # use Mail::Sendmail; $ceilingSize=$ARGV[0]; $targetFS=$ARGV[1]; $incrementSize=$ARGV[2]; $sleepTime=$ARGV[3]; $preserveAmount=$ARGV[4]; $notifyCounter=$ARGV[5]; $mailRecipient=$ARGV[6]; $mailSender=$ENV{"USER"}."\@"."localhost"; if ($#ARGV!=6) { showUsage(); exit(); } spinUpRoutine(); mainRoutine(); spinDownRoutine(); sub showUsage() { print "\n MoveCeiling's job is to watch a filesystem, and incr +ease it's size if the\n"; print " amount of free space in that filesystem falls below th +reshold. MoveCeiling\n"; print " is much smarter than it used to be, but you should sti +ll use it with caution. \n"; print "\n"; print " Usage: moveceiling <ceiling in MB> <filesystem> < +increment size> <sleep time> <space to preserve> <notify counter> <em +ail address>\n"; print " Example: moveceiling 500 /tmp 64 30 5 foo\@bar.com\ +n"; print " In English: Every 30 seconds, check to see if /tmp has + at least 500MB free. \n"; print " If it sinks below 500MB, add another 64MB. + For every 5 times I \n"; print " add more space, i'll send a status message + to foo\@bar.com.\n"; print "\n\n"; exit(); } sub spinUpRoutine() { print "\nMoveCeiling: I will make sure $targetFS has at least +$ceilingSize MB free."; print "\nMoveCeiling: If I have to increase it's size, I will +do so in $incrementSize MB increments."; print "\nMoveCeiling: Every $notifyCounter times I do so, i'll + drop a note to $mailRecipient."; print "\nMoveCeiling: I'll stop adding storage if the volume g +roup has less than $preserveAmount MB remaining."; print "\nMoveCeiling: Starting up..\n"; ## Check to see if the filesystem actually exists... @dfContents=split(/\s+/,`df -m | grep " $targetFS\$"`); if(length($targetFS)==length($dfContents[6])) { print "MoveCeiling: Examining $dfContents[6]..\n"; } else { print "MoveCeiling: Uh-oh.. Can't find the filesystem +you specified ($targetFS)..! Exiting.\n\n"; exit(); } ## So far so good. Pull up the VG info for this filesystem.. $dfContents[0]=~/\/dev\//; $targetLV=$'; @lslvContents=split(/\s+/,`lslv $targetLV|head -n1` ); $targetVG=$lslvContents[5]; print "MoveCeiling: $targetFS belongs to logical volume $targe +tLV inside $targetVG.\n"; @lsvgDump=split(/\s+/,`lsvg -L $targetVG | head -n4 | tail -n1 +`); $lsvgDump[6]=~/\(/; $targetVGSpaceRemaining=$'; print "MoveCeiling: $targetVG has $targetVGSpaceRemaining MB r +emaining, of which $preserveAmount MB will be preserved.\n\n"; } sub mainRoutine() { while(true) { @dfContents=split(/\s+/,`df -m | grep " $targetFS\$"`) +; chomp($dateString=`date`); print "MoveCeiling: $dfContents[2] MB remaining in $ta +rgetFS as of $dateString.\n"; @lsvgDump=split(/\s+/,`lsvg -L $targetVG | head -n4 | +tail -n1`); $lsvgDump[6]=~/\(/; $targetVGSpaceRemaining=$'; if($dfContents[2] < $ceilingSize) # Tricky logic time. +. { if($targetVGSpaceRemaining >= ($preserveAmount ++$incrementSize)) { print "MoveCeiling: Less than $ceiling +Size MB remaining! Adding $incrementSize MB to $targetFS..\n"; system("echo `date` -- MoveCeiling: Le +ss than $ceilingSize MB remaining! Adding $incrementSize MB to $targe +tFS.. >>/tmp/moveceiling.log"); `chfs -a size=+"$incrementSize"M $targ +etFS`; $incrementCounter++; if($incrementCounter==$notifyCounter) { sendNotification(); $incrementCounter=0; } } else { system("echo `date` -- MoveCeiling: Pr +eserve limit reached. Committing suicide. $targetFS last seen with $d +fContents[2] MB free, $targetVGSpaceRemaiing MB remaining in $targetV +G. >>/tmp/moveceiling.log"); print "MoveCeiling: Increasing $target +FS by $incrementSize MB would eat into the preserved area! \n"; print "MoveCeiling: Preparing suicide +note to $mailRecipient..\n"; sendSuicideNote(); print "MoveCeiling: My hands are tied! + I'm sorry!\n"; spinDownRoutine(); exit(); } } else { print "MoveCeiling: More than $ceilingSize MB +remaining..No increase needed.\n"; } print "MoveCeiling: $targetVGSpaceRemaining MB remaini +ng in $targetVG. Sleeping for $sleepTime seconds..\n\n"; sleep($sleepTime); } } sub sendSuicideNote() { %mail=( To => $mailRecipient, From => $mailSender, Subject => "MoveCeiling Suicide Notice", Message => "Preserve limit reached -- Data loss may be + imminent. $targetFS last seen with $dfContents[2] MB free, $targetVG +SpaceRemaining MB remaining in $targetVG. ); sendmail(%mail); print "MoveCeiling: Suicide note sent.\n"; } sub sendNotification() { print "MoveCeiling: Sending a friendly reminder to $mailRecipi +ent..\n"; %mail=( To => $mailRecipient, From => $mailSender, Subject => "MoveCeiling Update", Message => "$targetFS still growing. Now at $dfContent +s[2] MB in size with $targetVGSpaceRemaining MB remaining in $targetV +G." ); sendmail(%mail); print "MoveCeiling: Mail sent.\n"; } sub spinDownRoutine() { print "MoveCeiling: Spinning down..\n\n"; }

In reply to MoveCeiling - monitor filesystem growth by bpoag

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.