Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Server Load help
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / General / General Chat

2023-05-20 18:57:58
hy, I have a problem with script Server load  can anyone help me

I'm using debian 11
I use the script below  

<?php
begin_frame(T_("SERVER_LOAD"));
$server_check_version = '1.0.4';
$start_time = microtime(TRUE);

$operating_system = PHP_OS_FAMILY;

if ($operating_system === 'Windows') {
// Win CPU
$wmi = new COM('WinMgmts:\\\\.');
$cpus = $wmi->InstancesOf('Win32_Processor');
$cpuload = 0;
$cpu_count = 0;
foreach ($cpus as $key => $cpu) {
$cpuload += $cpu->LoadPercentage;
$cpu_count++;
}
// WIN MEM
$res = $wmi->ExecQuery('SELECT FreePhysicalMemory,FreeVirtualMemory,TotalSwapSpaceSize,TotalVirtualMemorySize,TotalVisibleMemorySize FROM Win32_OperatingSystem');
$mem = $res->ItemIndex(0);
$memtotal = round($mem->TotalVisibleMemorySize / 1000000,2);
$memavailable = round($mem->FreePhysicalMemory / 1000000,2);
$memused = round($memtotal-$memavailable,2);
// WIN CONNECTIONS
$connections = shell_exec('netstat -nt | findstr :80 | findstr ESTABLISHED | find /C /V ""');
$totalconnections = shell_exec('netstat -nt | findstr :80 | find /C /V ""');
} else {
// Linux CPU
$load = sys_getloadavg();
$cpuload = $load[0];
// Linux MEM
      // RAM usage
      $meminfo = @file_get_contents("/proc/meminfo");
      preg_match("!^MemTotal:\s*(.*) kB!m", $meminfo, $memtotal);
      $memtotal = $memtotal[1] * 1024;
      preg_match("!^MemFree:\s*(.*) kB!m", $meminfo, $memfree);
      $memfree = $memfree[1] * 1024;
      preg_match("!^Buffers:\s*(.*) kB!m", $meminfo, $buffers);
      $buffers = $buffers[1] * 1024;
      preg_match("!^Cached:\s*(.*) kB!m", $meminfo, $cached);
      $cached = $cached[1] * 1024;

      $memused = mksize($memtotal - $memfree - $buffers - $cached);
      $memtotal = mksize($memtotal);
// Linux Connections
}

$memusage = round(($memused/$memtotal)*100);



$phpload = round(memory_get_usage() / 1000000,2);

$diskfree = round(disk_free_space(".") / 1000000000);
$disktotal = round(disk_total_space(".") / 1000000000);
$diskused = round($disktotal - $diskfree);

$diskusage = round($diskused/$disktotal*100);

if ($memusage > 85 || $cpuload > 85 || $diskusage > 85) {
$trafficlight = 'red';
} elseif ($memusage > 50 || $cpuload > 50 || $diskusage > 50) {
$trafficlight = 'orange';
} else {
$trafficlight = '#2F2';
}

$end_time = microtime(TRUE);
$time_taken = $end_time - $start_time;
$total_time = round($time_taken,4);

// use servercheck.php?json=1
//if (isset($_GET['json'])) {
// echo '{"ram":'.$memusage.',"cpu":'.$cpuload.',"disk":'.$diskusage.',"uptime":'.$uptime.'}';
// exit;
//}

 //$uptime = @file_get_contents( "/proc/uptime");
  $uptime = strtok( exec( "cat /proc/uptime" ), "." );
  $uptime = explode(" ",$uptime);
   $uptime = $uptime[0];
   $days = explode(".",(($uptime % 31556926) / 86400));
   $hours = explode(".",((($uptime % 31556926) % 86400) / 3600));
   $minutes = explode(".",(((($uptime % 31556926) % 86400) % 3600) / 60));
   $seconds = explode(".",((((($uptime % 31556926) % 86400) % 3600) / 60) / 60));

   $time = $days[0]."days:".$hours[0]."hours:".$minutes[0]."minutes";

// Operating system
      $temp = file_get_contents("/proc/version");
      if ($temp) {
          $osarray = explode(" ", $temp);
          $distros = [
              "Gentoo", "/etc/gentoo-release",
              "Fedora Core", "/etc/fedora-release",
              "Slackware", "/etc/slackware-version",
              "Cobalt", "/etc/cobalt-release",
              "Debian", "/etc/debian_version",
              "Mandrake", "/etc/mandrake-release",
              "Mandrake", "/etc/mandrakelinux-release",
              "Yellow Dog", "/etc/yellowdog-release",
              "Red Hat", "cat /etc/redhat-release", //Red Hat centos
              "Arch Linux", "/etc/arch-release",
          ];

          $distro = "";
          if (file_exists("cat /etc/*-release")) {
              $lsb = file_get_contents("cat /etc/*-release");
              preg_match('!DISTRIB_DESCRIPTION="(.*)"!', $lsb, $distro);
              $distro = $distro[1];
          } else {
              do {
                  if (file_exists($distros[1])) {
                      $distro = file_get_contents($distros[1]);
                      $distro = "$distros[0] " . preg_replace("/[^0-9]*([0-9.]+)[^0-9.]{0,1}.*/", "\\1", $distro);
                      break;
                  }
                  array_shift($distros);
                  array_shift($distros);
              } while (count($distros));
          }

          if (!$distro) {
              $distro = "Unknown Distro";
          }

          $operatingsystem = "$distro ($osarray[0] $osarray[2])";
      } else {
          $operatingsystem = "(N/A)";
      }

 



?>

<body>
<div id="container"  align="center">
<div id="trafficlight" class="nodark"></div>

<p><span class="description big">🌡️ RAM Usage:</span> <span class="result big"><?php echo $memusage; ?>%</span></p>
<p><span class="description big">🖥️ CPU Usage: </span> <span class="result big"><?php echo $cpuload; ?>%</span></p>
<p><span class="description">💽 Hard Disk Usage: </span> <span class="result"><?php echo $diskusage; ?>%</span></p>
<center><img src=images/pic_tbv/sageata.png></center>
<p><span class="description">🖧 <b><font color=lime><font color=red>Uptime</font>: </span> <span class="result"><?php echo $time; ?></font></b></span></p>
<p><span class="description">🖧 OS: </span> <span class="result"><?php echo $operatingsystem; ?></span></p>
<center><img src=images/pic_tbv/sageata.png></center>
<p><span class="description">🌡️ RAM Total:</span> <span class="result"><?php echo $memtotal; ?> GB</span></p>
<p><span class="description">🌡️ RAM Used:</span> <span class="result"><?php echo $memused; ?> GB</span></p>
<p><span class="description">🌡️ RAM Available:</span> <span class="result"><?php echo $memtotal; ?> GB</span></p>
<center><img src=images/pic_tbv/sageata.png></center>
<p><span class="description">💽 Hard Disk Free:</span> <span class="result"><?php echo $diskfree; ?> GB</span></p>
<p><span class="description">💽 Hard Disk Used:</span> <span class="result"><?php echo $diskused; ?> GB</span></p>
<p><span class="description">💽 Hard Disk Total:</span> <span class="result"><?php echo $disktotal; ?> GB</span></p>
<center><img src=images/pic_tbv/sageata.png></center>
<div id="details">

<p><span class="description">🌀 PHP Version: </span> <span class="result"><?php echo phpversion(); ?></span></p>
<p><span class="description">🏋️ PHP Load: </span> <span class="result"><?php echo $phpload; ?> GB</span></p>

<p><span class="description">⏱️ Load Time: </span> <span class="result"><?php echo $total_time; ?> sec</span></p>
</div>
</div>


</body>

<?
end_frame();
?>
loadsvr1.png
loadsvr1.png
serverscr.png
serverscr.png
Last edited by crisphp on 2023-05-20 19:00:22
2023-05-21 08:06:01
Do you have tested serverload_block.php block?



<?php
#================================#
#       TorrentTrader 2.08          #
#  torrenttrader.uk                   #
#--------------------------------#
#       Modified by M-Jay          #
#================================#

//SERVER LOAD BLOCK

begin_block(T_("SERVER_LOAD"));

if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") {
if (!class_exists("COM"))
echo "COM support not available.";
else {
function mkprettytime2($s){
foreach (array("60:sec","60:min","24:hour","1:day") as $x) {
$y = explode(":", $x);
if ($y[0] > 1) {
$v = $s % $y[0];
$s = floor($s / $y[0]);
} else
$v = $s;
$t[$y[1]] = $v;
}

if ($t['week'] > 1 || $t['week'] == 0) $wk = " weeks";
else $wk = " week";
if ($t['day'] > 1 || $t['day'] == 0) $day = " days";
else $day = " day";
if ($t['hour'] > 1 || $t['hour'] == 0) $hr = " hrs";
else $hr = " hr";
if ($t['min'] > 1 || $t['min'] == 0) $min = " mins";
else $min = " min";
if ($t['sec'] > 1 || $t['sec'] == 0) $sec = " secs";
else $sec = " sec";

if ($t["month"])
return "{$t['month']}$mth {$t['week']}$wk {$t['day']}$day ".sprintf("%d$hr %02d$min %02d$sec", $t["hour"], $t["min"], $t["sec"], $f["month"]);
if ($t["week"])
return "{$t['week']}$wk {$t['day']}$day ".sprintf("%d$hr %02d$min %02d$sec", $t["hour"], $t["min"], $t["sec"], $f["month"]);
if ($t["day"])
return "{$t['day']}$day ".sprintf("%d$hr %02d$min %02d$sec", $t["hour"], $t["min"], $t["sec"]);
if ($t["hour"])
return sprintf("%d$hr %02d$min %02d$sec", $t["hour"], $t["min"], $t["sec"]);
if ($t["min"])
return sprintf("%d$min %02d$sec", $t["min"], $t["sec"]);
return $t["sec"].$sec;
}

if (version_compare(PHP_VERSION, '5.0.0', '<'))
require("backend/serverload4.php");
else
require("backend/serverload5.php");
}
} else {
// Users and load information
$reguptime = exec("uptime");
if ($reguptime) {
if (preg_match("/up (.*), *(\d) (users?), .*: (.*), (.*), (.*)/", $reguptime, $uptime)) {
$up = preg_replace("!(\d\d):(\d\d)!", '\1h\2m', $uptime[1]);
$users[0] = $uptime[2];
$users[1] = $uptime[3];
$loadnow = $uptime[4];
$load5 = $uptime[5];
$load15 = $uptime[6];

// CPU Information
exec ("cat /proc/cpuinfo", $details);
$processor1 = $details[4];

}
} else {
$up = "--";
$users[0] = "NA";
$users[1] = "--";
$loadnow = "NA";
$load5 = "--";
$load15 = "--";
}


// Operating system
$temp = file_get_contents("/proc/version");
if ($temp) {

$osarray = explode(" ", $temp);

$distros = array(
"Gentoo", "/etc/gentoo-release",
"Fedora Core", "/etc/fedora-release",
"Slackware", "/etc/slackware-version",
"Cobalt", "/etc/cobalt-release",
"Debian", "/etc/debian_version",
"Mandrake", "/etc/mandrake-release",
"Mandrake", "/etc/mandrakelinux-release",
"Yellow Dog", "/etc/yellowdog-release",
"Red Hat", "/etc/redhat-release",
"Arch Linux", "/etc/arch-release"
);

$distro = "";
if (file_exists("/etc/lsb-release")) {
$lsb = file_get_contents("/etc/lsb-release");
preg_match('!DISTRIB_DESCRIPTION="(.*)"!', $lsb, $distro);
$distro = $distro[1];
} else do {
if (file_exists($distros[1])) {
$distro = file_get_contents($distros[1]);
$distro = "$distros[0] ".preg_replace("/[^0-9]*([0-9.]+)[^0-9.]{0,1}.*/", "\\1", $distro);
break;
}
array_shift($distros); array_shift($distros);
} while (count($distros));

if (!$distro) {
$distro = "Unknown Distro";
}

$operatingsystem = "$distro ($osarray[0] $osarray[2])";

} else {
$operatingsystem = "(N/A)";
}


// Current local server time
$localtime = exec('date');
$timer = 'servertime';




// RAM usage
$meminfo = file_get_contents("/proc/meminfo");
preg_match("!^MemTotal:\s*(.*) kB!m", $meminfo, $memtotal);
$memtotal = $memtotal[1] * 1024;
preg_match("!^MemFree:\s*(.*) kB!m", $meminfo, $memfree);
$memfree = $memfree[1] * 1024;
preg_match("!^Buffers:\s*(.*) kB!m", $meminfo, $buffers);
$buffers = $buffers[1] * 1024;
preg_match("!^Cached:\s*(.*) kB!m", $meminfo, $cached);
$cached = $cached[1] * 1024;

$memused = mksize($memtotal - $memfree - $buffers - $cached);
$memtotal = mksize($memtotal);



// set partition
$fs = "/";
// display available and used space
echo ("<b>Total HDD: </b>" . round(disk_free_space($fs) / (1024*1024*1024)) . " GB\r\n<br />");
// calculate used space
$disk_used_space = round((disk_total_space($fs) - disk_free_space($fs)) / (1024*1024*1024));
echo ("<b>HDD Used: </b>" . $disk_used_space . " GB\r\n<br />");
// calculate % used space
echo ("<b>Percentage: </b>" . round((disk_total_space($fs) - disk_free_space($fs)) / disk_total_space($fs) * 100) . " %<br/><hr/>");


//echo("<b>Current Users:</b> $users[0]<br>
echo("<b>CPU Info: </b> $processor1<br /><hr />");
echo("<b>Local Server Time:</b> $localtime<br /><hr />");

   $dt = new DateTime();
echo ("<b>PHP UTC Time: </b>".gmdate('m-d-Y H:i:s')."<br /><hr />");
   

echo("<b>".T_("CURRENT_LOAD").":</b> $loadnow<br /><b>".T_("LOAD_5_MINS").":</b> $load5<br /><b>".T_("LOAD_15_MINS").":</b> $load15<br /><hr />");

echo("<b>OS:</b> $operatingsystem<br />");
echo("<b>".T_("RAM_USED").":</b> $memused of $memtotal<br />");
echo("<b>".T_("UPTIME").":</b> $up<br />");


}
end_block();
?>



www.exyusubs.com
TorrentTrader V3.8.3 (SE)
OS: AlmaLinux 9.9 (BC)
Apache version: 2.4.71
PHP version: 8.5.13 (PHP-FPM)
MySQL version: 10.11.18-MariaDB
Last edited by Botanicar on 2023-05-21 08:06:40
2023-05-21 14:51:44
seems to work fine on ubuntu. Im not sure why it dont work for you. I used this code as a block.
Screenshot 2023-05-21 104939.png
Screenshot 2023-05-21 104939.png

TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
2023-05-21 15:54:38
It wont work if the OS doesn't support the system calls to pull these stats. It's not uncommon.
2023-05-22 05:46:55

find in php.ini and find disable_funcions make the line like this
disable_functions = system,passthru,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname

reboot apache/server
make sure mod security is off
and upload or get the code from block and put it where you want

P.S. I have made it for System information to show only theDistribution name



serverload_block.php
Download
Last edited by djlive on 2023-05-22 05:49:09
2023-05-23 03:07:22

if (extension_loaded('com_dotnet')) {
   // The com_dotnet extension is loaded
   $wmi = new COM('WinMgmts:\\\\.');
   // Rest of your code here
} else {
   // The com_dotnet extension is not loaded or supported
   // Handle the situation accordingly
   echo "The com_dotnet extension is not available.";
}
2023-05-23 18:52:23
Thanks everyone problem solved but it doesn't show os  ex. debian 11 x86_x64 etc. the rest is fine

*******DjLive  thanks for the code******

Here was the problem
$server_check_version = '1.0.4';
$start_time = microtime(TRUE);

$operating_system = PHP_OS_FAMILY;

if ($operating_system === 'Windows') {
// Win CPU
$wmi = new COM('WinMgmts:\\\\.');
$cpus = $wmi->InstancesOf('Win32_Processor');
$cpuload = 0;
$cpu_count = 0;
foreach ($cpus as $key => $cpu) {
$cpuload += $cpu->LoadPercentage;
$cpu_count++;
}
// WIN MEM
$res = $wmi->ExecQuery('SELECT FreePhysicalMemory,FreeVirtualMemory,TotalSwapSpaceSize,TotalVirtualMemorySize,TotalVisibleMemorySize FROM Win32_OperatingSystem');
$mem = $res->ItemIndex(0);
$memtotal = round($mem->TotalVisibleMemorySize / 1000000,2);
$memavailable = round($mem->FreePhysicalMemory / 1000000,2);
$memused = round($memtotal-$memavailable,2);
// WIN CONNECTIONS
$connections = shell_exec('netstat -nt | findstr :80 | findstr ESTABLISHED | find /C /V ""');
$totalconnections = shell_exec('netstat -nt | findstr :80 | find /C /V ""');
} else {
// Linux CPU
$load = sys_getloadavg();
$cpuload = $load[0];
// Linux MEM
      // RAM usage
      $start_time = microtime(TRUE);

$free = shell_exec('free');
$free = (string)trim($free);
$free_arr = explode("\n", $free);
$mem = explode(" ", $free_arr[1]);
$mem = array_filter($mem, function($value) { return ($value !== null && $value !== false && $value !== ''); }); // removes nulls from array
$mem = array_merge($mem); // puts arrays back to [0],[1],[2] after filter removes nulls

//print_r($mem); echo '<hr>';
$memtotal = round($mem[1] / 1000000,2);
$memused = round($mem[2] / 1000000,2);
$memfree = round($mem[3] / 1000000,2);

$membuffer = round($mem[5] / 1000000,2);
$memcached = round($mem[6] / 1000000,2);

$memusage = round(($memused - $memcached - $membuffer)/$memtotal*100,2);

$connections = `netstat -ntu | grep :80 | grep ESTABLISHED | grep -v LISTEN | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | grep -v 127.0.0.1 | wc -l`;
$totalconnections = `netstat -ntu | grep :80 | grep -v LISTEN | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | grep -v 127.0.0.1 | wc -l`;

$load = sys_getloadavg();
$cpuload = $load[0];

$diskfree = round(disk_free_space(".") / 1000000000);
$disktotal = round(disk_total_space(".") / 1000000000);
$diskused = round($disktotal - $diskfree);

$diskusage = round($diskused/$disktotal*100);

if ($memusage > 85 || $cpuload > 2 || $diskusage > 95) {
$trafficlight = 'red';
} elseif ($memusage > 70 || $cpuload > 1 || $diskusage > 85) {
$trafficlight = 'orange';
} else {
$trafficlight = '#2F2';
}

$end_time = microtime(TRUE);
$time_taken = $end_time - $start_time;
$total_time = round($time_taken,4);
// Linux Connections
}

$memusage = round(($memused/$memtotal)*100);



$phpload = round(memory_get_usage() / 1000000,2);

$diskfree = round(disk_free_space(".") / 1000000000);
$disktotal = round(disk_total_space(".") / 1000000000);
$diskused = round($disktotal - $diskfree);

$diskusage = round($diskused/$disktotal*100);

if ($memusage > 85 || $cpuload > 85 || $diskusage > 85) {
$trafficlight = 'red';
} elseif ($memusage > 50 || $cpuload > 50 || $diskusage > 50) {
$trafficlight = 'orange';
} else {
$trafficlight = '#2F2';
}

$end_time = microtime(TRUE);
$time_taken = $end_time - $start_time;
$total_time = round($time_taken,4);



$uptime = shell_exec("cut -d. -f1 /proc/uptime");
$days = floor($uptime/60/60/24);
$hours = $uptime/60/60%24;
$mins = $uptime/60%60;
$secs = $uptime%60;
   $time = $days."days:".$hours."hours:".$mins."minutes";

// Operating system
exec('lsb_release -a', $output);
$line = array_search('Description:', $output);
$distribution = trim(substr($output[$line], strpos($output[$line], ':') + 1));



php load why it is so big how can I make it smaller??

os1---.png
os1---.png
2023-05-28 17:47:15
You should do this in a viewport or else your smaller font size will be chicken scratch on a iPhone for example.

Once you have a viewport assigned in your .css file, you can set sizes based on the clients resolution.

This steps up suitable rendering that is both compatible and normalized.
2023-06-04 22:06:14
it's too big PHP Load: 1.68 GB,  how can I solve it?
thanks
server-php.png
server-php.png
Last edited by crisphp on 2023-06-04 22:10:32
2023-06-05 21:59:37
there can be many reasons for that, no way to pinpoint specifically. That amount isnt high, but it seems you only have 4GB total. If you have a dual channel board, installing more RAM to atleast 16GB would be best
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
2023-06-07 21:29:32
ok  MicroMonkey thanks for the reply
2023-06-16 05:21:45
same problem ,,, i just updated some torrents and server cpu is HIGH

1.2Gb database torrents.sql

what can be the solution ... is reading in 60sec the torrents table !

Last edited by Extremlym66 on 2023-06-16 05:31:39
2023-06-24 17:03:04
Monitor the usage clicking different links with the comment on your console / SSH

top -P

that should work any Linux/BSD system. Monitor the database server usage % and memory usage, but this really depends on your traffic too.

Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 4
  • Members: 0
  • Guests online: 4
  • Comments: 3
  • Messages: 1,728