How can I measure the actual memory usage of an application or process?

后端 未结 30 3169
心在旅途
心在旅途 2020-11-22 03:01

This question is covered here in great detail.

How do you measure the memory usage of an application or process in Linux?

From the blog articl

30条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 03:49

    Based on answer to a related question.

    You may use SNMP to get the memory and CPU usage of a process in a particular device on the network :)

    Requirements:

    • the device running the process should have snmp installed and running
    • snmp should be configured to accept requests from where you will run the script below (it may be configured in file snmpd.conf)
    • you should know the process ID (PID) of the process you want to monitor

    Notes:

    • HOST-RESOURCES-MIB::hrSWRunPerfCPU is the number of centi-seconds of the total system's CPU resources consumed by this process. Note that on a multi-processor system, this value may increment by more than one centi-second in one centi-second of real (wall clock) time.

    • HOST-RESOURCES-MIB::hrSWRunPerfMem is the total amount of real system memory allocated to this process.

    **

    Process monitoring script:

    **

    echo "IP: "
    read ip
    echo "specfiy pid: "
    read pid
    echo "interval in seconds:"
    read interval
    
    while [ 1 ]
    do
        date
        snmpget -v2c -c public $ip HOST-RESOURCES-MIB::hrSWRunPerfCPU.$pid
        snmpget -v2c -c public $ip HOST-RESOURCES-MIB::hrSWRunPerfMem.$pid
        sleep $interval;
    done
    

提交回复
热议问题