Solved

specify thresholds monitoring for MS SQL filegroups

Posted on 2013-06-02
10
191 Views
Last Modified: 2013-06-11
Hello

            I try to specify thresholds monitoring for MS SQL filegroups.
            With the code below, the last specific threshold is applied to a database filegrou is not in the list $ LIST_SPEC_DB

            Monitoring.txt contains the following lines for exclude MS SQL Server filegroups :
            MASTER-PRIMARY:DB:0%:50%
            TEMPDB-PRIMARY:DB:2M:8M


            $_WARN_THRES="30%"
            $_PANIC_THRES="90%"

            $DBSPACE contains all MS SQL Filegroups

		$CHCK_SUP_ENV = (Test-Path $MONITORING -PathType Leaf)

		If (($CHCK_SUP_ENV)) {
		$Global:LIST_SPEC_DB=get-content $MONITORING | where-object {$_ -match(":DB:")}  -ErrorAction silentlycontinue
	
		
		if ($LIST_SPEC_DB -ne $null) {
		foreach ($DBS in $LIST_SPEC_DB) {
		$array_str = $DBS.split(":")
		$SPEC_DBSPACE = $array_str[0]
		$SPEC_WARN_SPRV = $array_str[2]
		$SPEC_PANIC_SPRV  = $array_str[3] 
					
		if ($DBSPACE -eq $SPEC_DBSPACE -and $SPEC_WARN_SPRV -match "%") {
		$_WARN_THRES=$SPEC_WARN_SPRV.replace("%","")
  
  		$_PANIC_THRES=$SPEC_PANIC_SPRV.replace("%","")
		
		$_UNIT="%"
		
		}
	
		elseif ($DBSPACE -eq $SPEC_DBSPACE -and $SPEC_WARN_SPRV -match "M") {
		$_WARN_THRES=$SPEC_WARN_SPRV.replace("M","")
  
  		$_PANIC_THRES=$SPEC_PANIC_SPRV.replace("M","")
		
		$_UNIT="M"
		
	
		
		}
		}
		}
		}
		

		
		elseif ($LIST_SPEC_DBS -eq $null -or $DBSPACE -ne $SPEC_DBSPACE ) {
		
		foreach ($DBS in $DBSPACE) {
		
  		$_WARN_THRES=$SEUIL_WARN_SPRV.replace("%","")
  
  		$_PANIC_THRES=$SEUIL_PANIC_SPRV.replace("%","")
		
		$_UNIT="%"

		}
		}

Open in new window

           How can I resolve this problem?

            Thanks
0
Comment
Question by:bibi92
  • 5
  • 3
  • 2
10 Comments
 
LVL 21

Expert Comment

by:oleggold
Comment Utility
0
 
LVL 21

Expert Comment

by:oleggold
Comment Utility
0
 
LVL 21

Expert Comment

by:oleggold
Comment Utility
0
 
LVL 21

Expert Comment

by:oleggold
Comment Utility
0
 
LVL 21

Expert Comment

by:oleggold
Comment Utility
#### Check Log and Data Growth for all User Databases. If they are not set up correctly then change them to the correct setting.
$servers = invoke-sqlcmd -serverinstance server -database Database -query “select InstanceName, Port from instance where IsActive = 1¿
$output = @()
foreach($instance in $servers)
{
$name = $instance.instancename
$port = $instance.port
$server = “$name,$port”
#echo “`n###########################

######”
#$server

$s = New-Object (‘Microsoft.SqlServer.Management.Smo.Server’) $server

$databases = $s.databases
#$databases | get-member | where {$_.membertype -eq “Property”}
foreach($database in $databases)
{
$dbsize = $database.size
$name = $database.name
## Check the log File
$logfiles = $database.logfiles
foreach($logfile in $logfiles)
{
$filename = $logfile.filename
$growth = $logfile.growth
$growthtype = $logfile.growthtype
$size = $logfile.size
if(($growthtype -eq “Percent”) -and ($name -ne “Master”) -and ($name -ne “Model”))
{
$logfile.growth = 65536
$logfile.growthtype = “kb”
$logfile.alter()

}
}
## Datafiles
$filegroups = $database.filegroups
foreach($group in $filegroups)
{
$files = $group.files
foreach($file in $files)
{
$filename = $file.filename
$type = $file.growthtype
$growth = $file.growth
$size = $file.size
if(($type -eq “Percent”) -and ($name -ne “Master”) -and ($name -ne “Model”))
{
if($dbsize -lt 10240)
{
$file.growth = 51200
$file.growthtype = “kb”
$file.alter()
}

if(($dbsize -gt 20480) -and ($dbsize -lt 51200))
{
$file.growth = 307200
$file.growthtype = “kb”
$file.alter()
}

if(($dbsize -gt 51200) -and ($dbsize -lt 102400))
{
$file.growth = 512000
$file.growthtype = “kb”
$file.alter()
}

if($dbsize -gt 102400)
{
$file.growth = 1048576
$file.growthtype = “kb”
$file.alter()
}

}
}
}
}
}

Open in new window

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:bibi92
Comment Utility
Thanks a lot but I have to keep the orignal code and modified it.
0
 
LVL 40

Expert Comment

by:Subsun
Comment Utility
Are you still looking for help on this?
If yes..

I can see you are reading the thresholds from a text file.. but I don't see any code which reads the current size of the database or database volume which you need to validate against the threshold.. Please correct me If I am wrong..

Once you get those values then you can use the comparison operators -lt -le or -gt -ge depends on the threshold settings..
http://ss64.com/ps/syntax-compare.html
0
 

Author Comment

by:bibi92
Comment Utility
Yes, I'm still looking for help. Yes, I'm readind the thresholds from a text file but I search write code which reads the current size of the database or database volume which you need to validate against the threshold.
Thanks
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
Comment Utility
Check this article from Scripting Guy! Blog and see if it helps.. It explains how to obtain SQL Server database sizes using PowerShell..

http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/02/use-powershell-to-obtain-sql-server-database-sizes.aspx
0
 

Author Closing Comment

by:bibi92
Comment Utility
Thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Set OWA language and time zone in Exchange for individuals, all users or per database.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now