Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Detecting the UpTime of Web Server

0.00/5 (No votes)
19 Mar 2013 1  
Sometimes it would be necessary to check how long our web server has been running or if our web server is being restarted too many times. Here we discuss a simple solution for the same.
Introduction 

Occasionally, we would be in need to find how long our web server has been running and to find out whether the web server has been restarted or not, if it had experienced prolonged slowness for an extended period of time, say a couple of hours etc. In most of the hosting cases, we normally do not get a full console access to the web server and we might not be able to run the uptime.exe script that is normally available to check the uptime of a Windows system. Pinging the server might not be a valid choice because when the servers are behind NAT and firewalls, ICMP packets may either be blocked or might be responded to by the firewall. 

The Solution 

ASP.NET provides a sneak peek into system information through its Environment namespace and also Performance Counter. Here is a quick code tip as a humble endeavor to help people in deployment and maintenance of websites to have a comfortable control on their servers. 

Requirements 

All it needs for this quick utility is to have these two files 'default.aspx' (and/or its methods) in/as one of the webpages in your web application. There on when you visit the page, you would be given a quick option to check the uptime either through Performance Counter or Environment Tickcount. Though both are same, the latter was included as one of the options in the utility as guided by a peer member who suggested the same as a comment. 

Use of PerfCounter was actually for demonstration purposes on the same through ASP.NET. However, ASP.NET may run into permissions issue when going through this method.

Summary 

This utility, I hope would serve as quick tool as a sneak peek of the web server besides a learner's aide in using PerfCounters in ASP.NET. 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here