phpSysInfo

A category for tips and tricks or off-topic things
Post Reply
jeanmarc
Posts: 1833
Joined: Thu Aug 29, 2013 7:16 am

phpSysInfo

Post by jeanmarc » Fri Oct 04, 2019 4:44 pm

Hey,
If you want to have a "Process Status" in phpSysInfo, make this psstatus.php script. Make sure the $file path is correct and edit it to your needs.

Code: Select all

#!/usr/bin/php
<?php
# Create a phpsysinfo psstatus.txt file
# Enable PSStatus in phpsysinfo.ini, change ACCESS="data" into plugin configuration and PROCESSES="nginx,php-fpm,sshd,123solar,metern,com_daemon_loop,freedns"
#ln -s /home/jeanmarc/psstatus.php /usr/local/bin/psstatus

$file = '/srv/http/phpsysinfo/data/psstatus.txt';

if (file_exists($file)) {
    $data = file_get_contents($file);
} else {
    $data = '';
}
$out = '';
$pid = '';
$pid = exec("ps -ef | pgrep nginx | awk 'NR==1'");
if (!empty($pid)) {
    $out .= "nginx | $pid\r\n";
    $pid = '';
}
$pid = '';
$pid = exec("ps -ef | pgrep php-fpm | awk 'NR==1'");
if (!empty($pid)) {
    $out .= "php-fpm | $pid\r\n";
}
$pid = '';
$pid = exec("ps -ef | pgrep sshd | awk 'NR==1'");
if (!empty($pid)) {
    $out .= "sshd | $pid\r\n";
}
$pid = '';
$pid = exec("ps -eo pid,command | grep '123solar.php' | grep -v grep | awk '{print $1}'");
if (!empty($pid)) {
    $out .= "123solar | $pid\r\n";
}
$pid = '';
$pid = exec("ps -eo pid,command | grep 'metern.php' | grep -v grep | awk '{print $1}'");
if (!empty($pid)) {
    $out .= "metern | $pid\r\n";
}
$pid = '';
$pid = exec("ps -eo pid,command | grep 'com_daemon_loop.php' | grep -v grep | awk '{print $1}'");
if (!empty($pid)) {
    $out .= "com_daemon_loop | $pid\r\n";
}
$pid = '';
$pid = exec("ps -eo pid,command | grep 'freedns.php' | grep -v grep | awk '{print $1}'");
if (!empty($pid)) {
    $out .= "freedns | $pid\r\n";
}

if ($out != $data) { // Reduce write
    file_put_contents($file, $out);
}
?>
chmod a+x psstatus.php
make a link : ln -s /path_to/psstatus.php /usr/local/bin/psstatus
then in /etc/ systemd/sytem/ :
A psstatus.service file

Code: Select all

[Unit]
Description=psstatus

[Service]
Type=oneshot
ExecStart=/bin/sh -c 'psstatus'
and a psstatus.timer file

Code: Select all

[Unit]
Description=psstatus

[Timer]
OnBootSec=1min
#OnCalendar=5min
OnUnitActiveSec=5min
Unit=psstatus.service

[Install]
WantedBy=multi-user.target
Finally systemctl enable psstatus.timer and systemctl start psstatus.timer
have fun

jeanmarc
Posts: 1833
Joined: Thu Aug 29, 2013 7:16 am

Re: phpSysInfo

Post by jeanmarc » Fri Oct 04, 2019 6:36 pm

Also in phpsysinfo.ini change to

Code: Select all

[psstatus]
..
ACCESS="data"
..
PROCESSES="nginx,php-fpm,sshd,123solar,metern,com_daemon_loop,freedns"
..

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest