Ad Widget

Collapse

Issues with system.run[] command on Zabbix3.2

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vshah
    Junior Member
    • Nov 2016
    • 7

    #1

    Issues with system.run[] command on Zabbix3.2

    Hello Folks,

    I am trying to get the PID of tomcat process running on all the hosts that we are monitoring

    ps -ef | grep tomcat | grep twadmin | awk '{print $2}'
    or
    ps -ef | grep tomcat | grep twadmin | awk -F ' ' '{print $2}'

    These commands return the exact tomcat PID when I execute it on the hosts
    When I try to do the same thing using Zabbix, it gives me weird outputs
    system.run[ps -ef | grep tomcat | grep twadmin | awk '{print $2}']
    o/p --> 20205 25255
    The right PID is 25255

    It seems like Zabbix is having hard time figuring out using awk
    The same issue happening with sed/cut commands as well

    Can someone please help out with this
    Thanks in advance!!!


    -- Vaibhav
  • allexpetrov
    Senior Member
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2017
    • 361

    #2
    Originally posted by vshah
    Hello Folks,

    I am trying to get the PID of tomcat process running on all the hosts that we are monitoring

    ps -ef | grep tomcat | grep twadmin | awk '{print $2}'
    or
    ps -ef | grep tomcat | grep twadmin | awk -F ' ' '{print $2}'

    These commands return the exact tomcat PID when I execute it on the hosts
    When I try to do the same thing using Zabbix, it gives me weird outputs
    system.run[ps -ef | grep tomcat | grep twadmin | awk '{print $2}']
    o/p --> 20205 25255
    The right PID is 25255

    It seems like Zabbix is having hard time figuring out using awk
    The same issue happening with sed/cut commands as well

    Can someone please help out with this
    Thanks in advance!!!


    -- Vaibhav
    Hi Vailbhav,

    it seems like you have printed 2 values.

    Could you please show the real output of your command on host ?

    Regards,
    Alex
    Last edited by allexpetrov; 15-08-2017, 10:34.

    Comment

    • Semiadmin
      Senior Member
      • Oct 2014
      • 1625

      #3
      Hi, vshah.
      Try to use only awk, without grep.
      For example, for zabbix-agent (I havn't Tomcat now):
      ps -ef |awk '$8 ~/zabbix_agentd/ && $10 ~/zabbix_agentd.conf/ {print $2}'

      Comment

      • jan.garaj
        Senior Member
        Zabbix Certified Specialist
        • Jan 2010
        • 506

        #4
        Your problem is ps -ef | grep tomcat - it greps tomcat process and this grep command as well.

        Easy solution:

        Code:
        ps -C "<KEYWORD>" -o pid=
        Example and comparison with grep solution:

        Code:
        $ ps -ef | grep sshd
        root       1003      1  0 Aug14 ?        00:00:00 /usr/sbin/sshd -D
        root      60439   1003  0 08:00 ?        00:00:00 sshd: root@pts/1
        root      60628   1003  0 09:03 ?        00:00:00 sshd: root@pts/0
        root      60661   1003  0 09:27 ?        00:00:00 sshd: root@notty
        root      61446  60631  0 09:53 pts/0    00:00:00 grep --color=auto sshd
        $ ps -C "sshd" -o pid=
          1003
         60439
         60628
         60661
        See: man ps
        Devops Monitoring Expert advice: Dockerize/automate/monitor all the things.
        My DevOps stack: Docker / Kubernetes / Mesos / ECS / Terraform / Elasticsearch / Zabbix / Grafana / Puppet / Ansible / Vagrant

        Comment

        • vshah
          Junior Member
          • Nov 2016
          • 7

          #5
          Tried all the Inputs - Still Struggling

          Hello Guys,

          1) I tried using all awk as per Semiadmin:
          ps -ef | awk '/tomcat/{print}' | awk '/twadmin/{print}' | awk '{print$2}'
          - Still the same problem

          2) (i) ps -C tomcat -o pid=
          - Doesn't give me anything
          (ii) ps -C java -o pid=
          - gives me the output with other java processes as well along with tomcat

          I just need the tomcat pid (twadmin is the user running it)



          Just FYI:
          All these commands gives me the correct output when I execute it on the host itself:
          ps -ef | awk '/tomcat/{print}' | awk '/twadmin/{print}' | awk '{print$2}'
          ps -aux | grep tomcat | grep twadmin | awk '{print $2}'
          9353

          Comment

          • Semiadmin
            Senior Member
            • Oct 2014
            • 1625

            #6
            vshah, I don't suggest to use awk as grep
            Try to use it as awk, without pipes:
            ps -ef |awk '$8 ~/tomcat/ && $1 ~/twadmin/ {print $2}'

            Comment

            • vshah
              Junior Member
              • Nov 2016
              • 7

              #7
              Ohh...My bad

              Thanks @semiadmin
              I think this works now and I am able to get the PID.

              But this is what I am trying to do at the end:
              1) system.run[pd=$(ps -ef | awk '$8 ~/java/ && $1 ~/twadmin/ {print $2}') | ls -l /proc/$pd/fd | wc -l]

              Error on Zabbix:
              ls: cannot access /proc//fd: No such file or directory
              0

              2) system.run[pid=$(ps -ef | awk '$8 ~/java/ && $1 ~/twadmin/ {print $2}') | cat /proc/$pid/limits | grep "Max open files" | awk '{print $5}']
              Error on Zabbix:
              cat: /proc//limits: No such file or directory

              So this time it's not able to read the value of pid variable
              Last edited by vshah; 16-08-2017, 22:33.

              Comment

              Working...