Results 1 to 3 of 3

Thread: Monitoring script

  1. #1
    Join Date
    Dec 2005
    Location
    South Wales, UK
    Beans
    Hidden!

    Monitoring script

    Hi guys

    I am trying to write a script to monitoring script that reports the rss, pcpu and comm.

    That isn't the hard part, the bit i am struggling with is;

    find duplicate comm's, merge them into one adding up the cpu% use and rss use.

    so far i have this:

    Code:
    #!/bin/bash
    
    DATE=$(date +%F)
    NAME="Test_$DATE.csv"
    PROCS=""
    
    ps -eo "rss,pcpu,comm" >> temp.txt
    
    PROCS='cat temp.txt | grep ^PROCS= | sed 's/PROCS=//''
    
            for i in $PROCS ; do
                            HEAD='echo -n $HEAD$i rss,$i pcpu,'
                    done
    
                    HEAD='echo -n $HEAD | sed "s/.$//"'
    
                    echo "rss,pcpu,comm" >> $NAME
    
            for j in $PROCS ; do
                    TMPPROCSTAT=`grep $j temp.txt | awk '{rss+=$1} ; {pcpu+=$2} ; END { print rss","pcpu }'`
                    # if [ "$TMPPROCSTAT" = "," ] ; then
                    #       TMPPROCSTAT="NA,NA"
                    # fi
                    PROCSTAT=`echo "$PROCSTAT$TMPPROCSTAT,"`
                    done
                    PROCSTAT=`echo -n $PROCSTAT | sed "s/.$//"`
                    echo $PROCSTAT >> $NAME
            rm temp.txt
    I am putting the values into a csv file, adding the rss, pcpu and comm as headings, then want the info displayed below.

    all i am getting as output at the moment is:

    Code:
    rss,pcpu,comm
    ,,,,,,,,,,,1234,0,,,,,
    that not exact values, just an example

    Any help, or a point in the right direction will be appreciated, or if anyone knows of a better way that what i am trying...
    <tronyx> "you should hire me to stare at your wireshark because i can spot a virus being downloaded in a compressed file over bit torrent at up to 600 kb/s"

  2. #2
    Join Date
    Sep 2009
    Location
    Freiburg/Germany
    Beans
    1,091
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Monitoring script

    Maybe something like this:
    Code:
    ps -eo "rss,pcpu,comm" --no-header | awk '{rss[$3]+=$1; pcpu[$3]+=$2} END {OFS=","; for (r in rss) print rss[r], pcpu[r], r}'
    ClassicMenu Indicator - classic GNOME menu for Unity
    Unsettings - configuration program for the Unity
    Privacy Indicator - easily switch privacy settings in Unity
    Arronax - create and modify app starters

  3. #3
    Join Date
    Dec 2005
    Location
    South Wales, UK
    Beans
    Hidden!

    Re: Monitoring script

    Got it all sorted, thanks a lot
    ended up using :

    Code:
    ps -eo "rss,pcpu,comm" | awk '{ rss[$3] += $1; pcpu[$3]+=$2 } END { for (a in rss) printf "%.f, %.1f, %s\n", rss[a], pcpu[a], a }' >> $PRFNAME
    before reading your reply

    Thanks a lot though
    <tronyx> "you should hire me to stare at your wireshark because i can spot a virus being downloaded in a compressed file over bit torrent at up to 600 kb/s"

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •