Linux System Monitoring Tricks

Common commands for Linux: System status

Check system running time

Sometimes we want to know the uptime since last restart of the system.

1
2
uptime
15:25:19 up 15 days, 5:35, 6 users, load average: 0.00, 0.00, 0.02

Check logged in users

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
who -a
system boot 2018-10-24 10:50
LOGIN tty1 2018-10-24 10:50 1740 id=tty1
ryan + pts/0 2018-11-06 11:47 old 31085 (tmux(31085).%0)
run-level 5 2018-10-24 10:51
bach + pts/1 2018-11-08 15:25 . 18851 (141.161.238.204)
chaz + pts/2 2018-10-31 14:38 03:42 24392 (141.161.238.171)
chaz + pts/3 2018-10-31 14:39 22:30 24521 (141.161.238.171)
ryan + pts/4 2018-11-06 14:10 old 31085 (tmux(31085).%2)
ryan + pts/5 2018-11-08 10:14 01:44 31085 (tmux(31085).%3)
pts/6 2018-11-08 13:50 31085 id=ts/6 term=0 exit=0
pts/7 2018-11-06 10:33 26453 id=ts/7 term=0 exit=0
pts/8 2018-11-06 10:33 26453 id=ts/8 term=0 exit=0
pts/9 2018-11-06 10:33 26453 id=ts/9 term=0 exit=0
pts/10 2018-11-05 12:01 26453 id=s/10 term=0 exit=0
pts/11 2018-11-06 10:33 26453 id=s/11 term=0 exit=0
pts/12 2018-11-06 10:33 26453 id=s/12 term=0 exit=0
pts/13 2018-11-06 10:33 26453 id=s/13 term=0 exit=0
pts/14 2018-11-06 10:33 26453 id=s/14 term=0 exit=0
pts/15 2018-11-06 10:33 26453 id=s/15 term=0 exit=0
pts/16 2018-11-06 10:33 26453 id=s/16 term=0 exit=0
pts/17 2018-11-06 10:33 26453 id=s/17 term=0 exit=0
pts/18 2018-11-06 10:33 26453 id=s/18 term=0 exit=0
pts/19 2018-11-06 10:33 26453 id=s/19 term=0 exit=0
pts/20 2018-11-06 10:33 26453 id=s/20 term=0 exit=0
pts/21 2018-11-06 10:33 26453 id=s/21 term=0 exit=0

Check system version information

1
2
uname -a
Linux wkstn-c30 4.4.0-138-generic #164-Ubuntu SMP Tue Oct 2 17:16:02 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Check current environment variables

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export
declare -x HOME="/home/bach"
declare -x LANG="en_US.UTF-8"
declare -x LIBVIRT_DEFAULT_URI="qemu:///system"
declare -x LOGNAME="bach"
declare -x MAIL="/var/mail/bach"
declare -x OLDPWD
declare -x PATH="/home/bach/bin:/home/bach/CRISPResso_dependencies/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
declare -x PWD="/home/bach"
declare -x SHELL="/bin/bash"
declare -x SHLVL="1"
declare -x SSH_CLIENT="141.161.238.204 53729 22"
declare -x SSH_CONNECTION="141.161.238.204 53729 141.161.238.154 22"
declare -x SSH_TTY="/dev/pts/1"
declare -x TERM="linux"
declare -x USER="bach"
declare -x XDG_DATA_DIRS="/usr/local/share:/usr/share:/var/lib/snapd/desktop"
declare -x XDG_RUNTIME_DIR="/run/user/1000"
declare -x XDG_SESSION_ID="3621"

check directory and file useage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
du -h --max-depth=1
8.0K ./.ssh
40K ./.texlive2018
614M ./.local
48K ./.byobu
154M ./.dropbox-dist
3.5G ./chebi
176M ./apache-tomee-plume-7.0.2_for_yaoxiang
28K ./.config
191M ./.cache
2.3G ./R
2.0G ./cmm_bak
90M ./ceu_mass_mediator
2.8M ./.rstudio
106M ./cmm_versions
28K ./.java
8.0K ./.mplayer
9.4G .

Check usage on mount

1
2
3
4
5
6
7
8
9
10
11
12
13
14
df -h
Filesystem Size Used Avail Use% Mounted on
udev 32G 0 32G 0% /dev
tmpfs 6.3G 66M 6.3G 2% /run
/dev/mapper/wkstn--c30--vg-root 1.8T 468G 1.3T 27% /
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/sda1 472M 210M 238M 47% /boot
cgmfs 100K 0 100K 0% /run/cgmanager/fs
//141.161.238.138/share 21T 6.4T 15T 31% /mnt/cifs
tmpfs 6.3G 0 6.3G 0% /run/user/1000
tmpfs 6.3G 0 6.3G 0% /run/user/1001
tmpfs 6.3G 0 6.3G 0% /run/user/1003

Check memeory usage

1
2
3
4
free -h
total used free shared buff/cache available
Mem: 251G 973M 130G 217M 120G 249G
Swap: 130G 14M 130G

Check virtual memeory usage

1
2
3
4
vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 14592 136961440 702160 125441376 0 0 0 1 0 0 1 0 99 0 0

Check IP

1
ip addr

Check network

1
netstat

get the processes relations

1
pstree

Dynamicaly get the information

1
2
3
watch -n 1 cat /proc/meminfo

watch -n 1 cat /proc/net/dev