Simple server stats

ReDuX ReDuX is offline Offline Oct 12th, 2004, 10:54 pm |
0
This is a very simple statistics script that provides for services on/offline, memory info, server load averages and uptime and lastly drive info.
Its easily customised and i have usef <font> alot where you could have set come css and have it all done easily and look a bit more tidy than mine.
Quick reply to this message  
PHP Syntax
  1. <?
  2. // Set the services you want the script to check.
  3. // You can add more by just adding a line "servers name"=>"host/IP:port number",
  4. // You can use game servers or anything.
  5. // e.g. "IRCdaemon"=>"localhost:6667",
  6. $services = array(
  7. "http"=>"localhost:80",
  8. "ssh"=>"localhost:22",
  9. // "telnet"=>"localhost:23",
  10. "ftp"=>"localhost:21",
  11. // "smtp"=>"localhost:25",
  12. "pop3"=>"localhost:110",
  13. "mysql"=>"localhost:3306"
  14. );
  15.  
  16. // Variables at the top of the page, date, uptime etc.
  17. $date = date("l, M d, Y - h:i:s A");
  18. $version = `uname -sr`;
  19. $name = `hostname`;
  20. $uptime = `uptime`;
  21.  
  22. // df command function, formatted into a table
  23. function output_df()
  24. {
  25. $disk = `df`;
  26. $lines = split("\n", $disk);
  27. echo "<table border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">";
  28. for ($i = 0; $i < sizeof($lines) && strlen($lines[$i]) > 1; $i++)
  29. {
  30. $cols = preg_split("/[\s]+/", $lines[$i]);
  31. if ($i == 0)
  32. echo "<tr bgcolor=\"black\"><font color=orange>";
  33. else
  34. echo "<tr>";
  35. for ($j = 0; $j < 6; $j++)
  36. {
  37. if ($j == 0 || $j == 5)
  38. $align = "left";
  39. else if ($j == 1 || $j == 2 || $j == 3)
  40. $align = "right";
  41. else if ($j == 4)
  42. $align = "center";
  43.  
  44. echo "<td align=$align>&nbsp;<font face=\"Verdana\" size=\"1\" color=\"orange\">$cols[$j]</font>&nbsp;</td>";
  45. }
  46. echo "</font></tr>";
  47. }
  48. echo "</table>";
  49. }
  50.  
  51. // free comand function, formatted into a table
  52. function output_free()
  53. {
  54. $free = `free`;
  55. $lines = split("\n", $free);
  56. echo "<table border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">";
  57. for ($i = 0; $i < sizeof($lines) && strlen($lines[$i]) > 1; $i++)
  58. {
  59. if ($i == 2) $i++;
  60. $cols = preg_split("/[\s]+/", $lines[$i]);
  61. if ($i == 0)
  62. echo "<tr bgcolor=\"black\">";
  63. else
  64. echo "<tr>";
  65. foreach ($cols as $data)
  66. echo "<td align=right>&nbsp;<font face=\"Verdana\" size=\"1\" color=\"orange\">$data</font>&nbsp;</td>";
  67. echo "</tr>";
  68. }
  69. echo "</table>";
  70. }
  71.  
  72. // info grabbind done, onto the html
  73. ?>
  74. <table border="0" align="center" cellpadding="1" cellspacing="0">
  75. <tr><td>
  76. <p><font face="Verdana" size="1"><b>System Status:</b> <? echo $name ?><br><b>Time:</b> <? echo $date ?></font></p>
  77. <font face="Verdana" size="1">
  78. <? echo $version ?><br>
  79. <? echo $uptime ?>
  80. <p><table>
  81. <b>Services:</b><br>
  82. <tr bgcolor="black"><td><font face="Verdana" size="1" color="orange">Status</font></td><td><font face="Verdana" size="1" color="orange">Service</font></td><td><font face="Verdana" size="1" color="orange">Host</font></td></tr>
  83. <?
  84. foreach ($services as $name=>$location)
  85. {
  86. list($host, $port) = split(":",$location);
  87. $running = fsockopen($host, $port, $errno, $errstr, 30);
  88. if (!$running)
  89. $status_color = "red";
  90. else
  91. {
  92. fclose($running);
  93. $status_color = "green";
  94. }
  95. echo "<tr><td align=center><div align=\"center\" style=\"font-size: 13pt; color: $status_color\" width=\"15\" height=\"15\"><b>?</b></div></td><td><font face=\"Verdana\" size=\"1\">$name</font></td><td><font face=\"Verdana\" size=\"1\">$host</font></td></tr>";
  96. }
  97. ?>
  98. </table></p>
  99. <b>Memory:</b><br>
  100. <? output_free(); ?><br>
  101. <b>Drive Info:</b><br>
  102. <? output_df(); ?>
  103. </font>
  104. </td></tr></table>
0
inflictor inflictor is offline Offline | Feb 8th, 2005
kewl

very interesting
 
0
Kase Kase is offline Offline | May 19th, 2005
Nice job.
 
 

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC