Solved

specify thresholds monitoring for MS SQL filegroups

Posted on 2013-06-02
10
195 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
ID: 39214513
0
 
LVL 21

Expert Comment

by:oleggold
ID: 39214514
0
 
LVL 21

Expert Comment

by:oleggold
ID: 39214516
0
 
LVL 21

Expert Comment

by:oleggold
ID: 39214520
0
 
LVL 21

Expert Comment

by:oleggold
ID: 39214521
#### 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

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

Expert Comment

by:Subsun
ID: 39221965
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
ID: 39223395
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
ID: 39224019
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
ID: 39237256
Thanks
0

Featured Post

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Synchronize a new Active Directory domain with an existing Office 365 tenant
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

21 Experts available now in Live!

Get 1:1 Help Now