SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Server Up-Time Information


Server Up-Time Information

Author
Message
Michael L. Smith
Michael L. Smith
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 38
Comments posted to this topic are about the item Server Up-Time Information
rbandyo
rbandyo
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 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;
Selva Jayakar
Selva Jayakar
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 298
All my installations seems to have negative values in the sample_ms column. Seems to be a bug or an overflow .
DCPeterson
DCPeterson
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1605 Visits: 432
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



*****************/
SwePeso
SwePeso
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4147 Visits: 3433
The script calculates the uptime for the server, not the database service.


N 56°04'39.16"
E 12°55'05.25"
Mark D Powell
Mark D Powell
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1857 Visits: 463
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 --
Iwas Bornready
Iwas Bornready
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14030 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search