PDA

View Full Version : [fixed] load averages broken on OpenBSD (patch included)


jamesez
Fri 16th Nov '01, 11:44pm
Hi!

On OpenBSD, `uptime` says "load averages:" not "load average:"

This patch will fix the problem, and it's compatible with either version of the `uptime` command:

diff -u admin/index.php-old admin/index.php
--- admin/index.php-old Fri Nov 16 22:38:24 2001
+++ admin/index.php Fri Nov 16 22:30:50 2001
@@ -123,7 +123,7 @@

$onlineusers = number_format($guests + $members) . " users online ($members members & $guests guests).";

- preg_match("/average: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$stats,$regs);
+ preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$stats,$regs);
echo "<tr class=\"secondalt\"><td>Server Load Averages</td><td><b>$regs[1], $regs[2], $regs[3]</b> $onlineusers</td></tr>\n";
}
?>

--Jim

Ed's note:
Find the line in blue (note that it doesn't include the "-" or "+"), and add what's in red to it.

Mike Sullivan
Sun 18th Nov '01, 11:54am
Fixed.

To anyone that needs this fix -- if you're not familiar with diff syntax, I'm highlighting Jim's post to make it more obvious what to change.

jamesez
Sun 18th Nov '01, 12:14pm
I forgot to include the diff for mod/index.php, but it's the same regex change ("s?").

At some point I'll look into making /proc/averages portable, but it's not critical for me, so, not just yet. :-)

--Jim

Marco
Sun 18th Nov '01, 1:13pm
How come I don't see Load Averages in my CP? Because of Safe Mode?

jamesez
Sun 18th Nov '01, 2:42pm
Originally posted by Marco
How come I don't see Load Averages in my CP? Because of Safe Mode?

Looking at the code for 2.2.1 it doesn't look like it checks safe mode settings.

Are you seeing "Server Load Averages: , , " or nothing at all?

If you're seeing three commas, then try the fix I just posted.

If you're not seeing the line at all, at a shell prompt try `uptime` and see what it says.

--Jim

JTMON
Sun 18th Nov '01, 3:02pm
I don't see anything at all. I'm on a shared Unix account but without shell access.

jamesez
Sun 18th Nov '01, 3:09pm
My guess is that you can't run `uptime`, probably because you don't have a shell set in your server's password file.

The code currently uses the output of `uptime` to display the load, and displays nothing if running `uptime` fails.

It could be switched to looking at /proc/averages, but that's a Linux-ism and doesn't port to (say) Solaris.