LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-31-2010, 10:52 PM   #16
koshihaku
Member
 
Registered: Aug 2010
Posts: 50

Original Poster
Rep: Reputation: 0

Quote:
Originally Posted by konsolebox View Post
try this then
Code:
#!/bin/sh
#G.sh 20100813

USAGE="Usage: $0 processName"

if [ "$#" -ne 1 ]; then
  echo "$USAGE"
  exit 1
fi

# In case the monitored process has not yet started
# keep searching until its PID is found
PROCESS_PID=""
while :
do
  PROCESS_PID=`/bin/pidof "$1"`

  if [ "$PROCESS_PID.X" != ".X" ]; then
    break
  fi
done

LOG_FILE="memusage.csv"

echo "ElapsedTime,VmSize,VmRSS" > "$LOG_FILE"

ELAPSED_TIME=`date +%H:%M:%S:%N`
PERIOD=2        # seconds

while :
do
  TOTAL_VM_SIZE=0
  TOTAL_VM_RSS=0

  for PID in $PROCESS_PID; do
    if [ -d "/proc/$PID" ] ; then
      VM_SIZE=`awk '/VmSize/ {print $2}' < "/proc/$PID/status"`
      if [ "$VM_SIZE.X" = ".X" ]; then
        continue
      fi
      VM_RSS=`awk '/VmRSS/ {print $2}' < "/proc/$PID/status"`
      if [ "$VM_RSS.X" = ".X" ]; then
        continue
      fi
      let TOTAL_VM_SIZE+=VM_SIZE
      let TOTAL_VM_RSS+=VM_RSS
    else
      echo "$1 ($PID) is no longer a running process"
      exit 0
    fi
  done

  echo "$ELAPSED_TIME,$TOTAL_VM_SIZE,$TOTAL_VM_RSS" >> "$LOG_FILE"
  sleep "$PERIOD"
  ELAPSED_TIME=`date +%H:%M:%S:%N`
done


I got a problem that the VMsize and VMrss is larger than the physical memory. It was said that there are some libraries used by many processes simultaneously, so I am accumulating the shared component over and over because of there are more than one processes for apache.

So the data I got by this script is not exactly correct. do you have any idea about this?
 
Old 09-02-2010, 10:07 AM   #17
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Maybe you should just also try to solve the problem with C. You can either create a stand-alone program or maybe let it print the output to be used by a script, etc. Maybe something that interacts with the kernel or with some library. Sorry I really have not much idea.
 
Old 09-02-2010, 08:51 PM   #18
koshihaku
Member
 
Registered: Aug 2010
Posts: 50

Original Poster
Rep: Reputation: 0
Question

Quote:
Originally Posted by konsolebox View Post
Perhaps VMsize is not really the total amount of memory allocated but only what virtually appears to the process? Sorry I also don't know much about it.

I found this pages while trying to figure it out. Just in case you find something about it.

http://linuxdevcenter.com/pub/a/linu...of-memory.html
http://www.mail-archive.com/c-prog@y.../msg05009.html
http://www.linuxforums.org/forum/lin...id-status.html
It was said that there are some double counted part because there are some libraries used simultaneously by many processes. Maybe it is the problem.

And altough I set up the script "sleep=2", but sometimes it takes longer than tens of minutes to get another data. Is that becaused the system is saturated?
 
Old 09-03-2010, 12:11 AM   #19
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by koshihaku View Post
And altough I set up the script "sleep=2", but sometimes it takes longer than tens of minutes to get another data. Is that becaused the system is saturated?
Do you mean the time the data gets updated, or the time the script takes another loop?.. For the former I think it depends on how the kernel was configured for the time it should update the data in /proc.
 
Old 09-03-2010, 12:24 AM   #20
koshihaku
Member
 
Registered: Aug 2010
Posts: 50

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by konsolebox View Post
Do you mean the time the data gets updated, or the time the script takes another loop?.. For the former I think it depends on how the kernel was configured for the time it should update the data in /proc.
I meant my monitoring script sleep 2 seconds before taking another loop.

And sometimes the data is /proc/pid/status was updated fast, because some data got by the script are only in several seconds.

for example:
ElapsedTime VmSize VmRSS
14:08:14:487053684 31643556 3456272
14:08:28:750838950 31643556 3456272
14:08:44:595622851 31643556 3456272
14:09:00:068480514 31643556 3456272
14:09:15:089910302 31643556 3456272
14:09:31:990478795 31643556 3456272
14:09:48:008821734 31643556 3456272
14:10:02:410624899 31643556 3456272


This is the data I got this afternoon. The results were all like this , in the beginning, the period between two records are small, but it got larger when the stress of the system became very high.

Last edited by koshihaku; 09-03-2010 at 12:28 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
[SOLVED] Problem running .sh script with "screen" and "java" IJustinI Linux - Newbie 31 06-01-2010 07:13 AM
cant "source" bash script with arguments (PATH updating) monkey_king Linux - General 5 12-30-2008 04:34 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 01:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration