免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2773 | 回复: 3
打印 上一主题 下一主题

请问 kstat是什么,与ksh有什么关系 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-02-27 15:01 |只看该作者 |倒序浏览
rt

论坛徽章:
0
2 [报告]
发表于 2003-02-28 02:15 |只看该作者

请问 kstat是什么,与ksh有什么关系

...

ft   

论坛徽章:
0
3 [报告]
发表于 2003-02-28 02:26 |只看该作者

请问 kstat是什么,与ksh有什么关系

...


Maintenance Commands                kstat(1M)

NAME
   kstat - display kernel statistics

SYNOPSIS
   kstat [ -lpq ]  [ -T  u | d   ]  [ -c class ]  [ -m module ]
   [  -i  instance ]  [ -n name ]  [ -s statistic ]  [ interval
   [ count ]  ]

   kstat [ -lpq  ]   [  -T   u  |  d    ]   [  -c  class  ]   [
   module:instance:name:statistic  ... ]  [ interval  [ count ]
   ]

DESCRIPTION
   The kstat utility examines the available kernel  statistics,
   or  kstats, on the system and reports those statistics which
   match the criteria specified  on  the  command  line.   Each
   matching statistic is printed with its module, instance, and
   name fields, as well as its actual value...

论坛徽章:
0
4 [报告]
发表于 2003-02-28 09:43 |只看该作者

请问 kstat是什么,与ksh有什么关系

那么我在ksh下,为什么不能执行它呢?
下面这个shell就用了kstat,不能执行。我确认过,已经安装了ksh。
#!/bin/ksh
# Korn Shell script
# Written by Jeff Turner of Context-Switch.com
# Dated: January, 2002
# Version: A.0
# Mail comments to: Jeff.Turner@context-switch.com

# BACKGROUND:
# Administrators may wish to determine just how busy their
# disks are and to also determine whether their systems are
# read-intensive or write-intensive
#
# This shell script uses the 'kstat' utility to determine
# the number of disk reads/writes per disk slice in a specified
# time interval (see FREQUENCY & REPEATS variables, below)
#
# Output is structured on a per-slice basis, with a report output
# line for each FREQUENCY-interval
#
# Most of the work is carried out by the shell in which this script
# is executing, with minimal use of external utilities. Hopefully, this
# makes the script more efficient (with regard to system resource demand)
# and reduces the impact on the running system.

# assign variables for use in the script
integer COUNT=1 SAMPLE=0 # used as a counter for loops
integer READS=0 WRITES=0 TOTREADS=0 TOTWRITES=0 # used to store date
integer DIFFREADS=0 DIFFWRITES=0 # used to store the calculated differences

typeset -L10 SLICENAME=""        # used to format output
typeset -R15 READS # used to format output
typeset -R15 WRITES # used to format output
SLICENAME=""
TMPFILE=/tmp/kstat.$$

# HINT: Do not set the FREQUENCY value to be a number less than 5
# as this could impact on system performance
integer FREQUENCY=5 REPEATS=13        # used with the kstat command
                # The first sample is used to obtain starting values
                # the remaining twelve samples provide...
                # 5 seconds x 12 repeats = 60 seconds sampling time

# assign kstat pathname to a variable
KSTAT="`which kstat`" export KSTAT

# determine that the kstat utility exists
if [ -f "$KSTAT" -a -x "$KSTAT" ]
then
        # The kstat utility exists and is executable by this user
        # We now need to produce details for SCSI (sd) and IDE (dad)
        # module reads and writes
        STARTTIME=$(date +"Started sampling at %T on %D"
        $KSTAT -m \*[sa]d -p $FREQUENCY  $REPEATS |
        sed -n -e 's/:/ /g'  -e 's/\,/_/' -e '/_[abd-h] [rw][er][ai][dt][se]/p' > $TMPFILE
        ENDTIME=$(date +"Sampling ended at %T on %D"

        # verify that there has been some output,
        # otherwise exit from the script
        if [ -z $TMPFILE ]
        then
                # file has zero contents
                echo "\nOutput file has zero contents. Aborting script now...\n"
                exit 1
        fi

        # now determine how many disk slices are reported on
        # obtain unique instances of each slice name
        SLICELIST=$( nawk '{ print $3 }' $TMPFILE | sort -u)

        # output the start time details
        echo "$STARTTIME"
        echo "Sample frequency is set to $FREQUENCY seconds"

        # now process the data
        for SLICENAME in $SLICELIST
        do
                grep $SLICENAME $TMPFILE | while read LINE
                do
                        set -- $LINE
                        if [[ $COUNT == 1 && $4 = "reads" ]]
                        then
                                READS=$5
                                integer DIFFREADS=0
                        elif [[ $COUNT == 1 && $4 = "writes" ]]
                        then
                                WRITES=$5
                                integer DIFFWRITES=0
                                (( COUNT = $COUNT + 1 ))

                                # produce report output
                                echo "\nSAMPLE        $SLICENAME            Reads               Writes"

                        elif  [[ $COUNT > 1 && $4 = "reads" ]]
                        then
                                integer NUMVAR=$5
                                (( DIFFREADS = $NUMVAR - $READS ))
                                if (( $DIFFREADS > 0 ))
                                then
                                        READS=$NUMVAR
                                fi
                                (( TOTREADS = $TOTREADS + $DIFFREADS ))

                        elif  [[ $COUNT > 1 && $4 = "writes" ]]
                        then
                                integer NUMVAR=$5
                                (( DIFFWRITES = $NUMVAR - $WRITES ))
                                if (( $DIFFWRITES > 0 ))
                                then
                                        WRITES=$NUMVAR
                                fi
                                (( TOTWRITES = $TOTWRITES + $DIFFWRITES ))
                                (( SAMPLE = $SAMPLE + 1 ))

                                # produce report output
                                typeset -L8 SAMPLE # used to format output
                                typeset -R15 DIFFREADS # used to format output
                                typeset -R15 DIFFWRITES # used to format output
                                echo "$SAMPLE                $DIFFREADS $DIFFWRITES"
                        fi
                done
                COUNT=1
                SAMPLE=0
        done
        echo "Total Reads:  $TOTREADS"
        echo "Total Writes: $TOTWRITES\n"

        # output the start time details
        echo "$ENDTIME"

else
        # either the kstat command dows not exist in the user's PATH list
        # or the user does not have permission to execute the kstat command

        echo "\aSorry."
        cat << EOF

        Either... 1. The 'kstat' utility can not be found in the \$PATH directories
            or... 2. You do not have permission to execute the 'kstat' command
        Terminating the program now.

EOF
        exit 2
fi
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP