Use Bash scripts to monitor process performance and bash script Process Performance

Source: Internet
Author: User

Use Bash scripts to monitor process performance and bash script Process Performance

Monitors a Linux Process and uses Bash scripts.

Use the ps command to monitor the process, and use the cycle plus sleep time for continuous monitoring.

Usage:

Psmonitor. sh-p [pid]-d [interval]-n [statistics count]

Parameters:

-P monitoring process ID

-D read performance data interval

-N: The number of statistics. When this number is reached, the system automatically exits.

#!/bin/bashinterval=0count=0pid=""while getopts "p:d:n:" argdo        case $arg in        p)                pid=$OPTARG                echo "pid: $pid"                ;;        d)                interval=$OPTARG                echo "interval:$interval"                ;;        n)                count=$OPTARG                echo "count:$count"                ;;        \?)                echo "unkonw argument"                exit 1                ;;        esacdonei=0;while [ true ]; do        if [ $i -gt $count ]        then                exit 0;        else                let "i+=1"        fi         ps h -p $pid -o rss,vsz,%mem,%cpu        sleep $intervaldone

Monitoring results:

-bash-3.2$ ./psmonitor.sh -p 4181 -d 1 -n 10pid: 4181interval:1count:101511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.41511232 2537664 37.3 2.4


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.