Results 1 to 9 of 9

Thread: getting value from TOP command

  1. #1

    Question getting value from TOP command

    Hello, everybody,
    I'm interesting how can I get a single value from TOP command (I mean, a single value that represents a CPU usage by a certain process). This problem comes from following:
    I use "top" to evaluate an average of CPU usage by a certain process. If you would put duration to 0.2 (refresh time for "top"), every 0.2 seconds you'll get a new value. It is hard to evaluate the average using the "top" table. That's why I want to get every 0.2 seconds just a value, put it into a stack. After, say, a minute, take all values and evaluate the average. Is it possible to do?
    Thanks in advance.

  2. #2
    ab@novell.com NNTP User

    Default Re: getting value from TOP command

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Why not use 'ps'?

    ps aux | grep processName | grep -v grep | awk '{print $3}'

    Replace 'processName' with your process.

    Good luck.





    diktofon wrote:
    > Hello, everybody,
    > I'm interesting how can I get a single value from TOP command (I mean,
    > a single value that represents a CPU usage by a certain process). This
    > problem comes from following:
    > I use "top" to evaluate an average of CPU usage by a certain process.
    > If you would put duration to 0.2 (refresh time for "top"), every 0.2
    > seconds you'll get a new value. It is hard to evaluate the average using
    > the "top" table. That's why I want to get every 0.2 seconds just a
    > value, put it into a stack. After, say, a minute, take all values and
    > evaluate the average. Is it possible to do?
    > Thanks in advance.
    >
    >

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFJEed93s42bA80+9kRAsDuAJ9G0oqVPDkFVGjH+JIdedkH++j+ygCfSc3S
    gOzrdLxdOXpfwtTv12cXheA=
    =a738
    -----END PGP SIGNATURE-----

  3. #3

    Question Re: getting value from TOP command

    Quote Originally Posted by ab@novell.com View Post
    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Why not use 'ps'?

    ps aux | grep processName | grep -v grep | awk '{print $3}'

    Replace 'processName' with your process.
    That is cool! Thanks. Does anybody have an idea, how to put it now into the script, that will execute that command automatically each 0.2 seconds and put the obtained values into text file? (I do not ask for the script, just ideas).

  4. #4
    ab@novell.com NNTP User

    Default Re: getting value from TOP command

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    #!/bin/bash
    while [ 1 ]; do
    ps aux | grep processName | grep -v grep | awk '{print $3}' > filename
    sleep 0.2
    done

    There's a start.

    Good luck.





    diktofon wrote:
    > ab@novell.com;1892160 Wrote:
    >> -----BEGIN PGP SIGNED MESSAGE-----
    >> Hash: SHA1
    >>
    >> Why not use 'ps'?
    >>
    >> ps aux | grep processName | grep -v grep | awk '{print $3}'
    >>
    >> Replace 'processName' with your process.
    >>
    >>

    >
    > That is cool! Thanks. Does anybody have an idea, how to put it now into
    > the script, that will execute that command automatically each 0.2
    > seconds and put the obtained values into text file? (I do not ask for
    > the script, just ideas).
    >
    >

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFJEitZ3s42bA80+9kRAhHXAJ9E/7iMmBKv7qs1DmEFgVwzbJFo0QCfah26
    SWnI61ucGkPuko5EOpkrpt0=
    =HQCR
    -----END PGP SIGNATURE-----

  5. #5
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: getting value from TOP command

    top has a -b option which prints to stdout. It's intended to let you filter the output in whatever way you want. See the man page.

  6. #6
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    1,273

    Default Re: getting value from TOP command

    Not meaning to hijack the thread... but thinking along these lines when looking at CPU values in top, it does not always correspond with what processes are doing.

    For instance.. the processes can be running normally (no heavy CPU use), but looking at the CPU's itself the wa (wait for access?) can be as high as 99%.

    How does one go about finding out what is causing that if it does not seem directly related to a running process?
    Have a lot of fun!

  7. #7
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: getting value from TOP command

    Wait is wait for I/O completion, so it would be due to device I/O holding things up.

  8. #8

    Question Re: getting value from TOP command

    Quote Originally Posted by ab@novell.com View Post
    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    #!/bin/bash
    while [ 1 ]; do
    ps aux | grep processName | grep -v grep | awk '{print $3}' > filename
    sleep 0.2
    done

    There's a start.

    Good luck.
    Sorry for my stupidness, but when I try to write all this lines in Konsole, I've got the message:

    alexey@right:~> while [1]; do
    > ps aux|grep Xorg|grep -v grep|awk '{print $3}' > my.txt
    > sleep 0.2
    > done
    bash: [1]: command not found

    Am I doing something wrong? Maybe I have to use another program instead of Shell?

  9. #9
    ab@novell.com NNTP User

    Default Re: getting value from TOP command

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Put spaces around '1' on the while line.

    Good luck.





    diktofon wrote:
    > ab@novell.com;1892300 Wrote:
    >> -----BEGIN PGP SIGNED MESSAGE-----
    >> Hash: SHA1
    >>
    >> #!/bin/bash
    >> while [ 1 ]; do
    >> ps aux | grep processName | grep -v grep | awk '{print $3}' > filename
    >> sleep 0.2
    >> done
    >>
    >> There's a start.
    >>
    >> Good luck.
    >>
    >>

    >
    > Sorry for my stupidness, but when I try to write all this lines in
    > Konsole, I've got the message:
    >
    > alexey@right:~> while [1]; do
    >> ps aux|grep Xorg|grep -v grep|awk '{print $3}' > my.txt
    >> sleep 0.2
    >> done

    > bash: [1]: command not found
    >
    > Am I doing something wrong? Maybe I have to use another program instead
    > of Shell?
    >
    >

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFJGHFe3s42bA80+9kRAq9tAJ0bNaemifgKx0bOhaFcRE575zy/EgCfdHnM
    1SJBQb6kp8b2dB0+D0KsxoM=
    =+7Vk
    -----END PGP SIGNATURE-----

Posting Permissions

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