Ad Widget

Collapse

Highlight processes that use CPU

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djwhyte
    Junior Member
    • Jun 2008
    • 7

    #1

    Highlight processes that use CPU

    Hi,

    I have some brief history with IBM Tivoli Monitoring at work. In Tivoli, you can create 'situations' that for example generically monitor for a process that uses a percentage of CPU and when that situation occurs, it will create an event/alert that can include the name of the process that is using that percentage of CPU.

    I.e. a situation called 'Warning CPU' that is true when *any* process is using >50% and <=80% CPU and when those conditions are true, you can have the process name shown in the event.

    This is useful to identify which processes commonly use a lot of CPU at what times.

    Is there anything like this that can be done in Zabbix? I haven't been able to create custom UserParameters as I am running 1.4.1 and there seem to be issues with this. Would UserParameters be one way to achieve what I want it to do?

    Regards,
    Whytey
  • nelsonab
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2006
    • 1233

    #2
    In linux

    ps -aux | grep <process name> | awk 'BEGIN {$i=0} {$i=$i+$2} END {print $i}'

    This will include the processor percentage used by grep but that's minor. I have a hunch the awk bit has an error, but you get the point. I did it from my head without testing.
    RHCE, author of zbxapi
    Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
    Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

    Comment

    • djwhyte
      Junior Member
      • Jun 2008
      • 7

      #3
      Thanks for your response.

      The problem with this is that I would need to create a new item/trigger for each process that I think I would need to monitor.

      What I am actually looking for is a solution that will let me identify *any* process that may go rogue and chew up CPU (or memory or anything).

      It may be useful to do this to identify what process caused my CPU to chug every night at 7pm or something.

      Also, would your suggestion have to be implemented as a UserParameter?

      Regards,
      Whytey

      Comment

      • nelsonab
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Sep 2006
        • 1233

        #4
        LOL.... I'm trying to do exactly the same thing.

        What I want to do is trigger a remote command which will push the top 5 processes by cpu percentage into zabbix using zabbix_sender when cpu utilization goes above a cretin threshold. However I'm having issues getitng the sender to accept input data from an external file.

        If I manage to find a solution I'll post it.
        RHCE, author of zbxapi
        Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
        Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

        Comment

        • djwhyte
          Junior Member
          • Jun 2008
          • 7

          #5
          Heh, you know what they say about 'great minds thinking alike'

          The problem with having a UserParameter as I see it is that you have to manually go and configure this on every agent where you want to the Item to be. It would be better to just assign it to a template and somehow push that out to every host in that template.

          I need to have a look at this zabbix_sender. I have no idea what that is at this stage. (I am new to Zabbix really)

          Thanks,
          Whytey

          Comment

          • nelsonab
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • Sep 2006
            • 1233

            #6
            :-)

            Well I'm getting closer!

            Rather than figure out what was going on with the standard zabbix sender I wrote one in Ruby. I was able to push the contents of "ps -aux" into zabbix successfully. Now I just need to get it to work as a remote command.

            When I'm able I'll post all source and instructions.
            RHCE, author of zbxapi
            Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
            Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

            Comment

            • ngarnier
              Junior Member
              • Mar 2008
              • 21

              #7
              ps -ef | awk '{ if ($4 > 0) print $0 }'

              It shows process(es) that uses CPU time

              Comment

              • nelsonab
                Senior Member
                Zabbix Certified SpecialistZabbix Certified Professional
                • Sep 2006
                • 1233

                #8
                Alright here's what I have so far

                I'm going to go ahead and post what I have thus far, but in the process I have found a very interesting bug in Zabbix. I need to research this more, and check to see if it's a 1.5.3 only bug.

                I have attached the Ruby script I wrote, but after I verified Zabbix was the source of the bug I realized my work was "overkill".

                Ok so here's what you do:
                1) put the ruby script wherever you like and ensure the Zabbix user can execute the script. Run the script and it will tell you what the command line options are.
                2) Create a key of type text to put the remote data into
                3) Create a trigger condition, example, processor idle below 10%.
                4) Create an action for the trigger and make it include a remote command.
                The remote action syntax is: host:command
                Host is the zabbix hostname, and the command is the full path to the command.
                More information can be found in the manual.

                Data will be pumped in when the trigger activates and deactivates.
                I run the command "ps aux | sort -k3 | tail -10" to show me the top 10 processes by CPU.

                **NOTE** You need to ensure your data is in reverse line order! This way it will be put into the Zabbix server in the correct order when you go to view the data in the Latest Data screen. "tac" is a command you can use to ensure this if needed.


                The bug: This is strange. When I run the script from the command line everything works. When I have it run from the remote command the results are truncated. I need to do a little more testing but it is quite strange. Testing was done on 1.5.3. No information is yet available for 1.4.5.

                If anyone else can verify the same bug please post.
                Attached Files
                RHCE, author of zbxapi
                Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
                Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

                Comment

                • djwhyte
                  Junior Member
                  • Jun 2008
                  • 7

                  #9
                  Hi,

                  Thanks, giving your post a go now but I come across a couple of questions.

                  1) How do I create a Key? I can create an item or a trigger etc, but no key.
                  2) When I run your suggested command 'ps aux | sort -k3 | tail -10' it shows firefox as being at about 14% but in top it is not that high. Is that command supposed to show the current highest ten processes or the cumulative?

                  Regards,
                  Whytey

                  Comment

                  • nelsonab
                    Senior Member
                    Zabbix Certified SpecialistZabbix Certified Professional
                    • Sep 2006
                    • 1233

                    #10
                    key = item

                    It should be sorting on the third field of ps' output which in this case is %cpu. I have found it to be an instantaneous measure just like top.
                    RHCE, author of zbxapi
                    Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
                    Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

                    Comment

                    Working...