Linux Uptime Command – How to check Server and Service uptime

Linux Uptime Command – How to check Server and Service uptime
 

Uptime of a server means how long the server is running since last reboot/shutdown. You can use different commands to check the uptime of linux server.

Try any of the below command to check uptime of your VPS/Dedicated server.
 


 

Uptime Command

 
1. Log into your linux server as ‘root’

2. Run the command ‘uptime’ to check the uptime of the server

‘uptime –pretty’ OR ‘uptime -p’ command will show the uptime of the server in days, hours and minutes.

[root@server ~]# uptime –pretty
up 3 days, 14 hours, 3 minutes

If you just type ‘uptime’ command it will display current server time, server uptime, numbers of users on server and load average.

[root@server ~]# uptime
22:10:29 up 3 days, 13:57, 1 user, load average: 0.07, 0.14, 0.14

22:10:29 = This is the current server time

3 days, 13:57 = This linux server is up for 3 days 13 hours and 57 minutes.

1 user = One user is currently online on the server

load average: 0.07, 0.14, 0.14 = This is the load average of the server.

“uptime –since” OR “uptime -s” command will display since when the server/system is up.

[root@server2 ~]# uptime –since
2016-08-10 08:12:58

Above linux Server is up since 2016-08-10 08:12:58
 


 

W command

 
‘w’ command can be used to check the uptime of your linux server/system. This command will display the current server time, server uptime, number of users on server and what they are doing etc

1. Log into your linux server via SSH as ‘root’

2. Run the command ‘w’ to check server uptime

[root@server2 ~]# w
22:37:00 up 3 days, 14:24, 1 user, load average: 0.41, 0.13, 0.13
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 180.215.42.43 22:10 4.00s 0.05s 0.00s w

The above linux server is online for 3 days 14 hours and 24 minutes.
 


 

top command

 
Top command will display server uptime, processes running under users, CPU usage, Memory usage, zombie process etc

1. Log into linux Server as root

2. Run the command ‘top -c’ to check the server uptime
 


 

cat /proc/uptime

 
‘cat /proc/uptime’ command will show the server uptime in seconds. The first number in the command output is the total number of seconds the server is up.

1. Log into linux Server as root

2. Run the command ‘cat /proc/uptime’ to check server uptime in seconds

[root@server ~]# cat /proc/uptime
311628.68 284895.28
 


 

last reboot

 
‘last reboot’ command will show when the server was last rebooted

1. Log into linux Server via SSH as ‘root’

2. Run the command ‘last reboot’ to check last reboot details and Server uptime

[root@server ~]# last reboot
reboot system boot 3.10.0-327.22.2. Wed Aug 10 08:12 – 22:53 (3+14:40)
 


 

How to check uptime of Apache Service

 
1. Log into linux server via SSH as ‘root’

2. Type any of the below commands to check the uptime of httpd service

httpd fullstatus | grep -i uptime

OR

systemctl status httpd.service (CentOS 7 Server)

[root@server ~]# httpd fullstatus | grep -i uptime
Server uptime: 4 days 1 hour 42 minutes 49 seconds

[root@server2 ~]# systemctl status httpd.service
Active: active (running) since Wed 2016-08-10 08:13:06 UTC; 4 days ago
 


 

How to check uptime of mySQL Service

 
1. Log into your Linux server as ‘root’

2. Type the below command to check the uptime of mysql process

Command :

mysqladmin version | grep -i uptime

OR

mysqladmin status

[root@server ~]# mysqladmin version | grep -i uptime
Uptime: 4 days 3 hours 26 min 1 sec

[root@server ~]# mysqladmin status
Uptime: 358436 Threads: 2 Questions: 353373 Slow queries: 0 Opens: 204 Flush tables: 1 Open tables: 193 Queries per second avg: 0.985

You can also check mySQL uptime from mySQL prompt. Type ‘\s’ to check the MySQL service uptime

[root@server ~]# mysql
mysql> \s

Uptime: 4 days 3 hours 34 min 42 sec
 


 

How to check Apache and server uptime on a cPanel/WHM Server

 
1. Log in to WHM (WebHost Manager)

2. Search for ‘Apache Status’ in WHM search bar

3. Click on ‘Apache Status’ under ‘Server Status’ to check Apache uptime
 

Linux server uptime

Linux server uptime


 
METHOD 2 :

You can also check server uptime by creating a PHP file under your website.

Create a file under document root of your website and enter the below code.
 

Uptime Linux Script

Uptime Linux Script


Save the file and exit.

Access the file in web browser to check the server uptime. The above code might not work if ‘system’ is disabled in php.ini (Remove ‘system’ from PHP disable_functions)
 

Server uptime

Server uptime