Monitoring commands

  • In Ubuntu Desktop, check 'system monitor' app for UI stats of CPU, memory, process and file system

Memory Info

  • open following file
/proc/meminfo
o/p:
MemTotal: 32752748 kB
MemFree: 24057464 kB
MemAvailable: 30558528 kB
Buffers: 1394784 kB
Cached: 5151312 kB
..so on

CPU Info

  • open following file
/proc/cpuinfo
o/p:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i5-9500T CPU @ 2.20GHz
stepping : 10
microcode : 0xd6
cpu MHz : 3010.984
cache size : 9216 KB
..so on

top

  • following command shows auto refreshing stats
top
o/p
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1650 prasan 20 0 5018204 358568 116800 S 3.3 1.1 2:23.97 gnome-shell
1239 root 20 0 1131252 88988 53920 S 0.7 0.3 1:13.56 Xorg
1242 prasan 20 0 8632 5736 3860 S 0.7 0.0 1:44.66 dbus-daemon
1976 prasan 20 0 408316 48376 36856 S 0.7 0.1 0:58.20 vino-server
11099 prasan 20 0 20620 3908 3236 R 0.3 0.0 0:00.12 top
1 root 20 0 169300 13368 8472 S 0.0 0.0 0:02.75 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp
..so on

Note : NI means nice value/ priority

free

free -h
  • h : human readable
o/p:
total used free shared buff/cache available
Mem: 31Gi 1.6Gi 22Gi 33Mi 6.7Gi 29Gi
Swap: 59Gi 0B 59Gi

iftop

iftop is used to view the current bandwidth on a network interface. It listens to network traffic on a named interface and displays a table of current bandwidth usage by pairs of hosts

sudo apt install iftop
  • Now check connected internet interface
ip addr
o/p :
..
2: eno1: <NO-CARRIER,BROADCAST,MULTICAST,UP>
link/ether
... so on

check

say if eno1 is connected interface

sudo iftop -i eno1

ps

current shell

processes running in current shell

ps
o/p:
11030 pts/1 00:00:00 bash
11976 pts/1 00:00:00 ps

all active process

ps aux
o/p:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 169300 13368 ? Ss 21:21 0:02 /sbin/init splash
root 2 0.0 0.0 0 0 ? S 21:21 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< 21:21 0:00 [rcu_gp]
root 4 0.0 0.0 0 0 ? I< 21:21 0:00 [rcu_par_gp]
root 6 0.0 0.0 0 0 ? I< 21:21 0:00 [kworker/0:0H-kblockd]
root 9 0.0 0.0 0 0 ? I< 21:21 0:00 [mm_percpu_wq]
root 10 0.0 0.0 0 0 ? S 21:21 0:00 [ksoftirqd/0]
root 11 0.1 0.0 0 0 ? I 21:21 0:09 [rcu_sched]
root 12 0.0 0.0 0 0 ? S 21:21 0:00 [migration/0]
root 13 0.0 0.0 0 0 ? S 21:21 0:00 [idle_inject/0]
root 14 0.0 0.0 0 0 ? S 21:21 0:00 [cpuhp/0]
..so on

word count

ps aux | wc
251 2937 24176
  • total number of lines, words and characters

filter by grep

ps aux | grep sshd
o/p:
root 1035 0.0 0.0 12160 7276 ? Ss 21:22 0:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
root 10896 0.0 0.0 13976 9068 ? Ss 23:07 0:00 sshd: prasan [priv]
prasan 11029 0.0 0.0 13976 5980 ? S 23:08 0:00 sshd: prasan@pts/1
prasan 12004 0.0 0.0 17664 736 pts/1 S+ 23:37 0:00 grep --color=auto sshd
//example 2
ps aux | grep -i tomcat

kill process

kill processId
  • kill all instances of particular process
killall processName

check process status

sudo systemctl status processName

If it's a service, then can enable/ disable for auto start after boot

sudo systemctl enable serviceName
//stop & start service
sudo systemctl stop serviceName
sudo systemctl start serviceName
//check enabled services & disable not needed
systemctl list-unit-files --state=enabled

priority of process (nice)

  • nice : Adjusting the “niceness” value of processes allows for setting an advised CPU priority that the kernel's scheduler will use to determine which processes get more or less CPU time

link

  • from (-20) most priority to (20) least priority
  • nice command is used to start a process with specified nice value, which renice command is used to alter priority of running process.
    eg:
    //start a process with some priority
    nice -n -5 processName

//reset priority by process id renice -n 5 -p 2371

// reset priority by user name/ user id renice -n -2 -u userName

Note: 'man command' to get help/ options description quickly
## journalctl
Journalctl is a utility for querying and displaying logs from journald.
journal manages logs of all kernel and user processes.

journalctl --since "20 minutes ago"

journalctl | less

- journal entries that have been collected since the most recent reboot.

journalctl -b

Note : change Storage settings to persistent in /etc/systemd/journald.conf to save journal logs across/ past boots
- all logs by default at /var/log like auth.log, boot.log, syslog ..etc
- [Filtering journal](https://www.digitalocean.com/community/tutorials/how-to-use-journalctl-to-view-and-manipulate-systemd-logs)
- In ubuntu check **logs** app, arranged by category, can filter by time, also export to file..etc
### Managing logs
- to manage disk space, Linux automatically deletes most logs based on time..etc
For manual shrinking logs

//say shrink the jornal size to 1GB by deleting old logs (by size) sudo journalctl --vacuum-size=1G

// Any entries beyond that time are deleted(by time) sudo journalctl --vacuum-time=1years

Settings in /etc/systemd/journald.conf to limit journal storage
- change maximum disk space that can be used by 'SystemMaxUse' (persistent storage), 'RuntimeMaxUse'(volatile storage)
- [linux rotate logs](https://help.ubuntu.com/community/LinuxLogFiles)
## dmesg
- dmesg = driver message or display message
- It prints the message buffer of kernel
- messages are produced by the device drivers
//useful for new installation test

dmesg | less

//filter wireless lan messages dmesg | grep wl

## Nagios
https://www.nagios.org/