Click here to Skip to main content
6,630,586 members and growing! (15,820 online)
Email Password   helpLost your password?
Web Development » Site & Server Management » General     Intermediate

Detecting the UpTime of Web Server

By Vasudevan Deepak Kumar

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.
C#.NET 1.0, Win2K, WinXP, ASP.NET, Visual Studio, Dev
Posted:5 Dec 2002
Views:90,299
Bookmarked:38 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
15 votes for this article.
Popularity: 2.94 Rating: 2.50 out of 5
4 votes, 26.7%
1
4 votes, 26.7%
2
1 vote, 6.7%
3
4 votes, 26.7%
4
2 votes, 13.3%
5

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. Recently we experienced this issue of Ping timing out, SMTP not responding with our domain for a while and we suspected whether the server is going for a restart or not.

Peek Into System Environment Variables and Counters

After a brief search into MSDN, a small code trick did the job of finding how long the web server had been running. Moreover, this research also revealed one more way of getting the name of the machine from environment variables, besides the usual way.

Server.MachineName

The Code

The actual code that does this trick is:

PerformanceCounter pc = new PerformanceCounter("System",
    "System Up Time");

//Normally starts with zero. do Next Value always.

pc.NextValue(); 
TimeSpan ts = TimeSpan.FromSeconds(pc.NextValue());
    
Response.Write("This system " + Environment.MachineName + 
    " has been up for " + ts.Days + " days " + ts.Hours + 
    " hours, " + ts.Minutes + " and " + ts.Seconds + 
    " seconds.");

I hope this piece of code would really be useful as a ready-reckoner to find out how long the web server has been running.

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

About the Author

Vasudevan Deepak Kumar


Member
Vasudevan Deepak Kumar is from Chennai, India who has been in the programming career since 1994, when he was 15 years old. He has his Bachelors of Engineering (in Computer Science and Engineering) from Vellore Engineering College (now VIT University). He also has a MBA in Systems from Alagappa University, Karaikudi, India.


He started his programming career with GWBasic and then in his college was involved in developing programs in Fortran, Cobol, C++. He has been developing in Microsoft technologies like ASP, SQLServer 2000. For sometime, he has also been with PHP and MySQL based development in one of his previous organizations. Now currently his focus is on Microsoft .NET World (ASP.NET, C# and Whidbey)


In his past-time, he listens to polite Carnatic Music.

Web Presence



Homepage

http://www.lavanyadeepak.tk/

Blogs



Technical




Gossips




Spiritual







Occupation: Web Developer
Location: India India

Other popular Site & Server Management articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 23 of 23 (Total in Forum: 23) (Refresh)FirstPrevNext
Generalany one have aspx file which can work with remote computer. PinmemberMember 266788219:45 5 Jan '09  
GeneralRe: any one have aspx file which can work with remote computer. Pinmembermbaocha14:13 29 Apr '09  
GeneralDid I get it wrong? PinmemberRobMeade0:06 31 May '06  
GeneralRe: Did I get it wrong? Pinmembermbaocha20:19 9 May '09  
GeneralHow to use my web application on another computer PinmemberNisarat19:25 30 Jun '05  
GeneralUptime with WMI Pinmemberjserban5:46 23 May '05  
GeneralMilliseconds instead of Seconds? PinmemberSunB13:12 21 Apr '05  
GeneralVery good PinmemberFFSysCode20:06 12 Jan '05  
GeneralEasier way, without worrying about the "Access Denied" message. PinmemberClinton Frankland10:44 14 Jan '04  
GeneralRe: Easier way, without worrying about the "Access Denied" message. PinmemberMatt Philmon8:56 11 Feb '04  
GeneralRe: Easier way, without worrying about the "Access Denied" message. PinmemberRheal_Notes16:25 3 Jul '06  
Generalplease, what's your system setup? PinsussAnonymous17:26 12 Dec '02  
GeneralCode does not work? Pinmembersmday111:37 10 Dec '02  
GeneralRe: Code does not work? PinsussAnonymous17:24 12 Dec '02  
GeneralRe: Code does not work? Pinmemberevansc20:45 25 Dec '03  
GeneralRe: Code does not work? PinmemberClinton Frankland10:45 14 Jan '04  
GeneralRe: Code does not work? PinmemberVDragon11:49 26 Oct '06  
GeneralRe: Code does not work? PinmemberMatt Philmon8:57 11 Feb '04  
GeneralUptime.exe PinmemberAnders Molin22:56 5 Dec '02  
GeneralRe: Uptime.exe PinmemberDeepak Kumar Vasudevan23:25 5 Dec '02  
GeneralRe: Uptime.exe PinmemberMegan Forbes2:58 9 Dec '02  
GeneralRe: Uptime.exe PinsussAnonymous15:07 24 Sep '03  
GeneralRe: Uptime.exe PinmemberRheal_Notes16:35 3 Jul '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Dec 2002
Editor: Smitha Vijayan
Copyright 2002 by Vasudevan Deepak Kumar
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project