Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Server Up-Time Information Expand / Collapse
Author
Message
Posted Monday, September 24, 2007 6:22 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, March 3, 2011 1:01 PM
Points: 6, Visits: 38
Comments posted to this topic are about the item Server Up-Time Information
Post #402310
Posted Monday, November 5, 2007 3:11 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, October 16, 2012 11:02 AM
Points: 46, Visits: 80
Nice query!! But the server start time is not coming out correct as you are subtracting all the days, and then all the hours and all the minutes. Just subtracting the total minutes of uptime from the current time should show the right date and time the server was last started.

WITH ServerUpTimeInfo AS (
SELECT (dm_io_virtual_file_stats.sample_ms / 1000.00 ) / 60.00
AS server_up_time_min,
((dm_io_virtual_file_stats.sample_ms / 1000.00 ) / 60.00) / 60.00
AS server_up_time_hr,
(((dm_io_virtual_file_stats.sample_ms / 1000.00 ) / 60.00) / 60.00) / 24.00
AS server_up_time_day
FROM sys.dm_io_virtual_file_stats(1,1) AS dm_io_virtual_file_stats )
SELECT CAST(server_up_time_min AS decimal(12,2)) AS server_up_time_min,
CAST(server_up_time_hr AS decimal(12,2)) AS server_up_time_hr,
CAST(server_up_time_day AS decimal(12,2)) AS server_up_time_day,
CAST(DATEADD(mi,
-ROUND(server_up_time_min, -1), getutcdate()) as smalldatetime
) as approx_server_start_utc_datetime
FROM ServerUpTimeInfo;


Post #418785
Posted Thursday, November 15, 2007 8:02 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, October 23, 2014 11:37 AM
Points: 6, Visits: 248

All my installations seems to have negative values in the sample_ms column. Seems to be a bug or an overflow .
Post #422650
Posted Friday, April 11, 2008 4:02 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 8:16 AM
Points: 1,035, Visits: 410
There's a much simpler way to do this:

select ServerUptimeInHrs = datediff(hh, Login_time, current_timestamp)
from sys.dm_exec_sessions
where session_id = 1

That gives you the hours, obviously days, minutes or whatever are just as easy to calculate...



/*****************

If most people are not willing to see the difficulty, this is mainly because, consciously or unconsciously, they assume that it will be they who will settle these questions for the others, and because they are convinced of their own capacity to do this. -Friedrich August von Hayek



*****************/
Post #483998
Posted Monday, December 7, 2009 3:27 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 11:02 AM
Points: 2,397, Visits: 3,419
The script calculates the uptime for the server, not the database service.


N 56°04'39.16"
E 12°55'05.25"
Post #829716
Posted Thursday, November 17, 2011 10:58 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, October 22, 2014 2:00 PM
Points: 1,384, Visits: 402
It aslo calculates a start time in the future:

server_up_time_min server_up_time_hr server_up_time_day approx_server_start_utc_datetime
-26332.06 -438.87 -18.29 2012-01-13 08:47:00


HTH -- Mark D Powell --
Post #1207759
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse