elcamlost / checkmk-php-fpm-plugin

9 stars 7 forks source link

discover_fpm doesn't discover all fpm configs #11

Closed 4oo4 closed 1 year ago

4oo4 commented 2 years ago

I can't get the plugin discover my correct php-fpm config, I'm wondering if it's because the socket config it's looking for is within a second config file.

The plugin is reading the cmdline for the php-fpm process, which is php-fpm: master process (/etc/php8/php-fpm.conf). Then it only seems to be looking within /etc/php8/php-fpm.conf for the pm.status* config. However, the actual config for the status monitoring is in /etc/php8/php-fpm.d/www.conf and the plugin never picks it up.

So I think it might just also have to look to see if that main config file has something like include=/etc/php8/php-fpm.d/*.conf, then also search within additional files for the necessary config settings. This might just be a quirk of how Alpine does their configs but I think the configs in deb.sury.org repos for other distros are similar.

Cheers

jplitza commented 1 year ago

The plugin should parse includes correctly: https://github.com/elcamlost/checkmk-php-fpm-plugin/blob/0d51b85ad5b42c9dccde19fe2b2cf88fe4ee5613/php-fpm/agents/plugins/php_fpm_pools#L141-L152 In particular, the include line you posted is quite standard and works fine on many servers for me.

Can you maybe post you php-fpm.conf as well as www.conf here (redacting possibly identifying or sensitive information)?

4oo4 commented 1 year ago

Wow, I totally missed that when I read through the code before, sorry.

Before when I was testing, I modified the output like this to print the config files and settings it was finding:

sys.stdout.write('<<<php_fpm_pools>>>\n')
for configfile in discover_fpm():
    print(configfile)
    for fpm_status in parse_fpm_config(parse_includes(configfile)):
        print(fpm_status)
        if not fpm_status.get('path'):
            continue
        try:
            fcgi_client = FCGIStatusClient( socket_path = fpm_status.get('socket'), status_path = fpm_status.get('path', '/status') )
            fcgi_client.make_request()
            fcgi_client.print_status()

        except Exception as e:
            sys.stderr.write('Exception (%s): %s\n' % (fpm_status.get('socket'), e))

And that output the following:

python3 /usr/lib/check_mk_agent/plugins/php_fpm_pools 
<<<php_fpm_pools>>>
/etc/php8/php-fpm.conf

So, this would be what's getting parsed:

pool: www process manager: dynamic start time: 16/Nov/2022:04:01:07 -0600 start since: 55409 accepted conn: 19491 listen queue: 0 max listen queue: 0 listen queue len: 0 idle processes: 19 active processes: 1 total processes: 20 max active processes: 35 max children reached: 0 slow requests: 0

Thanks

**EDIT:** I think the culprit is this:

```python
        if listen and not listen.startswith('/'):
            if 'prefix' in section:
                listen = os.path.join(section['prefix'], listen)
            else:
                # we cannot infer the relative listen anchor
                print("we cannot infer the relative listen anchor")
                continue

When I add that print statement, I can see it's hitting that else clause. If I'm reading that correctly it's looking for a prefix setting in my fpm config?

jplitza commented 1 year ago

I think the culprit is this:...

I agree.

If I'm reading that correctly it's looking for a prefix setting in my fpm config?

The problem more likely is that ConfigParser doesn't understand quotes (I guess). Try removing the quotes from the listen path.

4oo4 commented 1 year ago

Removing the quotes for listen fixed it, thanks!