Plugins PHP-FPM

Hello, I come from https://exchange.checkmk.com/p/php-fpm, thank you very much for making this plugins available, I installed it but I have a problem that I could not solve, I have this error.

[root@te-aai-34-03 plugins]# ./php_fpm_pools
<<<php_fpm_pools>>>
[Errno 2] No such file or directory
[root@te-aai-34-03 plugins]#

my config file is this:

[root@te-aai-34-03 plugins]# cat /etc/check_mk/php_fpm_pools.cfg
php_fpm = [
 {"socket": "localhost:9000"}
]
[root@te-aai-34-03 plugins]#

the test according to the checkman works for me.

[root@te-aai-34-03 plugins]# SCRIPT_NAME=/status SCRIPT_FILENAME=/status QUERY_STRING= REQUEST_METHOD=GET cgi-fcgi -bind -connect localhost:9000
X-Powered-By: PHP/7.3.11
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Content-type: text/plain;charset=UTF-8

pool:                 www
process manager:      ondemand
start time:           25/Apr/2020:23:39:06 -0400
start since:          1112
accepted conn:        42
listen queue:         0
max listen queue:     0
listen queue len:     511
idle processes:       0
active processes:     1
total processes:      1
max active processes: 1
max children reached: 0
slow requests:        0
[root@te-aai-34-03 plugins]# 

I don’t know what I could be missing, some help please

my check_mk version is: 1.6.0p11 Raw

Thanks!

JLIO.

1 Like

Hi,
when you run the script from CLI, please set MK_CONFDIR=/etc/check_mk first, or run check_mk_agent instead.

Cheers, Christian

Hi @ChristianM, check environment variables and then run agent and I have the same result.

[root@te-aai-34-03 plugins]# env |grep MK_CONFDIR
MK_CONFDIR=/etc/check_mk
[root@te-aai-34-03 plugins]#
[root@te-aai-34-03 plugins]# check_mk_agent
...
...
...
<<<lnx_vga:sep(58):persist(1588097401)>>>
00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA (prog-if 00 [VGA controller])
        Flags: bus master, fast devsel, latency 0, IRQ 11
        Memory at f8000000 (32-bit, non-prefetchable) [size=64M]
        Expansion ROM at <unassigned> [disabled]
        Kernel driver in use: hyperv_fb
        Kernel modules: hyperv_fb

<<<logwatch>>>
[[[/var/log/messages]]]
[[[/var/log/auth.log:missing]]]
[[[/var/log/syslog:missing]]]
[[[/var/log/kern.log:missing]]]
<<<php_fpm_pools>>>
[Errno 2] No such file or directory
[root@te-aai-34-03 plugins]#
[root@te-aai-34-03 plugins]# ./php_fpm_pools
<<<php_fpm_pools>>>
[Errno 2] No such file or directory
[root@te-aai-34-03 plugins]# 

JLIO

I managed to get the plugin to work:

Most important part was to realise that the script currently cannot handle tcp sockets and only works with unixsockets.
Second annoying part was that the script currently doesn’t iterate over the list, so you can only configure one socket.
Third part was that the script doesn’t tell you that a config_file is mandatory, I changed that to print it out and exit with UNKNOWN.

It’s pretty late now, maybe tomorrow I’ll provide a working code with tcp sockets. Anyways here the adjusted code:

diff php_fpm_pools php_fpm_pools.ori
80d79
<             print(self.socket_path, self.status_path)
82c81
<             #sys.exit(1)
---
>             sys.exit(1)
151,152c150
<     print("Config file does not exist or is empty!")
<     sys.exit(3)
---
>     sys.exit(0)
164a163
>

Thank you very much for your help and of course I can wait until you consider it convenient for the change to tcp socket!

JLIO!

I couldn’t sleep before I solved this:

The /etc/check_mk/php_fpm_pools.cfg now can be configured with a tuple containing host and port. Also, the check can work with both IPv4 and IPv6 as well as DNS resolution.

/etc/check_mk/php_fpm_pools.cfg

php_fpm = [
  {"socket": "/var/run/php/php-fpm.sock", "path": "/status"},
  {"socket": ("localhost", 9000)},
]

Here’s the new diff:

36c36
< #  {"socket": ("localhost", 9000)},
---
> #  {"socket": "localhost:9000"},
77,78d76
<         if type(self.socket_path) is tuple:
<            self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
81,83c79,82
<         except Exception as e:
<             sys.stderr.write("Socket: " + str(self.socket_path) + ", Path: " + self.status_path + "\n")
<             sys.stderr.write(str(e) + "\n")
---
>         except:
>             print(self.socket_path, self.status_path)
>             print(sys.exc_info()[1])
>             #sys.exit(1)
117d115
<                 self.status_data = self.raw_status_data.decode().split("\r\n\r\n")[1]
124,126c122,125
<
<         except Exception as e:
<             sys.stderr.write(str(e) + "\n")
---
>         except:
>             print(sys.exc_info()[1])
>             sys.exit(2)
>         self.status_data = self.raw_status_data.decode().split("\r\n\r\n")[1]
136,142c135,140
<         if hasattr(self, 'status_data'):
<             data = json.loads(self.status_data)
<             pool_name = data.pop('pool', None)
<             pm_type = data.pop('process manager', None)
<             for key in data:
<                 spaceless_key = "_".join( key.split() )
<                 sys.stdout.write("%s %s %s %s\n" % (pool_name, pm_type, spaceless_key, str(data[key])))
---
>         data = json.loads(self.status_data)
>         pool_name = data.pop('pool', None)
>         pm_type = data.pop('process manager', None)
>         for key in data:
>             spaceless_key = "_".join( key.split() )
>             sys.stdout.write("%s %s %s %s\n" % (pool_name, pm_type, spaceless_key, str(data[key])))
167d164
<         continue

I will write the author tomorrow and ask if he can merge my changes and add me as contributor.

Good night!

PS: The script will be printing error messages to stderr, so a human can read them manually running the script while the agent will not get confused with unintentional output:

root@host:~# ./php_fpm_pools
<<<php_fpm_pools>>>
Socket: /var/run/php/php-fpm.sock, Path: /status
[Errno 2] No such file or directory
[Errno 107] Transport endpoint is not connected
www dynamic active_processes 1
www dynamic accepted_conn 196
www dynamic listen_queue 0
www dynamic start_since 5084
www dynamic idle_processes 11
www dynamic start_time 1588117405
www dynamic slow_requests 0
www dynamic max_active_processes 3
www dynamic max_children_reached 0
www dynamic max_listen_queue 0
www dynamic total_processes 12
www dynamic listen_queue_len 128
root@host:~# ./php_fpm_pools 2> /dev/null
<<<php_fpm_pools>>>
www dynamic active_processes 1
www dynamic accepted_conn 197
www dynamic listen_queue 0
www dynamic start_since 5087
www dynamic idle_processes 11
www dynamic start_time 1588117405
www dynamic slow_requests 0
www dynamic max_active_processes 3
www dynamic max_children_reached 0
www dynamic max_listen_queue 0
www dynamic total_processes 12
www dynamic listen_queue_len 128
1 Like

I optimized the plugin furher today and created a pull request in the author’s github repo:

1 Like

@simon-mueller thank you very much for your help and time! hopefully the author accepts the pull request

JLIO