nginxinc/nginx-amplify-agent

php-fpm status = IOError: [Errno 2] No such file or directory: 'php-fpm'

actionm opened this issue · 7 comments

OS: FreeBSD 11.1-RELEASE-p1
PHP: 7.0.23 (fpm-fcgi)

sudo -u user python2.7 /usr/bin/nginx-amplify-agent.py start \
                   --config=/etc/amplify-agent/agent.conf \
                   --pid=/var/run/amplify-agent/amplify-agent.pid

and from root.

ls -lh /usr/local/etc/:

-rw-r--r--    1 root     wheel   4.3K Sep  4 16:05 php-fpm.conf.default
drwxr-xr-x    2 root     wheel     5B Sep  5 11:58 php-fpm.d

ls -lh /usr/local/etc/php-fpm.d:

-rw-r--r--  1 root  wheel   587B Sep 14 23:32 user.conf
-rw-r--r--  1 root  wheel    18K Sep 14 22:48 www.conf
-rw-r--r--  1 root  wheel    18K Sep  4 16:05 www.conf.default

cat /usr/local/etc/php-fpm.d/user.conf:

[user]
user = user
group = user
listen = /var/run/php-fpm/php-fpm.sock
pm.status_path = /status
....

cat /usr/local/etc/php-fpm.d/www.conf:

[www]
user = www
group = www
listen = 127.0.0.1:9000
pm.status_path = /status
...
2017-09-15 09:10:38,307 [32678] supervisor ps php-fpm output: [' 9316 18145 php-fpm: pool user (php-fpm)', '17867 18145 php-fpm: pool user (php-fpm)', '18145     1 php-fpm: master process (/usr/local/etc/php-fpm.conf) (php-fpm)', '18146 18145 php-fpm: pool www (php-fpm)', '18147 18145 php-fpm: pool www (php-fpm)', '19438 18145 php-fpm: pool user (php-fpm)', '26010 18145 php-fpm: pool user (php-fpm)', '42333 18145 php-fpm: pool user (php-fpm)', '42334 18145 php-fpm: pool user (php-fpm)', '42335 18145 php-fpm: pool user (php-fpm)', '']
2017-09-15 09:10:38,307 [32678] supervisor phpfpm objects: ['4a62862557cee95ea204f82b43712dae832a66ad4f714aef9fac1f12a6532e81']
2017-09-15 09:10:43,394 [32678] supervisor system objects: ['5e5729dddfbe659ca09bca0f9e9adc117f365888e2e567abcfd951d967ea39ab']
2017-09-15 09:10:43,409 [32678] supervisor ps nginx output: ['18304     1 nginx: master process /usr/local/sbin/nginx', '18305 18304 nginx: worker process (nginx)', '18306 18304 nginx: worker process (nginx)', '18307 18304 nginx: worker process (nginx)', '18308 18304 nginx: worker process (nginx)', '18309 18304 nginx: worker process (nginx)', '18310 18304 nginx: worker process (nginx)', '18311 18304 nginx: worker process (nginx)', '18312 18304 nginx: worker process (nginx)', '18313 18304 nginx: worker process (nginx)', '18314 18304 nginx: worker process (nginx)', '18315 18304 nginx: worker process (nginx)', '18316 18304 nginx: worker process (nginx)', '18317 18304 nginx: worker process (nginx)', '18318 18304 nginx: worker process (nginx)', '18319 18304 nginx: worker process (nginx)', '18320 18304 nginx: worker process (nginx)', '18321 18304 nginx: worker process (nginx)', '18323 18304 nginx: worker process (nginx)', '18324 18304 nginx: worker process (nginx)', '18325 18304 nginx: worker process (nginx)', '18327 18304 nginx: worker process (nginx)', '18328 18304 nginx: worker process (nginx)', '18330 18304 nginx: worker process (nginx)', '18331 18304 nginx: worker process (nginx)', '18332 18304 nginx: worker process (nginx)', '18333 18304 nginx: worker process (nginx)', '18334 18304 nginx: worker process (nginx)', '18335 18304 nginx: worker process (nginx)', '18336 18304 nginx: worker process (nginx)', '18337 18304 nginx: worker process (nginx)', '18338 18304 nginx: worker process (nginx)', '18339 18304 nginx: worker process (nginx)', '']
2017-09-15 09:10:43,422 [32678] supervisor nginx objects: ['a7a11e5276c9e0fac53f986e67f584c500de456a93d3df62831d5ebcc349df78']
2017-09-15 09:10:43,422 [32678] supervisor plus objects: []
2017-09-15 09:10:43,423 [32678] supervisor run failed
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/nginx_amplify_agent-0.45-py2.7.egg/amplify/agent/managers/abstract.py", line 134, in _run
    self._discover()
  File "/usr/local/lib/python2.7/site-packages/nginx_amplify_agent-0.45-py2.7.egg/amplify/agent/managers/abstract.py", line 109, in _discover
    self._discover_objects()
  File "/usr/local/lib/python2.7/site-packages/nginx_amplify_agent-0.45-py2.7.egg/amplify/ext/phpfpm/managers/pool.py", line 42, in _discover_objects
    discovered_pools = self._find_all()
  File "/usr/local/lib/python2.7/site-packages/nginx_amplify_agent-0.45-py2.7.egg/amplify/ext/phpfpm/managers/pool.py", line 91, in _find_all
    master_config = master.parse()
  File "/usr/local/lib/python2.7/site-packages/nginx_amplify_agent-0.45-py2.7.egg/amplify/ext/phpfpm/objects/master.py", line 62, in parse
    self.parsed_conf = PHPFPMConfig(path=self.conf_path).parsed
  File "/usr/local/lib/python2.7/site-packages/nginx_amplify_agent-0.45-py2.7.egg/amplify/ext/phpfpm/util/parser.py", line 50, in __init__
    self.read(self.path)
  File "/usr/local/lib/python2.7/site-packages/nginx_amplify_agent-0.45-py2.7.egg/amplify/ext/phpfpm/util/parser.py", line 69, in read
    self._parse_file(root)
  File "/usr/local/lib/python2.7/site-packages/nginx_amplify_agent-0.45-py2.7.egg/amplify/ext/phpfpm/util/parser.py", line 103, in _parse_file
    with open(path, 'r') as conf_file:
IOError: [Errno 2] No such file or directory: 'php-fpm'

Yes, I can re-create this.. Investigating.

The issue is in how we parse the ps output trying to find the php-fpm config.

It's in

/usr/local/lib/python2.7/site-packages/nginx_amplify_agent-0.46-py2.7.egg/amplify/ext/phpfpm/util/ps.py

Line 32 should be something like:

_PS_MASTER_REGEX = re.compile(r'.*\((?P<conf_path>\/[^\)]*)\).*')

Can you possibly try it out and see if it helps?

Couple of other issues with the default configuration on FreeBSD 11 are:

  1. The /proc can be unmounted by default, and we can't find certain metrics. (also can't detect php-fpm meta info due to a minor bug in the agent, but that's harmless)
  2. If error.log and/or access.log are not explicitly defined in nginx.conf, we won't be collecting "metrics from logs"
  1. mount -t procfs proc /proc
  2. _PS_MASTER_REGEX = re.compile(r'.((?P<conf_path>/[^\)])).*')

Thank you. The problem with php-fpm has been solved.

I concur with @ptreyes assessment and fix. I haven't seen a master ps line like this before:

18145     1 php-fpm: master process (/usr/local/etc/php-fpm.conf) (php-fpm)

So far all of the outputs I have seen don't have the ending "php-fpm" in parentheses. Perhaps what we should do is find all strings in parentheses like so:

>>> new_regex = re.compile(r'\((?P<conf_path>[^()]+)\)')
>>> new_regex.findall(<ps_output>)

Using this findall method we will get:

>>> new_regex.findall('18145     1 php-fpm: master process (/usr/local/etc/php-fpm.conf) (php-fpm)')
['/usr/local/etc/php-fpm.conf', 'php-fpm']

And we can default to the first occurrence or try each in order until we have a success, raising an error only after all fail.

If php-fpm processes ~1000 RPS, the amplify agent doesn't send any statistics.

Perhaps this should be a new ticket?

Our collection service depends on firing a request at the php-fpm status page it is possible your workers are getting overloaded and hitting our timeout.

Could you check your log for error messages like:

'pool communication at "%s" timed out'

or...

'failed to communicate with pool at "%s"'

Where the %s format should be the FCGI socket address we are trying to connect to.