Using bash scripts for process performance monitoring

Source: Internet
Author: User

Monitor a Linux process with a bash script implementation.

Monitor the process using the PS command, and use the Loop plus sleep time for continuous monitoring.

Usage:

PSMONITOR.SH-P [PID]-D [Interval]-n [Statistics count]

Parameters:

-p Monitored process ID

-D read performance data interval

-N statistics, up to the number of times, automatic exit

#!/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 effect:

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


Using bash scripts for process performance monitoring

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.