September 8, 2008 at 1:22 pm
Let me start by saying I know very little about WMI. I need to setup some alerts for a SQL box if various conditions exist. For example cpu over x% for y period of time. Hard drive space falls below x% free. I know there are tools out there, but do to constraints I need to write my own code, alerts, etc.
It seems like WMI is an option. But I can not find any information on real life examples. All the code is either very basic (not enough) or non existant. Can anyone point me to some sample code, articles etc for these types of alerts in sql 2k5.
Thanks
September 8, 2008 at 3:01 pm
this should get info on all logical drives
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_LogicalDisk where drivetype=3 and freespace < 1073741824",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_LogicalDisk instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "DeviceID: " & objItem.DeviceID
Wscript.Echo "DriveType: " & objItem.DriveType
Wscript.Echo "Size: " & objItem.Size / 1073741824 & " GB's"
Wscript.Echo "FreeSpace: " & objItem.FreeSpace /1073741824 & " GB's"
Wscript.Echo "FileSystem: " & objItem.FileSystem
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "VolumeName: " & objItem.VolumeName
Wscript.Echo "VolumeSerialNumber: " & objItem.VolumeSerialNumber
Next
you just need to find any that have free space fall below your threshold 😎
for example the following WMI query
"SELECT * FROM Win32_LogicalDisk where drivetype=3 and freespace < 1073741824"
is checking for only logical disks which have less than 1GB of free space (the value is in bytes 😉 )
The WMI class i have used is addressable on win 2003\XP\Vista and 2000
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉
September 8, 2008 at 3:05 pm
Thanks.. that should help a lot for the disk space one.
Now on to figuring out the %cpu usage!
September 8, 2008 at 3:11 pm
dmc (9/8/2008)
Now on to figuring out the %cpu usage!
give it a go yourself and if you're still stuck post back.
Try searching for "Scripting guy", it'll be a lot of help 😉
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply