PDA

View Full Version : Need some simple PHP help please



awelsh
28-02-2009, 12:34 PM
Well ive got this script for displaying server status, however I need the info to a line down not one after another.

Heres the script:


<?php
# status.php -- very simple server status monitor
# Get and display load average times 3
$load = sys_getloadavg();
echo "Load Average: $load[0]\n";
echo "Load Average2: $load[1]\n";
echo "Load Average3: $load[2]\n";

# Get and display disk usage percentages
$df = `/bin/df`;
foreach( split( "\n", $df ) as $line )
{
if( preg_match( "/(\d+%)\s+(\S+)$/", $line, $matches ) )
{
$fs = $matches[ 2 ];
$usage = $matches[ 1 ];
echo "Disk Usage_$fs: $usage\n";
}
}
# Count running processes
$procs = `/bin/ps -e|wc -l`;
echo "Running Processes: $procs\n";
?>

I need it so the

echo "Load Average: $load[0]\n";
echo "Load Average2: $load[1]\n";
echo "Load Average3: $load[2]\n";

Show below eachother like

Load Average: 10.34
Load Average2: 13.51
Load Average3: 15.78

Not like below as thats what it comes up as now. Same for the disk useage too. This cant be hard can it? I think im just missing something very simple :)

Load Average: 10.34 Load Average2: 13.51 Load Average3: 15.78


Thread moved from 'Designing & Development' by Yoshimitsui (Forum Super Moderator): Please post in the correct sub-section.

Blinger1
28-02-2009, 12:35 PM
could you not do something like this?

<?php
# status.php -- very simple server status monitor
# Get and display load average times 3
$load = sys_getloadavg();
echo "Load Average: $load[0]\n";
echo "Load Average2: $load[1]\n";
echo "Load Average3: $load[2]\n";

# Get and display disk usage percentages
$df = `/bin/df`;
foreach( split( "\n", $df ) as $line )
{
if( preg_match( "/(\d+%)\s+(\S+)$/", $line, $matches ) )
{
$fs = $matches[ 2 ];
$usage = $matches[ 1 ];
echo "Disk Usage_$fs: $usage\n";
}
}
# Count running processes
$procs = `/bin/ps -e|wc -l`;
echo "Running Processes: $procs<br>";
?>

awelsh
28-02-2009, 12:38 PM
EDIT: nevermind, fixed ti :D thanks

Sameer!
28-02-2009, 01:03 PM
I was just to reply on how to fix it lol. Good job!

Want to hide these adverts? Register an account for free!