- Introduction
- Monitoring Server Hardware for Performance
- Monitoring Server Services for Uptime
- Conclusion
Monitoring Server Services for Uptime
Once you get your hardware monitored for performance, it's a good idea to monitor important services for uptime. By doing both, you'll have a well-rounded monitoring system for performance and uptime.
I think one of the most important server services to be monitored is the web service. Today, things are becoming more web-based all the time—mostly for convenience. Internet Information Services (IIS) happens to be the most widely used web server for web applications in the world right now. If you're an administrator, making sure that your web sites are running day in and day out are critical to your business. Listing 3 is a simple sample script using WMI that I created to check the status of web sites hosted with IIS 6.0.
Listing 3 WMI Script for Monitoring Web Sites
1 strComputer = "." 2 Set objWMIService = GetObject _ 3 ("winmgmts:{authenticationLevel=pktPrivacy}\\" _ 4 & strComputer & "\root\microsoftiisv2") 5 Set colItems = objWMIService.ExecQuery("Select * from IIsWebServer") 6 For Each objItem in colItems 7 If objItem.ServerState = 4 Then 8 If objItem.Name = "W3SVC/1" Then 9 Wscript.Echo "Default web site is down" 10 End If 11 If objItem.Name = "W3SVC/2" Then 12 Wscript.Echo "Administration web site is down" 13 End If 14 End If 15 Next
The script checks each web site on the server to determine whether the site is running. If the server state is 4 (see line 7), the site is not running, and the script displays the appropriate site alert. The WMI service reports the web site's name (using the Name property) as the number that IIS assigned to the web site when the site was created, for logging purposes. For example, on line 8 the script reports the name of the default website as W3SVC/1. This is the same log file directory path that was created for the site in the winnt/system32/logfiles directory. W3SVC stands for World Wide Web service, and 1 is the number that was assigned to the site when created (it was created first). In lines 8–13, I tell the script to display the actual name given to the site in English, instead of just using the Name property. You could use a time interval with this script, such as the one used earlier in this article for checking the CPU, or use the Task Manager to schedule script execution.
Another service well worth monitoring ise the mail service. The script in Listing 4 is similar to the script in Listing 3, but instead monitors the mail service.
Listing 4 WMI Script for Monitoring Mail Servers
1 strComputer = "IO" 2 Set objWMIService = GetObject _ 3 ("winmgmts:{authenticationLevel=pktPrivacy}\\" _ 4 & strComputer & "\root\microsoftiisv2") 5 Set colItems = objWMIService.ExecQuery("Select ServerState from IIsSmtpServer") 6 For Each objItem in colItems 7 If objItem.ServerState = 4 Then 8 Wscript.Echo "IO Mail Server is down" 9 End If 10 Next
On line 8, I tell the script to send an alert message when the mail server is down on a server named IO. The WMI service actually uses queries in the form of SQL called WQL to retrieve information (see line 5). This makes it convenient for anyone who knows SQL to run queries against WMI, to return information in an easy and timely manner.