Feature Req: load averages (with code)

Discuss the technical details of Gargoyle and ongoing development

Moderator: Moderators

Post Reply
distemper
Posts: 4
Joined: Wed Jul 29, 2009 9:05 am

Feature Req: load averages (with code)

Post by distemper »

I tried to add load averages to overview.sh & compile & test it, but running full-build-809.sh had a problem:
Checking 'case-sensitive-fs'... failed.
Build dependency: OpenWrt can only be built on a case-sensitive filesystem

So I'll need to juggle things around.

Its simple enough:

--- overview_new.sh 2009-07-29 22:30:11.000000000 -0400
+++ overview.sh 2009-08-02 11:23:12.000000000 -0400
@@ -33,6 +33,8 @@
echo "var totalMemory=$total_mem;"
echo "var freeMemory=$free_mem;"

+ load_avg=$(cat loadavg | awk '{print $1, $2, $3}')
+

?>
//-->
@@ -54,6 +56,9 @@
<div>
<span class='leftcolumn'>Memory Usage:</span><span id="memory" class='rightcolumn'></span>
</div>
+ <div>
+ <span class='leftcolumn'>Load Averages:</span><span id="load_avg" class='rightcolumn'></span>
+ </div>
<div class="internal_divider"></div>
</div>


---------------
If this isn't how you want code submissions, maybe a FAQs entry would be instructive.

Eric
Site Admin
Posts: 1443
Joined: Sat Jun 14, 2008 1:14 pm

Re: Feature Req: load averages (with code)

Post by Eric »

Congratulations! You're the first person to submit code that has made it into Gargoyle!

That said... you you clearly didn't test your patch. It needed some rather significant modification before it would work. Even though you couldn't rebuild the full system you can scp files to the router /www or /www/js directory (e.g. scp overview.sh root@192.168.1.1:/www), to test out your modifications.


The big problems were:

(1) "cat loadavg" should be "cat /proc/loadavg". You need to specify the right file...

(2) You need to either embed the haserl variable you defined directly into the page or set it using javascript. You just defined the variable but didn't do anything with it, so it never shows up, even if you fix (1) and get the right value.

I also made a few very minor cosmetic changes.

So, on the one hand I'm overjoyed to be getting code submissions... but on the other hand I'd really prefer if you test your work before submitting it.

In terms of format... I'll take code however I find it, but if you do post on the forum i'd prefer if you enclose the patch in "code" tags so that the whitespace formatting isn't lost, which screws up the patch if I try to apply it directly.


Here's what the patch applied in svn r532 (yep, it's in there!) looks like:

Code: Select all

--- files/www/js/overview.js	(revision 531)
+++ files/www/js/overview.js	(working copy)
@@ -45,6 +45,7 @@
 	setChildText("device_name", uciOriginal.get("system", systemSections[0], "hostname" ));
 	setChildText("gargoyle_version", gargoyleVersion);
 	setChildText("memory", "" + ramUsed + "MB / " + ramMemory + "MB (" + percentRamUsed + "%)" );
+	setChildText("load_avg", loadAvg );
 
 	setChildText("uptime", uptimeDays + " days, " + uptimeHours + " hours, " + uptimeMinutes + " minutes");
 	setChildText("current_time", currentTime);
Index: files/www/overview.sh
===================================================================
--- files/www/overview.sh	(revision 531)
+++ files/www/overview.sh	(working copy)
@@ -33,7 +33,10 @@
 	echo "var totalMemory=$total_mem;"
 	echo "var freeMemory=$free_mem;"
 
+	load_avg=$(cat /proc/loadavg | awk '{print $1 " / " $2 " / " $3}')
+	echo "var loadAvg=\"$load_avg\";"
 
+
 ?>
 //-->
 </script>
@@ -54,6 +57,9 @@
 		<div>
 			<span class='leftcolumn'>Memory Usage:</span><span id="memory" class='rightcolumn'></span>
 		</div>
+ 		<div>
+ 			<span class='leftcolumn'>CPU Load Averages:</span><span id="load_avg" class='rightcolumn'></span><span>&nbsp;&nbsp;(1/5/15 minutes)
+ 		</div>
 		<div class="internal_divider"></div>
 	</div>

distemper
Posts: 4
Joined: Wed Jul 29, 2009 9:05 am

Re: Feature Req: load averages (with code)

Post by distemper »

Eric wrote: "cat loadavg" should be "cat /proc/loadavg". You need to specify the right file...
That does seem painfully obvious now.
Eric wrote: You need to either embed the haserl variable you defined directly into the page or set it using javascript. You just defined the variable but didn't do anything with it, so it never shows up, even if you fix (1) and get the right value.
As I've never coded a webpage, I will keep that in mind.
Eric wrote:...on the other hand I'd really prefer if you test your work before submitting it.
And onto the next problem - both atheros (which I don't have) and broadcom (which I do) don't build, so that is not something I can yet do. Please note that this is on a case-sensitive partition under Mac OS X 10.5.7.

•••• atheros build error:

Code: Select all

chmod 644 /Volumes/CS/trunk/atheros-2.6-src/build_dir/mips/libericstools/ipkg/libericstools/CONTROL/control
(cd /Volumes/CS/trunk/atheros-2.6-src/build_dir/mips/libericstools/ipkg/libericstools/CONTROL; var2file "V_Package_libericstools_conffiles" conffiles; var2file "V_Package_libericstools_preinst" preinst; var2file "V_Package_libericstools_postinst" postinst; var2file "V_Package_libericstools_prerm" prerm; var2file "V_Package_libericstools_postrm" postrm; )

cp -fpR /Volumes/CS/trunk/atheros-2.6-src/build_dir/mips/libericstools/*.so* /Volumes/CS/trunk/atheros-2.6-src/build_dir/mips/libericstools/ipkg/libericstools/usr/lib/
cp: cannot stat `/Volumes/CS/trunk/atheros-2.6-src/build_dir/mips/libericstools/*.so*': No such file or directory
make[3]: *** [/Volumes/CS/trunk/atheros-2.6-src/bin/packages/mips/libericstools_1.0-1_mips.ipk] Error 1
make[2]: *** [package/libericstools/compile] Error 2
make[1]: *** [/Volumes/CS/trunk/atheros-2.6-src/staging_dir/mips/stamp/.package_compile] Error 2
make: *** [world] Error 2


I looked through the libericstools makefile, and I assume cp gets somehow substituted for CP:=cp -fpR from trunk/rules.mk. There are 2 lines in install:

cp *.h ~/usr/include
cp *.$(SHLIB_EXT)* ~/usr/lib

Why the first 2nd line ran & not the first is unknown. And when the makefile compiled the library, it got it right (libericstools.dylib symlink to libericstools.dylib.1).

In short, I have no idea what to follow to see if I can alter the behavior.
--------------------------------
••••• broadcom build error:

Code: Select all

make -C ipv4/netfilter fastdep
make[9]: *** No rule to make target `fastdep'.  Stop.
make[8]: *** [_sfdep_ipv4/netfilter] Error 2
make[7]: *** [fastdep] Error 2
make[6]: *** [_sfdep_net] Error 2
make[5]: *** [dep-files] Error 2
make[4]: *** [/Volumes/CS/trunk/brcm-2.4-src/build_dir/linux-brcm-2.4/linux-2.4.35.4/.configured] Error 2
make[3]: *** [compile] Error 2
make[2]: *** [target/linux/compile] Error 2
make[1]: *** [/Volumes/CS/trunk/brcm-2.4-src/staging_dir/mipsel/stamp/.target_compile] Error 2
I think this error is because brcm-2.4-src/build_dir/linux-brcm-2.4/linux-2.4.35.4/net/ipv4/netfilter/Makefile is missing:

include $(TOPDIR)/Rules.make

Until I get my footings with the (incredibly complex) build system, I can't test anything Gargoyle related.

Eric
Site Admin
Posts: 1443
Joined: Sat Jun 14, 2008 1:14 pm

Re: Feature Req: load averages (with code)

Post by Eric »

OS X really isn't well-suited to building OpenWRT/Gargoyle. The problems you're seeing are the result of this.

For example the error about libericstools is complaining that it can't find the *.so files. Well, I suspect that since it's on a mac it decided to build .dylib files, which are the dynamic libraries on MAC instead of .so files on linux. You should really be building on a Linux system. (I use Ubuntu. I have a mac laptop, and Ubuntu has versions that work fine on it. For dual booting check out rEFIt.)

However, for testing modifications to the web interface like the patch you uploaded this is not necessary. All you have to do is edit the gargoyle files locally and upload them to the router via scp -- if you're editing haserl script/javascript you don't need to compile it. You can just download the pre-built images from the download section, install them, and then once they're running copy files to them. Not only is it simpler, it's less time consuming as well.

Post Reply