从http://nmon.sourceforge.net/pmwiki.php?n=Site.Download
下载对应版本nmon
将下载文件重命名为nmon
复制到Linux的/usr/bin,
chmod +x /usr/bin/nmon
接下来就可以使用nmon了
或者随便放自己喜欢放置的地方,记得设置环境变量也一样
配置一个收集进程ID的sh
while [ 1=1 ]
do
ps -ef ;sleep 300 >> /pslog/pslog_$(date +%Y%m%d%H).log
done
另外可以配置crontab
*/5 * * * * /pslog/pslog.sh 2 >/dev/null
[root@RHEL6 /root]$cat /pslog/pslog.sh
echo $(date +%Y"-"%m"-"%d" "%H":"%M":"%S) >> /pslog/pslog_$(date +%Y%m%d%H%M).log
ps -ef >> /pslog/pslog_$(date +%Y%m%d%H%M).log
echo "" >> /pslog/pslog_$(date +%Y%m%d%H%M).log
find /pslog -name *.log -mtime +30|xargs rm -rf
[root@localhost tmp]# nmon
│ ------------------------------
For help type H or ... │
│ # # # # #### # # nmon -? - hint │
│ ## # ## ## # # ## # nmon -h - full │
│ # # # # ## # # # # # # │
│ # # # # # # # # # #
To start the same way every time │
│ # ## # # # # # ## set the NMON ksh variable │
│ # # # # #### # # │
│ ------------------------------ │
│ │
│ Use these keys to toggle statistics on/off: │
│ c = CPU l = CPU Long-term - = Faster screen updates │
│ m = Memory j = Filesystems + = Slower screen updates │
│ d = Disks n = Network V = Virtual Memory │
│ r = Resource N = NFS v = Verbose hints │
│ k = kernel t = Top-processes . = only busy disks/procs │
│ h = more options q = Quit
nmon每30秒捕获一次数据快照
[root@localhost tmp]# nmon -f -s 30 -c 120
[root@localhost tmp]# ps -ef |grep nmon
root 3376 1 0 05:26 ? 00:00:01 gedit /tmp/nmon.txt
root 3466 1 0 05:44 pts/0 00:00:00 nmon -f -s 30 -c 120
root 3526 2784 0 05:44 pts/0 00:00:00 grep nmon
生成nmon文件
[root@localhost tmp]# ls -lrt *.nmon
-rw-r--r--. 1 root root 23970 Dec 22 05:45 localhost_121222_0544.nmon
将得到的nmon文件用nmon analyser v34a.xls 分析
结束nmon进程
[root@localhost tmp]# kill -9 3466
[root@localhost tmp]# ps -ef |grep nmon
root 3618 2784 0 05:55 pts/0 00:00:00 grep nmon
nmon -f -m /nmon/log -s 60 -c 2400
在/nmon/log 目录下生成格式为hostname_yymmdd_hhmi.nmon的文件,命令间隔为60秒钟,重复运行1440次(即1天)
日报:24*3600/60=1440
周报:24*3600*7/600=1008
[root@localhost weekly]# crontab -l
0 21 * * * /nmon/nmon.sh
0 21 * * 0 /nmon/weekly.sh
[root@localhost weekly]# cat /nmon/nmon.sh
/usr/bin/nmon -s 60 -c 1440 -t -F /nmon/log/`hostname`_`date "+%Y%m%d"`.nmon > /dev/null
find /nmon/log -name "*.nmon" -mtime +30 -exec -exec rm {} \;
[root@localhost weekly]# cat /nmon/weekly.sh
/usr/bin/nmon -s 600 -c 1008 -t -F /nmon/log/weekly/`hostname`_`date "+%Y%m%d"`.nmon > /dev/null
find /nmon/log/weekly -name "*.nmon" -mtime +120 -exec -exec rm {} \;
守护进程
[root@localhost ~]# ps -ef |grep nmon |grep -v grep
root 2811 1 0 04:35 ? 00:00:00 /usr/bin/nmon -s 60 -c 1440 -t -F /nmon/log/localhost.localdomain_20121225.nmon
root 2911 1 0 04:36 ? 00:00:00 /usr/bin/nmon -s 600 -c 1008 -t -F /nmon/log/weekly/localhost.localdomain_20121225.nmon
生成log
[root@localhost log]# ls -lrt
total 220
drwxr-xr-x. 2 root root 4096 Dec 25 07:47 weekly
-rw-r--r--. 1 root root 214892 Mar 12 09:00 localhost.localdomain_20121225.nmon
下载Excel分析工具,分析log即可
附nmon帮助
[root@localhost tmp]# nmon -h
Hint: nmon [-h] [-s <seconds>] [-c <count>] [-f -d <disks> -t -r <name>] [-x]
-h FULL help information
Interactive-Mode:
read startup banner and type: "h" once it is running
For Data-Collect-Mode (-f)
-f spreadsheet output format [note: default -s300 -c288]
optional
-s <seconds> between refreshing the screen [default 2]
-c <number> of refreshes [default millions]
-d <disks> to increase the number of disks [default 256]
-t spreadsheet includes top processes
-x capacity planning (15 min for 1 day = -fdt -s 900 -c 96)
Version - nmon 14g
For Interactive-Mode
-s <seconds> time between refreshing the screen [default 2]
-c <number> of refreshes [default millions]
-g <filename> User Defined Disk Groups [hit g to show them]
- file = on each line: group_name <disks list> space separated
- like: database sdb sdc sdd sde
- upto 64 disk groups, 512 disks per line
- disks can appear more than once and in many groups
-b black and white [default is colour]
example: nmon -s 1 -c 100
For Data-Collect-Mode = spreadsheet format (comma separated values)
Note: use only one of f,F,z,x or X and make it the first argument
-f spreadsheet output format [note: default -s300 -c288]
output file is <hostname>_YYYYMMDD_HHMM.nmon
-F <filename> same as -f but user supplied filename
-r <runname> used in the spreadsheet file [default hostname]
-t include top processes in the output
-T as -t plus saves command line arguments in UARG section
-s <seconds> between snap shots
-c <number> of snapshots before nmon stops
-d <disks> to increase the number of disks [default 256]
-l <dpl> disks/line default 150 to avoid spreadsheet issues. EMC=64.
-g <filename> User Defined Disk Groups (see above) - see BBBG & DG lines
-N include NFS Network File System
-I <percent> Include process & disks busy threshold (default 0.1)
don't save or show proc/disk using less than this percent
-m <directory> nmon changes to this directory before saving to file
example: collect for 1 hour at 30 second intervals with top procs
nmon -f -t -r Test1 -s30 -c120
To load into a spreadsheet:
sort -A *nmon >stats.csv
transfer the stats.csv file to your PC
Start spreadsheet & then Open type=comma-separated-value ASCII file
The nmon analyser or consolidator does not need the file sorted.
Capacity planning mode - use cron to run each day
-x sensible spreadsheet output for CP = one day
every 15 mins for 1 day ( i.e. -ft -s 900 -c 96)
-X sensible spreadsheet output for CP = busy hour
every 30 secs for 1 hour ( i.e. -ft -s 30 -c 120)
Interactive Mode Commands
key --- Toggles to control what is displayed ---
h = Online help information
r = Machine type, machine name, cache details and OS version + LPAR
c = CPU by processor stats with bar graphs
l = long term CPU (over 75 snapshots) with bar graphs
m = Memory stats
L = Huge memory page stats
V = Virtual Memory and Swap stats
k = Kernel Internal stats
n = Network stats and errors
N = NFS Network File System
d = Disk I/O Graphs
D = Disk I/O Stats
o = Disk I/O Map (one character per disk showing how busy it is)
o = User Defined Disk Groups
j = File Systems
t = Top Process stats use 1,3,4,5 to select the data & order
u = Top Process full command details
v = Verbose mode - tries to make recommendations
b = black and white mode (or use -b option)
. = minimum mode i.e. only busy disks and processes
key --- Other Controls ---
+ = double the screen refresh time
- = halves the screen refresh time
q = quit (also x, e or control-C)
0 = reset peak counts to zero (peak = ">")
space = refresh screen now
Startup Control
If you find you always type the same toggles every time you start
then place them in the NMON shell variable. For example:
export NMON=cmdrvtan
Others:
a) To you want to stop nmon - kill -USR2 <nmon-pid>
b) Use -p and nmon outputs the background process pid
c) To limit the processes nmon lists (online and to a file)
Either set NMONCMD0 to NMONCMD63 to the program names
or use -C cmd:cmd:cmd etc. example: -C ksh:vi:syncd
d) If you want to pipe nmon output to other commands use a FIFO:
mkfifo /tmp/mypipe
nmon -F /tmp/mypipe &
grep /tmp/mypipe
e) If nmon fails please report it with:
1) nmon version like: 14g
2) the output of cat /proc/cpuinfo
3) some clue of what you were doing
4) I may ask you to run the debug version
Developer Nigel Griffiths
Feedback welcome - on the current release only and state exactly the problem
No warranty given or implied.