четверг, 5 марта 2009 г.

К предыдущему посту. Какаой процесс потребляет память.


AIX
ps gv | head -n 1; ps gv | egrep -v "RSS" | sort +6b -7 -n -r | more
Для Solaris
ps -eo vsz,rss,pid,comm | sort -rn | head


Эта команда покажет список процессов и отсортирует по использованию процессом памяти, выглядеть будет примерно так:

bash-3.00$ ps gv | head -n 1; ps gv | egrep -v "RSS" | sort +6b -7 -n -r | more
PID TTY STAT TIME PGIN SIZE RSS LIM TSIZ TRS %CPU %MEM COMMAND
5305080 - A 556:51 2754 904308 949180 xx 88760 45084 4.2 2.0 oracleO
2088964 - A 570:29 3036 494860 539800 xx 88760 45084 4.2 1.0 oracleO
6923072 - A 33:40 1264 170708 215764 xx 88760 45084 0.4 0.0 oracleO
631014 - A 17:49 7 104384 149468 xx 88760 45084 2.2 0.0 oracleO
5931902 - A 443:58 9128 28072 71416 xx 88760 45084 0.4 0.0 ora_j00
5030156 - A 0:31 9635 99468 65644 xx 146 164 0.0 0.0 /usr/bi
5882388 - A 0:25 8 16244 61280 xx 88760 45084 0.0 0.0 oracleO
5546378 - A 0:13 20 15612 60536 xx 88760 45084 0.0 0.0 oracleO
5947762 - A 0:39 8 14660 59612 xx 88760 45084 0.0 0.0 oracleO
5464594 - A 0:14 27 14712 59476 xx 88760 45084 0.0 0.0 oracleO
5550740 - A 0:41 39 14564 59268 xx 88760 45084 0.0 0.0 oracleO
5759600 - A 4:15 16 14148 59220 xx 88760 45084 0.1 0.0 oracleO
4231932 - A 0:14 0 14072 59156 xx 88760 45084 0.0 0.0 oracleO
4920124 - A 0:40 1 14072 59152 xx 88760 45084 0.0 0.0 oracleO
6168866 - A 0:26 14 14140 59120 xx 88760 45084 0.0 0.0 oracleO
4616618 - A 4:39 13 14012 59072 xx 88760 45084 0.1 0.0 oracleO
5571014 - A 0:32 0 13944 59028 xx 88760 45084 0.0 0.0 oracleO
5730468 - A 0:10 48 14056 59016 xx 88760 45084 0.0 0.0 oracleO
5882736 - A 0:04 1 13896 58980 xx 88760 45084 0.0 0.0 oracleO
6894348 - A 0:12 0 13876 58960 xx 88760 45084 0.0 0.0 oracleO


Далее можно определить по PID остальную инфу по процессу
svmon -P | grep -p с предыдущего вывода


bash-3.00# svmon -P | grep -p 5305080
-------------------------------------------------------------------------------
Pid Command Inuse Pin Pgsp Virtual 64-bit Mthrd 16MB
5305080 oracle 3689463 65586 618301 3710639 Y N N


или определить его SID в oracle:

select module,sid, client_info
from v$session s, v$process p
where p.addr=s.paddr and p.spid=&pid;

За***лся я объяснять куда ушло столько памяти!

А вот блять куда:
Кроме SGA, памяти на операционку и других структур, Oracle потенциально может отъесть памяти - _pga_max_size * processes. _pga_max_size считается так:

select ksppinm "Name", ksppstvl/1024/1024 ||'M' "Value", ksppdesc "Desc"
from x$ksppi x, x$ksppcv y
where x.indx = y.indx and ksppinm ='_pga_max_size';

Статистика в линухе.

Вот наш инженер налабал скрипт для снятия статистики в линухе.

#!/bin/bash
# This script will output linux kernel stats in form suitable for oracle
# (c) 2009 YKonovalov@.croc.ru
# License: GPLv2 or later
#

theprocway()
{
###
## Some stats uses USER_HZ or Jiffies as a time units.
# We may need to know how many ms is Jiffie on owr platform
#
USER_HZ=$(getconf CLK_TCK)

###
## Date and Time
#
DATE=$(date +'%m/%d/%Y %H:%M:%S.000')

###
## Get CPU stats
#
STATS=$(cat /proc/stat)
CPU=$(echo "$STATS"|head -1|awk '{total=($2+$3+$4+$5+$6+$7+$8+$9);print ($2+$3)*100/total}') #'
RUNQ=$(echo "$STATS"|grep procs_running|cut -d' ' -f 2)

###
## Get Disk IO stats.
# Firstly we find out what are our disk devices. In some setups
# we need to tune disk filter below to prevent counting single
# pathed devices along with theire multipathes devs.
# Next is the example for dm-multipath:
# DISKFILTER="dm-"
# We count all block devices by default
DISKFILTER=".*"
DISKS=$(echo $(grep -v '[[:digit:]]$' /proc/partitions|grep $DISKFILTER|sed -e "1,2 d"|awk '{print $4}')|sed -e "s/ /\\\|/")
DISKSTATS=$(grep " \($DISKS\) " /proc/diskstats) #"
IOCOUNT=$(echo "$DISKSTATS"| awk '{x=x+$12} END {print x}')

echo \"$DATE\",\"$RUNQ\",\"$IOCOUNT\",\"$CPU\"

}

vmstatway()
{
# Vmstat is the simple way of mesuaring disk IO.
# Here we get the sum of block reads and block writes for
# three seconds. This will delay our script for 3 sec.
VMSTAT=$(vmstat 3 2 | tail -1)
#IO=$(echo $VMSTAT | awk '{print $9+$10}')
VMSTAT_RUNQ_IO_CPU=$(echo $VMSTAT | awk '{print $1, $9+$10, $13}'|sed -e "s/ /\",\"/g")

echo \"$DATE\",\"$VMSTAT_RUNQ_IO_CPU\"
}

###
## Actually do the job by calling either procway or vmstatway
theprocway
#vmstatway

###
## Finally we output the data
#
#

#=========== Next if for your reference=====================
###
## /proc/stat format notes
# CPU usage consist of following categories
# 2 - user: normal processes executing in user mode
# 3 - nice: niced processes executing in user mode
# 4 - system: processes executing in kernel mode
# 5 - idle: twiddling thumbs
# 6 - iowait: waiting for I/O to complete
# 7 - irq: servicing interrupts
# 8 - softirq: servicing softirqs
# since for oracle all is need - simply "%CPU", we caclulate % user+niced

###
## /proc/diskstat format
# Each set of stats only applies to the indicated device; if you want
# system-wide stats you'll have to find all the devices and sum them all up.
#
# Field 4 -- # of reads completed
# This is the total number of reads completed successfully.
# Field 5 -- # of reads merged, field 6 -- # of writes merged
# Reads and writes which are adjacent to each other may be merged for
# efficiency. Thus two 4K reads may become one 8K read before it is
# ultimately handed to the disk, and so it will be counted (and queued)
# as only one I/O. This field lets you know how often this was done.
# Field 6 -- # of sectors read
# This is the total number of sectors read successfully.
# Field 7 -- # of milliseconds spent reading
# This is the total number of milliseconds spent by all reads (as
# measured from __make_request() to end_that_request_last()).
# Field 8 -- # of writes completed
# This is the total number of writes completed successfully.
# Field 9 -- # of sectors written
# This is the total number of sectors written successfully.
# Field 10 -- # of milliseconds spent writing
# This is the total number of milliseconds spent by all writes (as
# measured from __make_request() to end_that_request_last()).
# Field 11 -- # of I/Os currently in progress
# The only field that should go to zero. Incremented as requests are
# given to appropriate struct request_queue and decremented as they finish.
# Field 12 -- # of milliseconds spent doing I/Os
# This field is increases so long as field 9 is nonzero.
# Field 13 -- weighted # of milliseconds spent doing I/Os
# This field is incremented at each I/O start, I/O completion, I/O
# merge, or read of these stats by the number of I/Os in progress
# (field 9) times the number of milliseconds spent doing I/O since the
# last update of this field. This can provide an easy measure of both
# I/O completion time and the backlog that may be accumulating.