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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>System Resources</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Linux System Administrators Guide"
HREF="index.html"><LINK
REL="UP"
TITLE="System Monitoring"
HREF="system-monitoring.html"><LINK
REL="PREVIOUS"
TITLE="System Monitoring"
HREF="system-monitoring.html"><LINK
REL="NEXT"
TITLE="Filesystem Usage"
HREF="fs-usage.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Linux System Administrators Guide: </TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="system-monitoring.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 7. System Monitoring</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="fs-usage.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="SYSTEM-RESOURCES"
></A
>7.1. System Resources</H1
><P
>Being able to monitor the performance of your system
is essential. If system resources become to low it can cause a lot of
problems. System resources can be taken up by individual users, or by
services your system may host such as email or web pages. The ability to
know what is happening can help determine whether system upgrades are needed,
or if some services need to be moved to another machine.</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="TOP"
></A
>7.1.1. The <B
CLASS="COMMAND"
>top</B
> command.</H2
><P
>The most common of these commands is <B
CLASS="COMMAND"
>top</B
>.
The <B
CLASS="COMMAND"
>top</B
> will display a continually updating report
of system resource usage.
<TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
><TT
CLASS="PROMPT"
>#</TT
> <TT
CLASS="USERINPUT"
><B
>top</B
></TT
>
<TT
CLASS="COMPUTEROUTPUT"
> 12:10:49 up 1 day, 3:47, 7 users, load average: 0.23, 0.19, 0.10
125 processes: 105 sleeping, 2 running, 18 zombie, 0 stopped
CPU states: 5.1% user 1.1% system 0.0% nice 0.0% iowait 93.6% idle
Mem: 512716k av, 506176k used, 6540k free, 0k shrd, 21888k buff
Swap: 1044216k av, 161672k used, 882544k free 199388k cached
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND
2330 root 15 0 161M 70M 2132 S 4.9 14.0 1000m 0 X
2605 weeksa 15 0 8240 6340 3804 S 0.3 1.2 1:12 0 kdeinit
3413 weeksa 15 0 6668 5324 3216 R 0.3 1.0 0:20 0 kdeinit
18734 root 15 0 1192 1192 868 R 0.3 0.2 0:00 0 top
1619 root 15 0 776 608 504 S 0.1 0.1 0:53 0 dhclient
1 root 15 0 480 448 424 S 0.0 0.0 0:03 0 init
2 root 15 0 0 0 0 SW 0.0 0.0 0:00 0 keventd
3 root 15 0 0 0 0 SW 0.0 0.0 0:00 0 kapmd
4 root 35 19 0 0 0 SWN 0.0 0.0 0:00 0 ksoftirqd_CPU0
9 root 25 0 0 0 0 SW 0.0 0.0 0:00 0 bdflush
5 root 15 0 0 0 0 SW 0.0 0.0 0:00 0 kswapd
10 root 15 0 0 0 0 SW 0.0 0.0 0:00 0 kupdated
11 root 25 0 0 0 0 SW 0.0 0.0 0:00 0 mdrecoveryd
15 root 15 0 0 0 0 SW 0.0 0.0 0:01 0 kjournald
81 root 25 0 0 0 0 SW 0.0 0.0 0:00 0 khubd
1188 root 15 0 0 0 0 SW 0.0 0.0 0:00 0 kjournald
1675 root 15 0 604 572 520 S 0.0 0.1 0:00 0 syslogd
1679 root 15 0 428 376 372 S 0.0 0.0 0:00 0 klogd
1707 rpc 15 0 516 440 436 S 0.0 0.0 0:00 0 portmap
1776 root 25 0 476 428 424 S 0.0 0.0 0:00 0 apmd
1813 root 25 0 752 528 524 S 0.0 0.1 0:00 0 sshd
1828 root 25 0 704 548 544 S 0.0 0.1 0:00 0 xinetd
1847 ntp 15 0 2396 2396 2160 S 0.0 0.4 0:00 0 ntpd
1930 root 24 0 76 4 0 S 0.0 0.0 0:00 0 rpc.rquotad</TT
></PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>The top portion of the report lists information such as
the system time, uptime, CPU usage, physical ans swap memory usage,
and number of processes. Below that is a list of the processes sorted
by CPU utilization.</P
><P
>You can modify the output of <B
CLASS="COMMAND"
>top</B
> while
is is running. If you hit an <TT
CLASS="OPTION"
>i</TT
>, top will no longer
display idle processes. Hit <TT
CLASS="OPTION"
>i</TT
> again to see them
again. Hitting <TT
CLASS="OPTION"
>M</TT
> will sort by memory usage,
<TT
CLASS="OPTION"
>S</TT
> will sort by how long they processes have been
running, and <TT
CLASS="OPTION"
>P</TT
> will sort by CPU usage again.</P
><P
>In addition to viewing options, you can also modify processes
from within the <B
CLASS="COMMAND"
>top</B
> command. You can use
<TT
CLASS="OPTION"
>u</TT
> to view processes owned by a specific user,
<TT
CLASS="OPTION"
>k</TT
> to kill processes, and <TT
CLASS="OPTION"
>r</TT
> to
renice them.</P
><P
>For more in-depth information about processes you can look in
the <TT
CLASS="FILENAME"
>/proc</TT
> filesystem. In the <TT
CLASS="FILENAME"
>/proc</TT
>
filesystem you will find a series of sub-directories with numeric names.
These directories are associated with the processes ids of currently
running processes. In each directory you will find a series of files
containing information about the process.</P
><P
>YOU MUST TAKE EXTREME CAUTION TO NOT MODIFY THESE FILES, DOING
SO MAY CAUSE SYSTEM PROBLEMS!</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="IOSTAT"
></A
>7.1.2. The <B
CLASS="COMMAND"
>iostat</B
> command.</H2
><P
>The <B
CLASS="COMMAND"
>iostat</B
> will display the current CPU load
average and disk I/O information. This is a great command to monitor
your disk I/O usage.
<TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
><TT
CLASS="PROMPT"
>#</TT
> <TT
CLASS="USERINPUT"
><B
>iostat</B
></TT
>
<TT
CLASS="COMPUTEROUTPUT"
>Linux 2.4.20-24.9 (myhost) 12/23/2003
avg-cpu: %user %nice %sys %idle
62.09 0.32 2.97 34.62
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dev3-0 2.22 15.20 47.16 1546846 4799520</TT
></PRE
></FONT
></TD
></TR
></TABLE
>
For 2.4 kernels the devices is names using the device's major
and minor number. In this case the device listed is <TT
CLASS="FILENAME"
> /dev/hda</TT
>. To have <B
CLASS="COMMAND"
>iostat</B
> print this
out for you, use the <TT
CLASS="OPTION"
>-x</TT
>.
<TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
><TT
CLASS="PROMPT"
>#</TT
> <TT
CLASS="USERINPUT"
><B
>iostat -x</B
></TT
>
<TT
CLASS="COMPUTEROUTPUT"
>Linux 2.4.20-24.9 (myhost) 12/23/2003
avg-cpu: %user %nice %sys %idle
62.01 0.32 2.97 34.71
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s rkB/s wkB/s avgrq-sz avgqu-sz await svctm %util
/dev/hdc 0.00 0.00 .00 0.00 0.00 0.00 0.00 0.00 0.00 2.35 0.00 0.00 14.71
/dev/hda 1.13 4.50 .81 1.39 15.18 47.14 7.59 23.57 28.24 1.99 63.76 70.48 15.56
/dev/hda1 1.08 3.98 .73 1.27 14.49 42.05 7.25 21.02 28.22 0.44 21.82 4.97 1.00
/dev/hda2 0.00 0.51 .07 0.12 0.55 5.07 0.27 2.54 30.35 0.97 52.67 61.73 2.99
/dev/hda3 0.05 0.01 .02 0.00 0.14 0.02 0.07 0.01 8.51 0.00 12.55 2.95 0.01</TT
></PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>The <B
CLASS="COMMAND"
>iostat</B
> man page contains a detailed
explanation of what each of these columns mean.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="PS"
></A
>7.1.3. The <B
CLASS="COMMAND"
>ps</B
> command</H2
><P
>The <B
CLASS="COMMAND"
>ps</B
> will provide you a list of
processes currently running. There is a wide variety of options
that this command gives you.</P
><P
>A common use would be to list all processes currently running.
To do this you would use the <B
CLASS="COMMAND"
>ps -ef</B
> command.
(Screen output from this command is too large to include, the following
is only a partial output.)
<TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Dec22 ? 00:00:03 init
root 2 1 0 Dec22 ? 00:00:00 [keventd]
root 3 1 0 Dec22 ? 00:00:00 [kapmd]
root 4 1 0 Dec22 ? 00:00:00 [ksoftirqd_CPU0]
root 9 1 0 Dec22 ? 00:00:00 [bdflush]
root 5 1 0 Dec22 ? 00:00:00 [kswapd]
root 6 1 0 Dec22 ? 00:00:00 [kscand/DMA]
root 7 1 0 Dec22 ? 00:01:28 [kscand/Normal]
root 8 1 0 Dec22 ? 00:00:00 [kscand/HighMem]
root 10 1 0 Dec22 ? 00:00:00 [kupdated]
root 11 1 0 Dec22 ? 00:00:00 [mdrecoveryd]
root 15 1 0 Dec22 ? 00:00:01 [kjournald]
root 81 1 0 Dec22 ? 00:00:00 [khubd]
root 1188 1 0 Dec22 ? 00:00:00 [kjournald]
root 1675 1 0 Dec22 ? 00:00:00 syslogd -m 0
root 1679 1 0 Dec22 ? 00:00:00 klogd -x
rpc 1707 1 0 Dec22 ? 00:00:00 portmap
root 1813 1 0 Dec22 ? 00:00:00 /usr/sbin/sshd
ntp 1847 1 0 Dec22 ? 00:00:00 ntpd -U ntp
root 1930 1 0 Dec22 ? 00:00:00 rpc.rquotad
root 1934 1 0 Dec22 ? 00:00:00 [nfsd]
root 1942 1 0 Dec22 ? 00:00:00 [lockd]
root 1943 1 0 Dec22 ? 00:00:00 [rpciod]
root 1949 1 0 Dec22 ? 00:00:00 rpc.mountd
root 1961 1 0 Dec22 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root 2057 1 0 Dec22 ? 00:00:00 /usr/bin/spamd -d -c -a
root 2066 1 0 Dec22 ? 00:00:00 gpm -t ps/2 -m /dev/psaux
bin 2076 1 0 Dec22 ? 00:00:00 /usr/sbin/cannaserver -syslog -u bin
root 2087 1 0 Dec22 ? 00:00:00 crond
daemon 2195 1 0 Dec22 ? 00:00:00 /usr/sbin/atd
root 2215 1 0 Dec22 ? 00:00:11 /usr/sbin/rcd
weeksa 3414 3413 0 Dec22 pts/1 00:00:00 /bin/bash
weeksa 4342 3413 0 Dec22 pts/2 00:00:00 /bin/bash
weeksa 19121 18668 0 12:58 pts/2 00:00:00 ps -ef</PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>The first column shows who owns the process. The second
column is the process ID. The Third column is the parent process
ID. This is the process that generated, or started, the process.
The forth column is the CPU usage (in
percent). The fifth column is the start time, of date if the process
has been running long enough. The sixth column is the tty associated
with the process, if applicable. The seventh column is the cumulitive
CPU usage (total amount of CPU time is has used while running). The
eighth column is the command itself.</P
><P
>With this information you can see exacly what is running on
your system and kill run-away processes, or those that are causing
problems.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="VMSTAT"
></A
>7.1.4. The <B
CLASS="COMMAND"
>vmstat</B
> command</H2
><P
>The <B
CLASS="COMMAND"
>vmstat</B
> command will provide a report
showing statistics for system processes, memory, swap,
I/O, and the CPU. These statistics are generated using data from the
last time the command was run to the present. In the case of the
command never being run, the data will be from the last reboot until
the present.</P
><P
> <TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
><TT
CLASS="PROMPT"
>#</TT
> <TT
CLASS="USERINPUT"
><B
>vmstat</B
></TT
>
<TT
CLASS="COMPUTEROUTPUT"
> 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 181604 17000 26296 201120 0 2 8 24 149 9 61 3 36</TT
></PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>The following was taken from the
<B
CLASS="COMMAND"
>vmstat</B
> man page.</P
><A
NAME="AEN3528"
></A
><BLOCKQUOTE
CLASS="BLOCKQUOTE"
><P
><P
CLASS="LITERALLAYOUT"
>FIELD DESCRIPTIONS<br>
Procs<br>
r: The number of processes waiting for run time.<br>
b: The number of processes in uninterruptable sleep.<br>
w: The number of processes swapped out but otherwise runnable. This<br>
field is calculated, but Linux never desperation swaps.<br>
<br>
Memory<br>
swpd: the amount of virtual memory used (kB).<br>
free: the amount of idle memory (kB).<br>
buff: the amount of memory used as buffers (kB).<br>
<br>
Swap<br>
si: Amount of memory swapped in from disk (kB/s).<br>
so: Amount of memory swapped to disk (kB/s).<br>
<br>
IO<br>
bi: Blocks sent to a block device (blocks/s).<br>
bo: Blocks received from a block device (blocks/s).<br>
<br>
System<br>
in: The number of interrupts per second, including the clock.<br>
cs: The number of context switches per second.<br>
<br>
CPU<br>
These are percentages of total CPU time.<br>
us: user time<br>
sy: system time<br>
id: idle time</P
></P
></BLOCKQUOTE
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LSOF"
></A
>7.1.5. The <B
CLASS="COMMAND"
>lsof</B
> command</H2
><P
>The <B
CLASS="COMMAND"
>lsof</B
> command will print out a list of
every file that is in use. Since Linux considers everythihng a file,
this list can be very long. However, this command
can be useful in diagnosing problems. An example of this is if you wish
to unmount a filesystem, but you are being told that it is in use. You
could use this command and <B
CLASS="COMMAND"
>grep</B
> for the name of the
filesystem to see who is using it.</P
><P
>Or suppose you want to see all files in use by a particular process.
To do this you would use <B
CLASS="COMMAND"
>lsof -p -processid-</B
>.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="MORE-UTILS"
></A
>7.1.6. Finding More Utilities</H2
><P
>To learn more about what command line tools are available, Chris
Karakas has wrote a reference guide titled <A
HREF="http://www.karakas-online.de/gnu-linux-tools-summary/"
TARGET="_top"
> GNU/Linux
Command-Line Tools Summary</A
>. It's a good resource for learning
what tools are out there and how to do a number of tasks.</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="system-monitoring.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="fs-usage.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>System Monitoring</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="system-monitoring.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Filesystem Usage</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
|