Using the UPTIME Utility to Monitor Servers

  • Comments posted to this topic are about the item Using the UPTIME Utility to Monitor Servers

  • For SQL Server 2008 you can execute the following query to obtain the server start time. This is a lot simpler than running a command line utility.

    SELECT sqlserver_start_time FROM sys.dm_os_sys_info

  • drikusvd (6/22/2010)


    For SQL Server 2008 you can execute the following query to obtain the server start time. This is a lot simpler than running a command line utility.

    Well, except that gives you the time the SQL Server started, which isn't necessarily the same as the time the server started. Secondly, that won't work for a server that you might want to monitor that doesn't actually have SQL Server installed on it!

  • Secondly, that won't work for a server that you might want to monitor that doesn't actually have SQL Server installed on it!

    Since I'm a DBA, i'm only interested in servers which have SQL installed (I only get payed for that)

    Another way to determine the uptime for SQL Server is to query the creation time from TempDB

    Wilfred
    The best things in life are the simple things

  • As you said in the article, enable xp_cmdshell is not the best option and a solution would be to create a CLR function to get the uptime.

    But, as the uptime it has nothing to do with SQL Server, because it's a Windows "function", it might be a good idea to get the information using a PowerShell script.

  • Powershell would be a good option and the one I'd pursue.

    However for those that don't want to dabble in Powershell and don't want to enable xp_cmdshell, you can pipe the output from uptime into a text file and then use osql/sqlcmd to import the file into the DB.

    --------------------
    Colt 45 - the original point and click interface

  • The one problem we have with measuring uptime is that the server uptime doesn't necessarily mean the SQL Server was accessible at all times. We made a custom check to run from a centralized server to check connectivity every 9 minutes to make sure a simple select runs against master. However, it's hard to measure the pct of uptime strictly of SQL Server.

    The logic I currently try to use it 100-((num_of_connectivity_failures/160)*100) = pct_uptime_for_connectivty_to_sql

    1440 minutes in a day / 9 minutes = 160 connectivity checks per day.

    For our missions critical systems, we check connectivity to the individual databases every minute, so the checks would be more 1440 checks per day and the percentage becomes more accurate.

    Any other thoughts / suggestions are always welcomed though.

    Steve

  • Good Article, uptime is sadly outdated and often crashes on Win2008

  • I would highly recommend against enabling xp_cmdshell, enabling this feature just opens up a can of worms - especially when the SQL Server service is running under a privileged account like the LocalSystem user.

    We use EventSentry (http://www.eventsentry.com) to track server uptime - it keeps a log of all reboots, shows graphs of server's uptimes (e.g. for comparison), logs the longest uptime for a server and more.

    It also monitors services, if one wants to track the SQL Server services themselves.

  • lake_xp: Check out the NTToolkit http://www.netikus.net/products_nttoolkit.html, it also includes a "uptime.exe". For a simple display, just run "uptime /onetime". Unfortunately it doesn't run against remote machines (yet).

  • WizardOfOz - thanks However, i'm extremely wary of 3rd party .exes on our production boxes. I'd strongly recommend testing this thoroughly in a test environment. ...oh the irony of a utility to test uptime that brings your systems down 🙂

  • 🙂

    Well, it's not really an install anyways, just a command-line app. But if you rather use Microsoft's outdated version that crashes - or enable xp_cmdshell then please go ahead 😉

    I actually wrote that tool, and it just queries the uptime from a Windows performance counter - so it's pretty safe 🙂

  • I do not agree to enable xp_cmdshell also no longer used in recent versions of SQL. Sorry.

    Itu.

  • Since someone mentioned using CLR to get this information I will say that my SQLCLR project, SQL# (SQLsharp), includes this function. It is usable in SQL Server 2005 and 2008 and is the real system uptime, not the DB uptime. It returns the number of milliseconds since the system was started. This can be used to determine what the exact date & time via:

    SELECT DATEADD(MILLISECOND, (SQL#.OS_Uptime() * -1), GETDATE())

    I hope this helps.

    Take care,

    Solomon...

    SQL#https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
    Sql Quantum Lifthttps://SqlQuantumLift.com/ ( company )
    Sql Quantum Leaphttps://SqlQuantumLeap.com/ ( blog )
    Info sitesCollations     •     Module Signing     •     SQLCLR

  • WizardOfOz - thanks

    I only mentioned testing as each org is different. We use Applocker in our environment to lock down all .exes, .DLLs etc on production boxes so anyone who has a similar setup would need to go through the ropes of testing before approval. Good to know though even if your .exe does not do remote uptime (as yet 🙂

Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in to reply to this topic. Login to reply