Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-13622

Agent items proc.num and proc.mem count 2 extra when called with -t (test item mode) with cmdline filtering

XMLWordPrintable

    • Icon: Patch request Patch request
    • Resolution: Duplicate
    • Icon: Trivial Trivial
    • None
    • 4.0.0alpha4
    • None

      Let's count number of running apache processes by using pgrep:

      $ pgrep -ca apache
      6
      

      Let's double check:

      $ ps axuwww | grep apache
      root       721  0.0  0.2 379608 33972 ?        Ss   Mar06   0:26 /usr/sbin/apache2 -k start
      vl       27738  0.0  0.0  14000   984 pts/10   S+   17:47   0:00 grep --color=always apache
      www-data 28946  0.0  0.0 379680 10924 ?        S    06:25   0:00 /usr/sbin/apache2 -k start
      www-data 28947  0.0  0.0 379680 10924 ?        S    06:25   0:00 /usr/sbin/apache2 -k start
      www-data 28948  0.0  0.0 379648  9668 ?        S    06:25   0:00 /usr/sbin/apache2 -k start
      www-data 28949  0.0  0.0 379648  9668 ?        S    06:25   0:00 /usr/sbin/apache2 -k start
      www-data 28950  0.0  0.0 379680 10924 ?        S    06:25   0:00 /usr/sbin/apache2 -k start
      

      We can see that we have 6 processes running, matching command-line pattern "apache".

      Let's use zabbix_agentd to get the same thing:

      $ sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf -t proc.num[,,,apache2]
      proc.num[,,,apache2]                          [u|8]
      

      Why 8? It appeared it also counts itself (2 times) as its command-line contains the same pattern, in 2 files:

      /proc/<OWNPID>/cmdline
      /proc/thread-self/cmdline
      

      In the code we already filter out /proc/self but this is not enough as it points to the corresponding PID file. So what we need is follow the link and ignore the PID that it points to.

      The attached patch takes care of it. After applying it:

      $ sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf -t proc.num[,,,apache2]
      proc.num[,,,apache2]                          [u|6]
      

      we get the correct value.

      In addition, the patch makes agent ignore any non-numeric entries in /proc.

      P. S. This happens only when calling zabbix_agentd with -t (test mode).

            Unassigned Unassigned
            dimir dimir
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: