ram.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. if ($os == "windows") {
  25. error_reporting(E_ALL);
  26. if (extension_loaded('com_dotnet'))
  27. {
  28. $wmiq = new COM("Winmgmts://");
  29. $ossq = $wmiq->execquery("SELECT * FROM Win32_OperatingSystem");
  30. foreach ($ossq as $osq) {
  31. $total = $osq->TotalVisibleMemorySize * 1024;
  32. $free = $osq->FreePhysicalMemory * 1024;
  33. }
  34. $belegtq = $total - $free;
  35. $percentage_used = 100 * $belegtq / $total;
  36. $ramusage = numbersFormatting($belegtq) . " ".get_lang('ram_of')." " . numbersFormatting($total);
  37. $rampercent = round($percentage_used, "2");
  38. }
  39. else
  40. $modulememory = "0";
  41. }
  42. elseif ($os == "linux" or $os == "cygwin") {
  43. if( isset($_GET['remote_server_id']) )
  44. {
  45. require_once('includes/lib_remote.php');
  46. global $db;
  47. $rhost_id = $_GET['remote_server_id'];
  48. $remote_server = $db->getRemoteServer($rhost_id);
  49. $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key'], $remote_server['timeout']);
  50. $ramstatus = $remote->shell_action('get_ram_usage' , 'status');
  51. $ramusage = numbersFormatting($ramstatus['used']) . " ".get_lang('ram_of')." " . numbersFormatting($ramstatus['total']);
  52. $rampercent = $ramstatus['percent'];
  53. }
  54. else
  55. {
  56. if( ini_get('open_basedir') )
  57. {
  58. $dirs = preg_split( "/:|;/", ini_get('open_basedir') , -1, PREG_SPLIT_NO_EMPTY );
  59. if( !in_array('/proc', $dirs) )
  60. $modulememory = "0";
  61. else
  62. $mem = file_get_contents("/proc/meminfo");
  63. }
  64. else
  65. $mem = file_get_contents("/proc/meminfo");
  66. if( isset($mem) )
  67. {
  68. if (preg_match('/MemTotal\:\s+(\d+) kB/', $mem, $matches))
  69. {
  70. $total = $matches[1];
  71. }
  72. if (preg_match('/Buffers\:\s+(\d+) kB/', $mem, $matches))
  73. {
  74. $buffers = $matches[1];
  75. }
  76. if (preg_match('/Cached\:\s+(\d+) kB/', $mem, $matches))
  77. {
  78. $cached = $matches[1];
  79. }
  80. unset($matches);
  81. if (preg_match('/MemFree\:\s+(\d+) kB/', $mem, $matches))
  82. {
  83. $free = $matches[1];
  84. }
  85. $Used = $total - $free - @$cached - @$buffers; // Added at(@) to avoid errors on some virtual machines that are not using pagefile or using the host OS pagefile.
  86. $percentage_used = 100 * $Used / $total;
  87. $ramusage = numbersFormatting($Used*1024) . " ".get_lang('ram_of')." " . numbersFormatting($total*1024);
  88. $rampercent = round($percentage_used, "2");
  89. }
  90. }
  91. }
  92. else
  93. {
  94. $ramusage = "Unable to Detect";
  95. $rampercent = "100";
  96. }
  97. ?>