Hi guys,
I did a search if somebody made a ps1 script before to read the status page of PHP-FPM. But it doesn't seem to exist yet?
Unfortunately I'm not handy with this and I would appreciate some help.
PHP-FPM has a built-in status page that can be found at a url like http://192.168.1.1/php_status and with the output that looks like this:
pool: www process manager: dynamic start time: 06/Jan/2018:22:09:55 +0100 start since: 171667 accepted conn: 425766 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: 2 slow requests: 0
I would like to add all the integer values in prtg.
I already found a NGINX PRTG PS1 script that is very much alike (this one: https://helpdesk.paessler.com/en/support/solutions/articles/60186-nginx-status-monitor-sensor) and I'm using that also. But I was not able to find a PHP-status page version.
Is somebody able to help me out?
Article Comments
Hello Dariusz,
I think you misunderstood me. I'm looking for someone that is able to make a ps1 script for me for the php status page I described above.
It is would be the same idea as the existing nginx ps1 script. I'm using that nginx ps1 script for our nginx status page. But obviously that script can't be used for the php status page, because the data and the values are different.
Jan, 2018 - Permalink
Hi there,
You are right, I somehow didn't got that. :)
Unfortunately, we do not write any custom scripts without a broader use case for many users. Could you give some insight by what application this status page is created?
I would recommend to the use the Nginx Script and to alter it to your needs with the PowerShell ISE. This would be the fastest and easiest way to get this script.
Best regards.
Jan, 2018 - Permalink
Hi Dariusz,
No problem.
The PHP-FPM Status page is wider accepted than the Nginx status page.
Some information about this built-in functionality of PHP-FPM:
https://brandonwamboldt.ca/understanding-the-php-fpm-status-page-1603/
If webservers use the PHP-FPM instance (which they should, because it is the fastest PHP solution for webservers). You are able to enable a built-in status page if PHP-FPM:
Example tutorial for Nginx: https://easyengine.io/tutorials/php/fpm-status-page/
This status page is not a custom page but a standard and built in page in PHP-FPM. Just like the built in status page of Nginx.
It is very helpful in monitoring the health of a servers PHP-FPM pool, running processes and limits.
A lot of admins and hosting providers use this status page.
I think it is worth considering to make a ps1 for it.
Jan, 2018 - Permalink
Hi there,
Thanks for the information. Could you send us a brief description of what values are especially important to monitor. With other word, which values from the initial answer should be monitored? :)
Best regards.
Jan, 2018 - Permalink
Sure, these are the important ones:
- listen queue = the amount of (TCP) requests that are waiting to be accepted. should be 0 in normal circumstances and * will cause delay if this queue is filled. Normally it can happen under heavy server load and so on.
- max listen queue = the longest the queue has been since php-fpm was started
- listen queue len = the queue length of socket based (so instead of TCP) connections. Should be 0 in healthy circumstances
- idle processes = number of php processes that are ready to handle requests, but are idle at the moment
- active processes = number of php processes that are handling requests at this moment
- total processes = Total of php processes that are (pre)loaded in the memory (idle + active processes)
- max active processes = the maximum of processes this PHP-FPM instance may start to handle requests
- max children reached = the number of times the webserver would need more active processes than allowed
- slow requests = the number of requests that are considered slow according to the request_slowlog_timeout setting in php. When this number is not 0 there are requests that take a too long time to finish.
The following parameters are not interesting to monitor (I think):
- pool = name of the pool - this is static
- process manager = mode of the process manager, also static
- start time = date and time te php-fpm process was started
- start since = how many seconds ago the php-fpm process was started
- accepted conn = the amount of connections php-fpm has handled since it was started
Hopefully the information above is useful to you. If there are any questions, let me know.
Jan, 2018 - Permalink
Hi there,
Thank you for the extensive information. In order to build the script, I will need an example of the status page. Could you post the raw code of such a status page so we can see the HTML elements, if any. Please upload it here (the sourcecode) or on Pastebin.
Best regards.
Jan, 2018 - Permalink
The code in my opening post was the source, haha. There isn't any html in it. Just plain text.
So in Google Chrome, the source (view-source:http://192.168.1.1/php_status) gives you this:
pool: www process manager: dynamic start time: 09/Jan/2018:22:38:59 +0100 start since: 1252 accepted conn: 2497 listen queue: 0 max listen queue: 0 listen queue len: 0 idle processes: 13 active processes: 1 total processes: 14 max active processes: 13 max children reached: 0 slow requests: 0
Jan, 2018 - Permalink
Hi there,
Could you try the following script? Just change the URL parameter on top:
param( $url = "http://myserver/php_fm.txt" ) $status_page = Invoke-WebRequest -uri $url -UseBasicParsing $statistics = ,@("value","name") # listen queue $status_page.RawContent -match '(listen queue:\s+)(\d+)' | Out-Null $statistics += ,@($matches[2],"listen queue") # max listen queue $status_page.RawContent -match '(max listen queue:\s+)(\d+)' | Out-Null $statistics += ,@($matches[2],"max listen queue") # listen queue len $status_page.RawContent -match '(listen queue len:\s+)(\d+)' | Out-Null $statistics += ,@($matches[2],"listen queue") # idle processes $status_page.RawContent -match '(idle processes:\s+)(\d+)' | Out-Null $statistics += ,@($matches[2],"idle processes") # active processes $status_page.RawContent -match '(active processes:\s+)(\d+)' | Out-Null $statistics += ,@($matches[2],"active processes") # total processes $status_page.RawContent -match '(total processes: \s+)(\d+)' | Out-Null $statistics += ,@($matches[2],"total processes") # max active processes $status_page.RawContent -match '(max active processes:\s+)(\d+)' | Out-Null $statistics += ,@($matches[2],"max active processes") # max children reached $status_page.RawContent -match '(max children reached:\s+)(\d+)' | Out-Null $statistics += ,@($matches[2],"max children reached") # slow requests $status_page.RawContent -match '(slow requests:\s+)(\d+)' | Out-Null $statistics += ,@($matches[2],"slow requests") Write-Host @" <PRTG> "@ for ($i=1; $i -lt $statistics.Count; $i++){ Write-Host @" <result> <channel>$($statistics[$i][1])</channel> <value>$($statistics[$i][0])</value> <Float>0</Float> <unit>Count</unit> "@ if($statistics[$i][1] -eq "listen queue" -or $statistics[$i][1] -eq "listen queue len"){ Write-Host @" <LimitMode>1</LimitMode> <LimitMaxError>1</LimitMaxError> "@ } Write-Host @" </result> "@ } Write-Host @" </PRTG> "@
You can add this script in PRTG via the EXE/Script Advanced Sensor and by entering "-url "http://myserver/php"" into the "Parameters"-field.
Best regards.
Jan, 2018 - Permalink
It works!
Small remark, the 'listen queue' started red because the error value was pre-set to 0, for myself I changed it to 1 as our server shouldn't queue at all and when it does, it is an error. But for others a higher value than 1 could be an error.
I'm very happy with this.
I'm amazed by your fast service. Happy that we chose PRTG! :)
Thank you very much! Dziekuje bardzo!
Jan, 2018 - Permalink
Hi there,
I have changed the script accordingly. :)
Thank you for the positive feedback! We will add the script to our Script World as well to get easier found.
Best regards.
Jan, 2018 - Permalink
Hi there,
What error/result do you get specifically when you run the PowerShell Script you have linked, against your Nginx Status Page (http://192.168.1.1/php_status)? This would help us further to help you. :)
Best regards.
Jan, 2018 - Permalink