如何做系统进程的快照,snapshot howtos
日常管理中我们会经常处理一些系统性能上的问题,这个过程通常是一个比较麻烦的过程,需要查看系统当时运行了哪些进程,因此,对于系统中运行的进程的跟踪是一个非常有必要的工作,这个可以帮助我们了解系统出现性能问题的当时,有哪些进行在运行,运行的情况如何?如CPU使用率,MEM使用率等.
下面用系统常用的命令来实现这个功能,如下:
[root@MQHOST sa]# ps -eo suser,ruser,lstart,time,pcpu,pmem,comm --sort pcpu,pmem
SUSER RUSER STARTED TIME %CPU %MEM COMMAND
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 migration/0
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 ksoftirqd/0
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 watchdog/0
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 migration/1
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 ksoftirqd/1
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 watchdog/1
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 events/0
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 events/1
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 khelper
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 kthread
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 kacpid
root root Wed Aug 24 17:09:32 2011 00:00:00 0.0 0.0 cqueue/0
root root Wed Aug 24 17:09:32 2011 00:00:00 0.0 0.0 cqueue/1
root root Wed Aug 24 17:09:32 2011 00:00:00 0.0 0.0 khubd
root root Wed Aug 24 17:09:32 2011 00:00:00 0.0 0.0 kseriod
root root Wed Aug 24 17:09:32 2011 00:00:00 0.0 0.0 aio/0
root root Wed Aug 24 17:09:32 2011 00:00:00 0.0 0.0 aio/1
root root Wed Aug 24 17:09:33 2011 00:00:00 0.0 0.0 kpsmoused
root root Wed Aug 24 17:09:34 2011 00:00:00 0.0 0.0 ata/0
root root Wed Aug 24 17:09:34 2011 00:00:00 0.0 0.0 ata/1
root root Wed Aug 24 17:09:34 2011 00:00:00 0.0 0.0 ata_aux
root root Wed Aug 24 17:09:35 2011 00:00:00 0.0 0.0 scsi_eh_0
root root Wed Aug 24 17:09:35 2011 00:00:00 0.0 0.0 scsi_eh_1
root root Wed Aug 24 17:09:35 2011 00:00:00 0.0 0.0 scsi_eh_2
root root Wed Aug 24 17:09:35 2011 00:00:00 0.0 0.0 scsi_eh_3
root root Wed Aug 24 17:09:35 2011 00:00:00 0.0 0.0 scsi_eh_4
root root Wed Aug 24 17:09:35 2011 00:00:00 0.0 0.0 scsi_eh_5
root root Wed Aug 24 17:09:37 2011 00:00:00 0.0 0.0 kstriped
root root Wed Aug 24 17:09:37 2011 00:00:00 0.0 0.0 ksnapd
root root Wed Aug 24 17:10:01 2011 00:00:00 0.0 0.0 hd-audio0
root root Thu Aug 25 10:15:09 2011 00:00:00 0.0 0.0 cupsd
root root Wed Aug 24 17:10:16 2011 00:00:00 0.0 0.0 kmpathd/0
root root Wed Aug 24 17:10:16 2011 00:00:00 0.0 0.0 kmpathd/1
root root Wed Aug 24 17:10:16 2011 00:00:00 0.0 0.0 kmpath_handlerd
root root Wed Aug 24 17:10:18 2011 00:00:00 0.0 0.0 kjournald
root root Wed Aug 24 17:10:18 2011 00:00:00 0.0 0.0 kjournald
root root Wed Aug 24 17:10:24 2011 00:00:00 0.0 0.0 klogd
root root Wed Aug 24 17:10:24 2011 00:00:00 0.0 0.0 rpciod/0
root root Wed Aug 24 17:10:24 2011 00:00:00 0.0 0.0 rpciod/1
root root Wed Aug 24 17:10:24 2011 00:00:00 0.0 0.0 rpc.idmapd
root root Wed Aug 24 17:10:25 2011 00:00:00 0.0 0.0 acpid
root root Wed Aug 24 17:10:25 2011 00:00:00 0.0 0.0 hald-runner
68 68 Wed Aug 24 17:10:25 2011 00:00:00 0.0 0.0 hald-addon-acpi
root root Wed Aug 24 17:10:30 2011 00:00:00 0.0 0.0 hidd
root root Wed Aug 24 17:10:31 2011 00:00:00 0.0 0.0 sshd
root root Wed Aug 24 17:10:31 2011 00:00:00 0.0 0.0 atd
root root Thu Aug 25 10:15:29 2011 00:00:00 0.0 0.0 vmware-usbarbit
avahi avahi Wed Aug 24 17:10:32 2011 00:00:00 0.0 0.0 avahi-daemon
root root Wed Aug 24 17:10:33 2011 00:00:00 0.0 0.0 smartd
root root Wed Aug 24 17:10:33 2011 00:00:00 0.0 0.0 mingetty
root root Wed Aug 24 17:10:33 2011 00:00:00 0.0 0.0 mingetty
root root Wed Aug 24 17:10:33 2011 00:00:00 0.0 0.0 mingetty
root root Wed Aug 24 17:10:33 2011 00:00:00 0.0 0.0 mingetty
root root Wed Aug 24 17:10:33 2011 00:00:00 0.0 0.0 mingetty
root root Thu Aug 25 10:15:29 2011 00:00:00 0.0 0.0 vmnet-bridge
root root Thu Aug 25 10:15:30 2011 00:00:00 0.0 0.0 vmnet-dhcpd
root root Thu Aug 25 10:15:30 2011 00:00:00 0.0 0.0 vmnet-netifup
root root Wed Aug 24 17:10:33 2011 00:00:00 0.0 0.0 mingetty
root root Wed Aug 24 17:10:33 2011 00:00:00 0.0 0.1 gdm-binary
root root Thu Aug 25 10:15:30 2011 00:00:00 0.0 0.0 vmnet-dhcpd
root root Thu Aug 25 10:15:30 2011 00:00:00 0.0 0.0 vmnet-natd
root root Thu Aug 25 10:15:30 2011 00:00:00 0.0 0.0 vmnet-netifup
root root Wed Aug 24 17:10:36 2011 00:00:00 0.0 0.1 gdm-binary
root root Wed Aug 24 17:10:51 2011 00:00:00 0.0 0.1 nm-system-setti
root root Tue Sep 27 11:19:41 2011 00:00:00 0.0 0.0 ps
root root Fri Aug 26 09:32:34 2011 00:00:00 0.0 0.0 rotatelogs
root root Wed Aug 24 17:09:29 2011 00:00:00 0.0 0.0 kblockd/0
root root Wed Aug 24 17:10:00 2011 00:00:00 0.0 0.0 udevd
root root Wed Aug 24 17:10:20 2011 00:00:00 0.0 0.0 kondemand/1
root root Fri Aug 26 09:32:34 2011 00:00:00 0.0 0.1 httpd
dbus dbus Wed Aug 24 17:10:25 2011 00:00:00 0.0 0.0 dbus-daemon
apache apache Fri Aug 26 09:32:34 2011 00:00:00 0.0 0.1 httpd
apache apache Fri Aug 26 09:32:34 2011 00:00:00 0.0 0.1 httpd
root root Wed Aug 24 17:09:59 2011 00:00:00 0.0 0.0 kauditd
apache apache Wed Sep 21 09:53:43 2011 00:00:00 0.0 0.1 httpd
apache apache Fri Aug 26 09:32:34 2011 00:00:00 0.0 0.1 httpd
root root Wed Aug 24 17:10:36 2011 00:00:00 0.0 0.1 gdm-rh-security
apache apache Thu Sep 15 10:40:32 2011 00:00:00 0.0 0.1 httpd
apache apache Sat Sep 24 16:04:49 2011 00:00:00 0.0 0.1 httpd
avahi avahi Wed Aug 24 17:10:32 2011 00:00:00 0.0 0.0 avahi-daemon
gdm gdm Wed Aug 24 17:13:19 2011 00:00:00 0.0 1.2 gdmgreeter
apache apache Thu Sep 15 14:46:41 2011 00:00:00 0.0 0.1 httpd
apache apache Mon Sep 19 09:47:23 2011 00:00:00 0.0 0.1 httpd
apache apache Thu Sep 15 10:40:42 2011 00:00:00 0.0 0.1 httpd
apache apache Thu Sep 15 14:46:41 2011 00:00:00 0.0 0.1 httpd
root root Wed Aug 24 17:10:20 2011 00:00:01 0.0 0.0 kondemand/0
68 68 Wed Aug 24 17:10:25 2011 00:00:01 0.0 0.1 hald
root root Wed Aug 24 17:10:31 2011 00:00:01 0.0 0.0 crond
root root Wed Aug 24 17:09:29 2011 00:00:02 0.0 0.0 kblockd/1
root root Wed Aug 24 17:10:23 2011 00:00:02 0.0 0.0 syslogd
root root Wed Aug 24 17:13:10 2011 00:00:02 0.0 0.2 Xorg
root root Wed Aug 24 17:10:22 2011 00:00:02 0.0 0.0 audispd
root root Wed Aug 24 17:09:29 2011 00:00:03 0.0 0.0 init
root root Wed Aug 24 17:09:57 2011 00:00:03 0.0 0.0 kjournald
root root Wed Aug 24 17:10:18 2011 00:00:03 0.0 0.0 kjournald
root root Tue Sep 27 09:43:54 2011 00:00:00 0.0 0.0 bash
root root Wed Aug 24 17:10:22 2011 00:00:05 0.0 0.0 auditd
root root Wed Aug 24 17:10:25 2011 00:00:08 0.0 0.0 pcscd
root root Fri Aug 26 09:31:47 2011 00:00:09 0.0 0.0 pdflush
root root Wed Aug 24 17:09:32 2011 00:00:10 0.0 0.0 kswapd0
root root Tue Sep 27 10:22:28 2011 00:00:00 0.0 0.0 bash
root root Tue Sep 27 10:04:44 2011 00:00:00 0.0 0.0 bash
root root Tue Sep 27 09:43:47 2011 00:00:00 0.0 0.1 sshd
root root Wed Aug 24 17:10:18 2011 00:00:28 0.0 0.0 kjournald
root root Mon Sep 26 16:42:39 2011 00:00:03 0.0 0.0 pdflush
root root Tue Sep 27 09:43:03 2011 00:00:00 0.0 0.0 bash
root root Tue Sep 27 09:43:03 2011 00:00:00 0.0 0.1 sshd
root root Thu Aug 25 09:24:32 2011 00:20:05 0.0 0.0 kjournald
root root Tue Sep 27 10:22:42 2011 00:00:03 0.1 1.1 vmware-tray
root root Tue Sep 27 10:22:24 2011 00:00:09 0.2 0.1 sshd
root root Tue Sep 27 10:24:14 2011 00:05:50 10.5 18.8 vmware-vmx
做成定时任务自动运行:
mkdir -m 755 -p /root/bin/
vi /root/bin/proc_snapshot.sh
proc_snapshot.sh 的内容如下:
#!/bin/bash
DATAPATH=/data/perf/linux
DAYTAMP=`date %Y-%M-%D`
if [ ! -d ${DATAPATH} ] ; then
mkdir -m 755 -p ${DATAPATH}
else
cd ${DATAPATH}
fi
ps -eo suser,ruser,lstart,time,pcpu,pmem,comm --sort pcpu,pmem >>${DAYTAMP}
在系统中增加cron任务(每10分钟执行一次):
运行crontab -e
增加以下内容:
*/10 * * * * cd /root/bin; sh proc_snapshot.sh 1>/dev/null 2>&1
全文完
阅读(2297) | 评论(0) | 转发(0) |