Ad Widget

Collapse

Monitoring cpu utilisation on linux machines

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alex_SYB
    Senior Member
    • Feb 2012
    • 133

    #1

    Monitoring cpu utilisation on linux machines

    Hi

    I want to track cpu utilisation for a particular user / process .. Is there an easy way to do this ?

    ps is not helping me
  • grep4error
    Junior Member
    • Sep 2012
    • 2

    #2
    use top maybe

    I do it like this

    zabbix_agentd.conf:
    UserParameter=process.cpu[*],top -b -u $1 -n 1|awk '/$2/ {print $ 9}'

    key: process.cpu[<user>,<process>]

    not ideal, but works for simple cases. This is not going to work for multiple process instances though...

    Comment

    • Alex_SYB
      Senior Member
      • Feb 2012
      • 133

      #3
      didn't think about that.

      why a userparm and not a agent run command ?

      I think i like your method better !
      Last edited by Alex_SYB; 18-09-2012, 04:14.

      Comment

      • sirtech
        Junior Member
        • Aug 2012
        • 25

        #4
        Yep I'm doing something similar for this. I used a UserParameter for a couple of reasons. 1 - it minimises the number of SSH connections from the server (think 30 hosts / 60 second intervals; adds up very quickly) and 2 - as a UserParameter the agent can run it in active mode and buffer it when link errors occur.

        Note that if you have multiple instances of a similar command running as the same user but with different arguments and need to distinguish between them (e.g. a bunch of rsync's) , you will need to tell top to display the arguments. By default it only shows the command name. This is the -c switch. I.e. updated UserParameter:

        Code:
        UserParameter=process.cpu[*],top -bc -u $1 -n 1|awk '/$2/ {print $9}'

        Comment

        • Alex_SYB
          Senior Member
          • Feb 2012
          • 133

          #5
          Yeah i found out about the -c command.

          one thing that does do though is change the command from a basename to a fullpathed name ..

          minor

          I do also like how awk handles the $ 9 (space).. that makes life easier !

          I didn't know about the active agent stuff though

          Thanks

          EDIT - how many of the tasks are actually available as active agent tasks ?
          Last edited by Alex_SYB; 19-09-2012, 01:35.

          Comment

          • Alex_SYB
            Senior Member
            • Feb 2012
            • 133

            #6
            Hi


            add

            Code:
            # key process.cpu[<process>] Look at all users
            UserParameter=process.cpu[*],top -b -n 1|awk '/$1/ {print $$9}'
            UserParameter=process.cpucmd[*],top -bc -n 1|awk '/$1/ {print $$9}'

            give me some flexibility

            But when I change the agent type to active... it fails

            i can test with zabbix_get and it returns whats seems to be a valid number.

            Do i have to do anything more to make it work under active ?

            Thanks


            EDIT ... seems like it took some time to come back
            Last edited by Alex_SYB; 19-09-2012, 08:34.

            Comment

            • Alex_SYB
              Senior Member
              • Feb 2012
              • 133

              #7
              Thought I would add to this.

              I found some times if the process was not running zabbix would error out as the would be nothing returned by this scripts so and update


              Code:
              # key process.cpu[<process>] Look at all users
              UserParameter=process.cpu[*],top -b -n 1|awk 'BEGIN {sum=-1} /$1/ {sum=$$9} END { print sum }'
              UserParameter=process.cpucmd[*],top -bc -n 1|awk 'BEGIN {sum=-1} /$1/ {sum=$$9} END { print sum }'

              and if you filter by command line... the regex must be of the form [x]. so if your looking for something with a command line like "ThisIsIt" The search string needs to be something like [T]hisIsIt so it doesn't find itself !

              Comment

              Working...