locked
Monitor file growth RRS feed

  • Question

  • Hello everyone,

    We have a database running with a transaction log that sometimes has exceptionally growth.

    I'm looking for a script that will monitor the log file size increase over time.

    I was trying to create a few variables that would compare the size with the size of 5-10 minutes ago and then send an e-mail if the value was greater than X GB's but so far no success.

    Just to be clear: I'm not looking for a script that generates a message when the file reaches a certain size. This is purely to monitor huge growth is a short amount of time.

    Can anyone help me with this ?




    • Edited by Ro_vi Thursday, November 1, 2018 1:17 PM
    Thursday, November 1, 2018 1:15 PM

Answers

  • There's nothing very wrong with your initial solution. No need for two scripts. Just schedule to run on system startup. This will run forever. :-)

    $a = ((Get-Item filepath).length/1gb)
    While ($TRUE)
    {
        sleep -Seconds (5*60)
        $b = ((Get-Item filepath).length/1gb)
        if ( ($b - $a) -gt 3)
        {
            Send-MailMessage
        }
        $a = $b
    }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Proposed as answer by BOfH-666 Thursday, November 1, 2018 3:55 PM
    • Marked as answer by Ro_vi Thursday, November 1, 2018 4:05 PM
    Thursday, November 1, 2018 3:38 PM

All replies

  • ...  but so far no success.  ....
    What does that mean? We do not write ready to use code on request. Show your code and tell us what's not wirking and we will try to help you.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Thursday, November 1, 2018 1:34 PM
  • #$a has to get its value first and not being overwritten when $b gets its value

    $a = ((Get-Item filepath).length/1gb)

    #$b has to be filled 10 minutes later
    $b = ((Get-Item filepath).length/1gb)

    $c = $b-$a

    if ($c -gt 3) {
    Send-MailMessage
    }
    #$a has to get the value $b had. This entire script should be looped from now on.



    • Edited by Ro_vi Thursday, November 1, 2018 3:38 PM
    Thursday, November 1, 2018 2:52 PM
  • You don't say if your concern is that the log file's growth is an indicator of a problem with an application, or if you're concerned with the possibility of the log file exhausting the free space on the disk.

    Is the log file on its own disk (it should be)? You might be better off monitoring free space (or lack thereof) on the disk. That might even be helpful if the log file shares the disk with other files.

    You could use this as a starting point:

    https://stackoverflow.com/questions/12159341/how-to-get-disk-capacity-and-free-space-of-remote-computer

    Sleep between execution of the query, and store the prior result for comparison. If the difference between the two exceeds what you expect send the mail. An added benefit is that you'll be able to signal an impending problem even if the free space decreases at a rate less than your threshold.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Thursday, November 1, 2018 3:01 PM
  • Have the script run upon system startup and simply loop between sampling the size. Add a sleep interval between samples.

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Thursday, November 1, 2018 3:03 PM
  • Hey Rich,

    The application is used by a different department. It's a known issue with the application that it sometimes starts looping.

    I have disk monitoring with SCOM but I'd like to know asap when the app. is bugging out again.

    Thursday, November 1, 2018 3:07 PM
  • $a = ((Get-Item filepath).length/1gb)


    $b = ((Get-Item filepath).length/1gb)

    $c = $b-$a

    if ($c -gt 3) {
    Send-MailMessage
    }


    I want to run/schedule a script every 10 minutes or so. Where $a gets the file size value 10 minutes behind $b

    This way I can compare the 2 values and save the difference in $c. If the difference is above x GB's, I want to send an e-mail.

    As you can see, the problem is the starting value ($a). How do i prevent the first value from being over-written every time the script runs.

    An easy fix would be to schedule 2 scripts, 1 script creating $a and the other script creating $b and comparing them to each other. I'm hoping this is possible in one script though.



    Your script to me would not work. Looking at variable $a and $b, by the statement you provided, they would return the same value so $c would = 0

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Thursday, November 1, 2018 3:26 PM
  • I know, I want to isolate the first line but don't really know how.

    I've editted the post. Maybe it's more clear now.

    • Edited by Ro_vi Thursday, November 1, 2018 3:38 PM
    Thursday, November 1, 2018 3:30 PM
  • You can't run a script to go back in time 10 minutes to collect the data unless you are continually collecting it.  For the suggested code block just add a sleep timer in between:

    $a = ((Get-Item filepath).length/1gb)
    
    Start-Sleep -s 600
    
    $b = ((Get-Item filepath).length/1gb)
    
    $c = $b-$a
    
    if ($c -gt 3) {
    Send-MailMessage
    }
    I would probably run a collection every "x" minutes which writes the size/data either to a database table or a CSV file.  You can then evaluate this information at any time, or run another script which will read this data output and report on it.

    Thursday, November 1, 2018 3:36 PM
  • There's nothing very wrong with your initial solution. No need for two scripts. Just schedule to run on system startup. This will run forever. :-)

    $a = ((Get-Item filepath).length/1gb)
    While ($TRUE)
    {
        sleep -Seconds (5*60)
        $b = ((Get-Item filepath).length/1gb)
        if ( ($b - $a) -gt 3)
        {
            Send-MailMessage
        }
        $a = $b
    }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Proposed as answer by BOfH-666 Thursday, November 1, 2018 3:55 PM
    • Marked as answer by Ro_vi Thursday, November 1, 2018 4:05 PM
    Thursday, November 1, 2018 3:38 PM
  • I got this so far:

    $a = ((Get-Item filepath).length/1gb)

    Start-Sleep -s 600

    $b = ((Get-Item filepath).length/1gb)

    $c = $a-$b

    if ($c -gt 5) {
    Send-MailMessage
    }

    $a=$b

    Edit: Ah thanks Rich, thats indeed what I was looking for. I just found out about the sleep part myself. I'll check if the looping works.



    • Edited by Ro_vi Thursday, November 1, 2018 3:44 PM
    Thursday, November 1, 2018 3:41 PM