Categories : Linux

 

#————————–[ Monitoring the System ]————————-#
This article provides the basics about monitoring the system in linux

# By
# VirtualLino
# virtuallino@linuxmail.org
Date: 10/8/2003
10:15 pm
……………………………………………………………………..

#–[ Commands for monitoring the system ]–#

pstree
top
ps
vmstat
free
uname
uptime
w
who
whoami
who am i
lsmod
runlevel
hostname

#———————————{ pstree }———————————–#

pstree It displays the tree of processes and parent-child
processes relationship

pstree -a Shows command line arguments

#———————————-{ top }————————————-#

top Shows top CPU processes.
It provides an ongoing look at processor activity in
real time.

e.g
the output of top command

12:18am up 3 min, 4 users, load average: 0.02, 0.05, 0.02
41 processes: 40 sleeping, 1 running, 0 zombie, 0 stopped
CPU states: 2.0% user, 2.8% system, 0.0% nice, 95.1% idle

Mem: 125172K av, 55568K used, 69604K free, 0K shrd, 7780K buff
Swap: 514040K av, 0K used, 514040K free 23400K cached

PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
720 root 15 0 1008 1008 836 R 0.9 0.8 0:00 top
1 root 15 0 480 480 428 S 0.0 0.3 0:03 init
2 root 15 0 0 0 0 SW 0.0 0.0 0:00 keventd
3 root 15 0 0 0 0 SW 0.0 0.0 0:00 kapmd
4 root 34 19 0 0 0 SWN 0.0 0.0 0:00 ksoftirqd_CPU0
5 root 15 0 0 0 0 SW 0.0 0.0 0:00 kswapd
6 root 25 0 0 0 0 SW 0.0 0.0 0:00 bdflush
7 root 15 0 0 0 0 SW 0.0 0.0 0:00 kupdated
8 root 25 0 0 0 0 SW 0.0 0.0 0:00 mdrecoveryd
105 root 15 0 0 0 0 SW 0.0 0.0 0:00 kjournald

explained below:

1.First line (you can toggle it on or off by `l’)
12:18am up 3 min, 4 users, load average: 0.02, 0.05, 0.02

This line is actually same as output of `uptime’ command
This line displays the time the system has been up and three load averages
for the system for the past 1, 5 and 15 minutes.

2.Second line
41 processes: 40 sleeping, 1 running, 0 zombie, 0 stopped

This line shows the total number of processes.
This is also broken down into the number of tasks which are running,
sleeping, stopped or undead(zombie)

3.Third line
CPU states: 2.0% user, 2.8% system, 0.0% nice, 95.1% idle

It displays the percentage of CPU time in user mode, system mode, niced tasks
(those are whose nice value is negative) and idle.

4.Fourth line
Mem: 125172K av, 55568K used, 69604K free, 0K shrd, 7780K buff
It provides the statistics on memory usage, including total available memory,
free memory, shared memory and memory used for buffers.

5.Fifth line
Swap: 514040K av, 0K used, 514040K free 23400K cached

It provides the statistics on swap space, including total swap space,
available swap space and used swap space.

Note: The output of the fourth line and fifth line are same as of `free’
command.

6.Sixth line
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
1 root 15 0 480 480 428 S 0.0 0.3 0:03 init

PID – process ID of every task
USER – parent process ID of every task
PRI – the priority of the task
NI – the nice value of the task
You can set the renice a value in range of +20 to -20
+20 lowest priority
-20 highest priority
SIZE – size of the task’s code, data and stack space in kb.
RSS – the total amount of physical memory used by the task in kb.
SHARE – the amount of shared memory used by the task in kb.
STAT – the state of the task
S — sleeping
D — uninterruptible sleep
R — running
Z — zombies
T — stopped/traced
N — Positive nice value
W — swapped out process

%CPU – task’s share of the CPU time
%MEM – task’s share of the physical memory
TIME – total CPU time the task has used
COMMAND – the task’s command name

You can toggle some options by several commands while top is running, but
here I am gonna do some of it.

r – renice a process. The default renice value is 10.
When u hit `r’ command, it asks for PID to renice and after
that a value to set
You can set the renice a value in range of +20 to -20
+20 lowest priority
-20 highest priority
You can do this even by command arguments i.e by `renice’ For this info
lookout for my next tutorial on Process Mangement.

k – To kill a process
It will prompt you for PID of the running task which you want to
stop and signal to kill

15 – normal kill (This signal is default for `kill’ command)
9 – abrupt kill

Configuration files:
——————-
/etc/toprc The global configuration file
~/.toprc The personal configuration file
To know more about this conf files read man pages of top(1)

#———————————-{ ps }————————————–#

ps It reports process status

ps -a displays all processes including other users.

ps -ef displays all processes with full listings

ps -auxw displays all processes in user oriented format and selects
processes without controlling ttys with wide output.

u – display user-defined format
x – selects processes without controlling ttys
w – wide output

#———————————{ vmstat }———————————–#

vmstat Monitors virtual memory

procs memory swap io system cpu
r b w swpd free buff cache si so bi bo in cs us sy id
0 0 0 2208 24152 39008 30028 0 0 60 23 561 104 1 1 98

It displays information about processes, memory, paging, block IO, traps
and cpu activity.

Procs
r - The number of processes waiting for run time.
b - The number of processes in uninterruptible sleep.
w – The number of processes swapped out

Memory
swpd - The amount of virtual memory used in kb
free - The amount of idle memory used in kb
buff – The amount of memory used as buffers in kb

Swap
si - Amount of memory swapped in from disk in kb
so - Amount of memory swapped to disk in kb

IO
bi - Blocks sent
bo - Blocks received

System
in - The number of interrupts per second
cs - The number of context switches per second

CPU
These are the percentages of total CPU time
us - user time
sy - system time
id - idle time

#———————————-{ free }————————————#

free Displays amount of free and used memory in the system

total used free shared buffers cached
Mem: 125172 101020 24152 0 38992 30016
-/+ buffers/cache: 32012 93160
Swap: 514040 2208 511832

note :
You can see the same memory information from /proc/meminfo

#———————————-{ uname }———————————–#

uname Prints system information

uname -a prints all information

Linux linobox.bom.labs.net 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686
i386 GNU/Linux

uname -r prints the kernel release (2.4.18-14)

uname -i prints the hardware platform (i386)

#———————————-{ uptime }———————————-#

uptime Tell how long the system has been running. Also number of
users and system’s load average.

#————————————-{ w }————————————#

w Show who is logged on and what they are doing.

3:25am up 3:11, 4 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 – 12:14am 12.00s 0.76s 0.67s vim sysmonitor
root tty2 – 12:15am 1:48 0.17s 0.00s vi naresh.txt
root tty3 – 12:15am 0.00s 0.20s 0.00s w
root tty6 – 12:15am 2:45 0.20s 0.13s links worli.html

The following entries are displayed for each user:
login name
tty name
remote host
login time
idle time
JCPU (time used by all processes attached to the tty)
PCPU (time used by the current process)
WHAT (command line arguments)

#———————————–{ who }————————————#

who Shows who is logged on only

e.g
# who
login names Terminal type Date login time
root tty1 Aug 10 08:34
naresh tty2 Aug 10 08:41
sheena tty3 Aug 10 10:11
priya tty4 Aug 10 09:00
anu tty5 Aug 10 10:01
mayur tty6 Aug 10 08:45

#———————————{ whoami }———————————-#

whoami Prints the user name

#——————————–{ who am i }———————————-#

who am i Prints the user name with terminal type

e.g
# who am i
ashish tty4 Aug 5 09:00

#———————————–{ lsmod }———————————-#

lsmod List all currently loaded kernel modules.
Same as `cat /proc/modules’

e.g

Module Size Used by Not tainted
es1371 30760 0 (autoclean)
ac97_codec 13384 0 (autoclean) [es1371]
gameport 3396 0 (autoclean) [es1371]
soundcore 6532 4 (autoclean) [es1371]

The format is name, size, use count

#———————————{ runlevel }———————————#

runlevel Displays the current and previous system runlevel

Runlevel reads the system utmp file (/var/run/utmp) to locate the runlevel
record

e.g
the output of runlevel

N 3

N — This means no previous system runlevel
3 — current system runlevel

#———————————{ hostname }———————————#

hostname Displays/Changes the systems node name.
But also manually change the hostname setting in
/etc/sysconfig/network

hostname -d Display the name of the DNS domain

hostname -f Display the FQDN (Fully Qualified Domain Name)

hostname -i Display the IP address of the host

hostname -s Display the short hostname

#———————————{ service }———————————#

service Display status of system services.
By this you could start and stop the service
e.g
service named restart
To start the DNS service

service –status-all Display status of all the system services.

#——————————————————————————#

Text was written by vi editor
feel free to pass it on to anyone

References:
manual pages for all commands

Outro:
Ok, I’m signing off for this column.
Hope you enjoyed reading the first article in the linux system
administration series. This was quite lame and was strictly meant for
newbies only.

VirtualLino
Any feedbacks
I’m at virtuallino@linuxmail.org(any suggestions are welcome)

#———————————–< EOF >————————————#

 Posted on : August 22, 2014
Tags:

You might also likeclose