作为服务器,了解他的实时运行情况是非常有必要的,而且要对其进行全面完整的监控,其中资源部分比如cpu,men,io,disk,network等,这些比较凌乱的东西,用linux提供的命令就可以了满足需要了,不必用那些庞大臃肿的企业级监控工具,比如Nagios,OpenNMS等。
还有比较重要的就是/proc文件系统了,里面的文件反应了几乎所有系统当前运行时的状态,是系统的实时快照,这时linux里一切都是文件这种理念的反映。如果你对于proc有及其强壮的了解,那么什么xx工具基本都可以忽略了。
- root@ubuntu:~# uptime
- 13:22:12 up 4:54, 3 users, load average: 0.93, 0.84, 0.81
其中13:22:12是当前的时间;up 4:54 是已经运行了多长时间;3 users 是当前有几个用户登录;load average :0.93 0.84 0.81 表示cpu在1min,5min,15min前的负载情况,值代表等待处理的process数,1在单核cpu机器上代表cpu总是处在运算状态。
- root@ubuntu:~# free
- total used free shared buffers cached
- Mem: 2025608 1942916 82692 0 451136 785420
- -/+ buffers/cache: 706360 1319248
- Swap: 261116 0 261116
- top - 13:50:53 up 5:22, 3 users, load average: 0.53, 0.67, 0.72
- Tasks: 179 total, 1 running, 177 sleeping, 0 stopped, 1 zombie
- Cpu(s): 7.9%us, 1.2%sy, 1.2%ni, 89.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
- Mem: 2025608k total, 1966004k used, 59604k free, 456644k buffers
- Swap: 261116k total, 0k used, 261116k free, 787140k cached
- PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
- 2096 fenix 20 0 280m 62m 20m S 14 3.2 55:30.27 chrome
- root@ubuntu:~# pmap -x 5215
- 5215: bash
- Address Kbytes RSS Dirty Mode Mapping
- 002da000 0 4 0 r-x-- [ anon ]
- 00323000 0 20 0 r-x-- libnsl-2.12.1.so
- 00336000 0 4 4 r---- libnsl-2.12.1.so
- 00337000 0 4 4 rw--- libnsl-2.12.1.so
- 00338000 0 0 0 rw--- [ anon ]
- 003b0000 0 8 0 r-x-- libdl-2.12.1.so
- root@ubuntu:~# mpstat
- Linux 2.6.35-22-generic (ubuntu) 04/27/2011 _i686_ (2 CPU)
- 02:26:47 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
- 02:26:47 PM all 11.76 0.27 1.74 0.23 0.00 0.20 0.00 0.00 85.79
- root@ubuntu:~# iostat
- Linux 2.6.35-22-generic (ubuntu) 04/27/2011 _i686_ (2 CPU)
- avg-cpu: %user %nice %system %iowait %steal %idle
- 11.77 0.27 1.94 0.23 0.00 85.78
- Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
- sda 3.39 199.43 55.77 4337613 1213008
- sdb 0.01 0.09 0.00 2035 82
- root@ubuntu:~# vmstat -a
- procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
- r b swpd free inact active si so bi bo in cs us sy id wa
- 0 0 0 84420 975336 892620 0 0 74 31 728 146 12 2 86 0
- Linux 2.6.35-22-generic (ubuntu) 04/27/2011 _i686_ (2 CPU)
- 12:25:01 PM CPU %user %nice %system %iowait %steal %idle
- 12:35:01 PM all 11.14 0.10 1.57 0.32 0.00 86.88
- 12:45:01 PM all 12.24 0.05 2.06 0.15 0.00 85.50
- 12:55:01 PM all 13.14 0.07 2.08 0.16 0.00 84.55
- 01:05:01 PM all 10.81 0.04 1.80 0.04 0.00 87.31
- 01:15:01 PM all 12.50 0.08 2.32 0.06 0.00 85.04
- root@ubuntu:~# strace -p 5482
- Process 5482 attached - interrupt to quit
- waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 5487
- --- SIGCHLD (Child exited) @ 0 (0) ---
- sigreturn() = ? (mask now [])
- waitpid(-1, 0xbfae781c, WNOHANG) = -1 ECHILD (No child processes)
- rt_sigaction(SIGINT, {0x805b950, [], 0}, NULL, 8) = 0
- rt_sigaction(SIGQUIT, {SIG_DFL, [], 0}, NULL, 8) = 0
- close(4) = 0
- chdir("/home/fenix") = 0
- ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
- root@ubuntu:~# ulimit -a
- core file size (blocks, -c) 0
- data seg size (kbytes, -d) unlimited
- scheduling priority (-e) 20
- file size (blocks, -f) unlimited
- pending signals (-i) 16382
- max locked memory (kbytes, -l) 64
- max memory size (kbytes, -m) unlimited
- open files (-n) 1024
- pipe size (512 bytes, -p) 8
- POSIX message queues (bytes, -q) 819200
- real-time priority (-r) 0
- stack size (kbytes, -s) 8192
- cpu time (seconds, -t) unlimited
- max user processes (-u) unlimited
- virtual memory (kbytes, -v) unlimited
- file locks (-x) unlimited