bkruse: trunk r620 - in /trunk: ./ config/ config/graphs/ config/scripts/ scr...

asterisk-gui-commits at lists.digium.com asterisk-gui-commits at lists.digium.com
Fri Apr 6 14:48:50 MST 2007


Author: bkruse
Date: Fri Apr  6 16:48:49 2007
New Revision: 620

URL: http://svn.digium.com/view/asterisk-gui?view=rev&rev=620
Log:
Wow, The gui can graph CPU usage, just a proof of concept.....I will do more with this later (600 lines :X)

Added:
    trunk/config/graphs/
    trunk/config/graphs.html
    trunk/config/graphs/graph_cpu.svg
    trunk/scripts/graphs.sh   (with props)
Modified:
    trunk/Makefile
    trunk/config/cfgbasic.html
    trunk/config/scripts/tooltip.js

Modified: trunk/Makefile
URL: http://svn.digium.com/view/asterisk-gui/trunk/Makefile?view=diff&rev=620&r1=619&r2=620
==============================================================================
--- trunk/Makefile (original)
+++ trunk/Makefile Fri Apr  6 16:48:49 2007
@@ -208,6 +208,7 @@
 	mkdir -p $(CONFIGDIR)/stylesheets
 	mkdir -p $(CONFIGDIR)/bkps
 	mkdir -p $(CONFIGDIR)/setup
+	mkdir -p $(CONFIGDIR)/graphs
 	mkdir -p $(ASTETCDIR)/scripts
 	@for x in gui_configs/*; do \
 		echo "$$x  -->  $(ASTETCDIR)" ; \
@@ -236,6 +237,10 @@
 	@for x in config/*.html; do \
 		echo "$$x  -->  $(CONFIGDIR)" ; \
 		$(INSTALL) -m 644 $$x $(CONFIGDIR)/ ; \
+	done
+	@for x in config/graphs/*; do \
+		echo "$$x  -->  $(CONFIGDIR)/graphs" ; \
+		$(INSTALL) -m 644 $$x $(CONFIGDIR)/graphs ; \
 	done
 	@if [ -x /usr/sbin/asterisk-gui-post-install ]; then \
 		/usr/sbin/asterisk-gui-post-install $(DESTDIR) . ; \

Modified: trunk/config/cfgbasic.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/cfgbasic.html?view=diff&rev=620&r1=619&r2=620
==============================================================================
--- trunk/config/cfgbasic.html (original)
+++ trunk/config/cfgbasic.html Fri Apr  6 16:48:49 2007
@@ -89,6 +89,8 @@
 		"Allows you to record custom voicemenus over a phone"),
 	
 	new PanelDef("status", "Active Channels", "accordion-icon.gif", "Monitor active channels."),
+
+	new PanelDef("graphs", "Graphs", "accordion-icon.gif", "View Graphs of your System Information."),
 
 	new PanelDef("sysinfo", "System Info", "accordion-icon.gif", "System Information."),
 
@@ -295,4 +297,4 @@
 		</td>
 </tr>
 </table>
-</body>
+</body>

Added: trunk/config/graphs.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/graphs.html?view=auto&rev=620
==============================================================================
--- trunk/config/graphs.html (added)
+++ trunk/config/graphs.html Fri Apr  6 16:48:49 2007
@@ -1,0 +1,160 @@
+<!--
+ * Asterisk-GUI	-	an Asterisk configuration interface
+ *
+ * SVG Graphing Capability For the Asterisk Gui.
+ *
+ * Copyright (C) 2006-2007, Digium, Inc.
+ *
+ * Brandon Kruse <bkruse at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ *
+-->
+<script src="scripts/prototype.js"></script>
+<script src="scripts/rico.js"></script>
+<script src="scripts/astman.js"></script>
+<script src="scripts/tooltip.js"></script>
+<link href="stylesheets/rico.css" media="all" rel="Stylesheet" type="text/css" />
+<link href="stylesheets/schwing.css" media="all" rel="Stylesheet" type="text/css" />
+
+<script>
+
+/* I am planning to add tons of graphs besides just CPU, this is more or less a Proof of Concept */
+var tabs = new Array('tab1'); 
+var divs_tohide = new Array('cpu_div');
+
+function update_graph(graph) {
+	var tmp_command = "sh /etc/asterisk/scripts/graphs.sh cpu > /var/lib/asterisk/static-http/config/graphs/data_cpu.html";
+	parent.astmanEngine.run_tool(tmp_command);
+	return true;
+	}
+
+function load_graphs() {
+	var _sm = _$('status_message').style ;
+	_sm.display = "" ;	
+	
+	var opt = {
+		method: 'get',
+		asynchronous: true,
+		onComplete: function(originalRequest){
+			_sm.display = 'none' ;
+			_$('todaylog').innerHTML = (originalRequest.responseText) ? "<PRE>"+originalRequest.responseText.escapeHTML() +"</PRE>" : "No log messages found on this Day" ;
+			
+		},
+		onFailure: function(t) {
+			_sm.display = 'none' ;
+			gui_alert("Config Error: " + t.status + ": " + t.statusText);
+		}
+	};
+	opt.parameters="";
+	var tmp = new Ajax.Request("graphs/cpu_data", opt);
+	return true;
+}
+
+function show_window(x){
+	for(i=0; i < tabs.length ; i++){
+		document.getElementById(tabs[i]).className = "tab";
+	}
+
+	document.getElementById(tabs[x-1]).className = "tabselected";
+	document.getElementById(tabs[x-1]).blur();
+
+	clearInterval(interval_handler); /*stop our other real-time refreshers... */
+
+	switch(x){
+		case 1:
+		var divs_toshow = new Array('cpu_div');
+		var interval_handler = setInterval("update_graph()",5000);
+		break;
+	}
+	for(var i=0; i < divs_tohide.length; i++ )
+		_$(divs_tohide[i]).style.display = "none";
+	for(var i=0; i < divs_toshow.length; i++ )
+		_$(divs_toshow[i]).style.display = "";
+
+	return true;
+}
+
+function getsysinfohtml(){
+	var opt = {
+		method: 'get',
+		asynchronous: true,
+		onComplete: function(originalRequest){
+			_$('sysinfohtml').innerHTML = originalRequest.responseText;
+			_$('osversion').innerHTML = _$('si_uname').innerHTML;
+			_$('uptime').innerHTML = _$('si_uptime').innerHTML;
+			_$('asterisk').innerHTML =_$('si_astver').innerHTML + "<BR>" + "Asterisk GUI-version " + asterisk_guiversion.substr(1) ;
+			_$('today').innerHTML = _$('si_date').innerHTML;
+			_$('hostname').innerHTML =_$('si_hostname').innerHTML;
+			_$('ifconfig').innerHTML =_$('si_ifconfig').innerHTML;
+			_$('diskusage').innerHTML = _$('si_du').innerHTML;
+			_$('memoryusage').innerHTML =_$('si_free').innerHTML;
+
+			var divs_toshow = new Array('osversion_div', 'uptime_div', 'asterisk_div', 'today_div','hostname_div');
+			for(var i=0; i < divs_toshow.length; i++ ){ _$(divs_toshow[i]).style.display = ""; }
+
+			document.getElementById(tabs[0]).className = "tabselected";
+			load_todayslog();
+		},
+		onFailure: function(t) {
+			_$('status_message').style.display='none';
+			gui_alert("Config Error: " + t.status + ": " + t.statusText);
+		}
+	};
+	opt.parameters="";
+	var tmp = new Ajax.Request("./bkps/sysinfo_output.html", opt);
+	return true;
+}
+
+
+function localajaxinit(){
+	setWindowTitle("Resource and Monitoring Graphs");
+	var date = new Date() ; 
+	parent.loadscreen(this);
+	show_window(1);
+}
+
+function free_mem(){
+	if( navigator.userAgent.indexOf("MSIE") == -1 ){ return true; }
+	try{
+		purge( document.body );
+	} catch(e){ }
+}
+
+</script>
+<body id="foo" onload="localajaxinit()" bgcolor="EFEFEF"  onunload="free_mem()">
+<div class="mainscreenTitleBar">
+	<span style="margin-left: 4px;font-weight:bold;">Graphs: </span>
+	<span style="cursor: pointer; cursor: hand;" onclick="window.location.href=window.location.href;" >&nbsp;<img src="images/refresh.png" title=" Refresh " border=0 >&nbsp;</span>
+</div>
+<div class="mainscreenContentBox" id="userscontent">
+<table class="mainscreenTable" align="center">
+	<tr valign="top" height="18">	
+			<td align="left">
+
+				<a href="#" class="tab" onclick="return show_window(1);" id="tab1"  onmouseover="show_tooltip('en', 'graph', 0);">CPU</a>&nbsp;&nbsp;
+				<div id="graphshtml" style="display:none"></div>
+
+				<div id="information" style=" border: solid 0px black; background: transparent; padding: 4px; height:440px; width:95%;">
+						<BR>
+						<div id="cpu_div" style="display:none">
+								<div id="cpu" style="font-family:courier; font-size:10pt;"></div><BR>
+								<embed id="cpu_embed" type="image/svg+xml" src="graphs/graph_cpu.svg?graphs/data_wan.html"
+									width="500" height="250" /> 
+						</div>
+				</div>
+			</td>
+	</tr>
+	<tr><td valign="top" align=center><div  id='status'></div></td></tr>
+	<tr><td></td></tr>
+</table>
+</div>
+</body>

Added: trunk/config/graphs/graph_cpu.svg
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/graphs/graph_cpu.svg?view=auto&rev=620
==============================================================================
--- trunk/config/graphs/graph_cpu.svg (added)
+++ trunk/config/graphs/graph_cpu.svg Fri Apr  6 16:48:49 2007
@@ -1,0 +1,197 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!--
+Additional Features/Tweaking for the asterisk GUI by Brandon Kruse <bkruse at digium.com>
+
+Original Credits and Copyrights:
+
+Copyright (C) 2004-2005 T. Lechat <dev at lechat.org>, Manuel Kasper <mk at neon1.net>
+and Jonathan Watt <jwatt at jwatt.org>.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+	this list of conditions and the following disclaimer.
+
+2. Redistributionss in binary form must reproduce the above copyright
+	notice, this list of conditions and the following disclaimer in the
+	documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+-->
+<svg xml:space='preserve' xmlns='http://www.w3.org/2000/svg' 
+	xmlns:xlink='http://www.w3.org/1999/xlink'
+	width='100%' height='100%' 
+	viewBox='0 0 600 300'
+	preserveAspectRatio='none'
+	onload='init(evt)'
+>
+<g id='graph'>
+	<rect id='bg' x1='0' y1='0' width='600' height='300' fill='white' />
+
+	<text id='graph_lbl'  x='50' y='15' fill='#435370' text-anchor='end'>CPU</text>
+	<text id='graph_txt'  x='54' y='15' fill='#435370'>--</text>
+
+	<text id='error' x='300' y='125' text-anchor='middle' visibility='hidden' fill='blue'>Cannot get data about interface</text>
+	<text id='collect_initial' x='300' y='125' text-anchor='middle' visibility='hidden' fill='gray'>Collecting initial data, please wait...</text>
+
+	<path id='grid' d='M 2 75 L 600 75 M 2 150 L 600 150 M 2 225 L 600 225' stroke='gray' stroke-opacity='0.5' />
+	<text id='grid_txt3' x='600' y='223' fill='gray' text-anchor='end'>25%</text>
+	<text id='grid_txt2' x='600' y='148' fill='gray' text-anchor='end'>50%</text>
+	<text id='grid_txt1' x='600' y='73' fill='gray' text-anchor='end'>75%</text>
+
+	<path id='graph_cpu'  d='' fill='none' stroke='#435370' stroke-width='2' stroke-opacity='0.8' />
+
+	<line id='axis_x' x1='1' y1='299' x2='600' y2='299' stroke='black' />
+	<line id='axis_y' x1='1' y1='299.5' x2='1' y2='0' stroke='black' />
+</g>
+<script type="text/ecmascript">
+<![CDATA[
+if (typeof getURL == 'undefined') {
+  getURL = function(url, callback) {
+    if (!url)
+      throw 'No URL for getURL';
+
+    try {
+      if (typeof callback.operationComplete == 'function')
+        callback = callback.operationComplete;
+    } catch (e) {}
+    if (typeof callback != 'function')
+      throw 'No callback function for getURL';
+
+    var http_request = null;
+    if (typeof XMLHttpRequest != 'undefined') {
+      http_request = new XMLHttpRequest();
+    }
+    else if (typeof ActiveXObject != 'undefined') {
+      try {
+        http_request = new ActiveXObject('Msxml2.XMLHTTP');
+      } catch (e) {
+        try {
+          http_request = new ActiveXObject('Microsoft.XMLHTTP');
+        } catch (e) {}
+      }
+    }
+    if (!http_request)
+      throw 'Both getURL and XMLHttpRequest are undefined';
+
+    http_request.onreadystatechange = function() {
+      if (http_request.readyState == 4) {
+        callback( { success : true,
+                    content : http_request.responseText,
+                    contentType : http_request.getResponseHeader("Content-Type") } );
+      }
+    }
+    http_request.open('GET', url, true);
+    http_request.send(null);
+  }
+}
+
+
+var SVGDoc = null;
+var last_cpu_total = 0;
+var last_cpu_idle = 0;
+var cpu_data = new Array();
+
+var max_num_points = 120;  // maximum number of plot data points
+var step = 600 / max_num_points;  // plot X division size
+
+var fetch_url='data_cpu.html';
+
+function init(evt) {
+	SVGDoc = evt.target.ownerDocument;
+	fetch_data();
+	setInterval('fetch_data()', 5000);
+}
+
+function fetch_data() {
+	if (fetch_url) {
+		getURL(fetch_url, plot_cpu_data);
+	} else {
+		handle_error();
+	}
+}
+
+function plot_cpu_data(obj) {
+	if (!obj.success || ''==obj.content) {
+		return handle_error();  // getURL failed to get current CPU load data
+	}
+
+	try {
+		var data=obj.content.split("\n");
+		var ugmt=(Date.parse(data[0]))/1000;
+		data=data[1].split(/\s+/);
+		var tot=parseInt(data[1])+parseInt(data[2])+parseInt(data[3])+parseInt(data[4]);
+		var idle=parseInt(data[4]);
+	} catch (e) {
+		return;
+	}
+
+	var cpu=0;
+	if (tot==last_cpu_total) {
+		cpu=100;
+	} else {
+		cpu=100*(idle-last_cpu_idle)/(tot-last_cpu_total);
+	}
+	cpu=100-cpu;
+
+	last_cpu_idle=idle;
+	last_cpu_total=tot;
+
+	if (!isNumber(cpu)) return handle_error();
+
+	switch (cpu_data.length) {
+	case 0:
+		SVGDoc.getElementById('collect_initial').setAttributeNS(null, 'visibility', 'visible');
+		cpu_data[0] = cpu;
+		fetch_data;
+		return;
+	case 1:
+		SVGDoc.getElementById('collect_initial').setAttributeNS(null, 'visibility', 'hidden');
+		break;
+	case max_num_points:
+		// shift plot to left if the maximum number of plot points has been reached
+		var i = 0;
+		while (i < max_num_points) {
+			cpu_data[i] = cpu_data[++i];
+		}
+		--cpu_data.length;
+	}
+
+	cpu_data[cpu_data.length] = cpu;
+
+	var path_data = "M 2 " + (298 - cpu_data[0]);
+	for (var i = 1; i < cpu_data.length; ++i) {
+		var x = step * i;
+		var y_cpu = 298 - 2.975*cpu_data[i];
+		path_data += " L" + x + " " + y_cpu;
+	}
+   
+	
+	SVGDoc.getElementById('error').setAttributeNS(null, 'visibility', 'hidden');
+	SVGDoc.getElementById('graph_cpu').setAttributeNS(null, 'd', path_data);
+	SVGDoc.getElementById('graph_txt').firstChild.data = Math.round(cpu*10)/10 + '%';
+}
+
+function handle_error() {
+  SVGDoc.getElementById("error").setAttributeNS(null, 'visibility', 'visible');
+  fetch_data();
+}
+
+function isNumber(a) {
+  return typeof a == 'number' && isFinite(a);
+}
+
+]]>
+</script>
+</svg>

Modified: trunk/config/scripts/tooltip.js
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/scripts/tooltip.js?view=diff&rev=620&r1=619&r2=620
==============================================================================
--- trunk/config/scripts/tooltip.js (original)
+++ trunk/config/scripts/tooltip.js Fri Apr  6 16:48:49 2007
@@ -29,6 +29,7 @@
 	tooltips['users'] .en[14] = "<B>3-Way Calling:</B>Check this option if the User or Phone should have 3-Way Calling capability."; //3-Way Calling:
 	tooltips['users'] .en[15] = "<B>Is Agent:</B> Check this option if this User or Phone is an Call Queue Member (Agent)"; //Is Agent:
 	tooltips['users'] .en[16] = "<B>VM Password:</B> Voicemail Password for this user, Ex: \"1234\"."; //Voicemail Password
+	tooltips['users'] .en[17] = "<B>Hints:</B> If checked the phone being called will be sent a \"hint\" to light up status lamps on SIP phones."; // Hint phone before being dialed.
 
 // Tooltips for Conferencing (meetme)
 	tooltips['meetme']= new Object;
@@ -247,3 +248,7 @@
 	tooltips['sysinfo'].en[1] = "<B>ifconfig:</B> Network devices information (ifconfig)";
 	tooltips['sysinfo'].en[2] = "<B>Resources:</B> Disk and Memory usage information";
 	tooltips['sysinfo'].en[3] = "<B>Logs:</B> Asterisk Log files";
+
+	tooltips['graph']= new Object;
+	tooltips['graph'].en = new Array;
+	tooltips['graph'].en[0] = "<B>CPU Usage:</B> Real-Time Updating Graph For CPU Usage";

Added: trunk/scripts/graphs.sh
URL: http://svn.digium.com/view/asterisk-gui/trunk/scripts/graphs.sh?view=auto&rev=620
==============================================================================
--- trunk/scripts/graphs.sh (added)
+++ trunk/scripts/graphs.sh Fri Apr  6 16:48:49 2007
@@ -1,0 +1,55 @@
+#!/bin/bash
+
+####################################################################
+####	Copyright Brandon Kruse <bkruse at digium.com> && Digium	####
+####################################################################
+
+#### Props and Credits to the m0n0wall and the xwrt group for information.
+#### Extra licensing information included in the svg files located at
+#### /var/lib/asterisk/static-http/config/graphs/*.svg. Thanks Guys!
+
+echo `date`
+case $1 in
+	cpu)
+		var="`head -n 1 /proc/stat`"
+		echo "$var"
+		;;
+	wan)
+		var="`cat /proc/net/dev | grep eth0`"
+		echo "$var"
+		;;
+	lan) 
+		var="`cat /proc/net/dev | grep eth1`"
+		echo "$var"
+		;;
+	hd)
+		var="`df -h`"	
+		echo "$var"
+		;;
+	mem)
+		var="`free`"
+		echo "$var"
+		;;
+	temp)
+		var="`echo \"temperature sensor?\"`"
+		echo "$var"
+		;;
+	ast)
+		var="`asterisk -rx 'core show channels'`"
+		echo "$var"
+		;;
+	swap)
+		SWAPINFO=$(free | grep "Swap:")
+		nI="0"
+		for CUR_VAR in $SWAPINFO; do
+			case "$nI" in
+				1)	TOTAL_SWAP=$CUR_VAR;;
+				3)	FREE_SWAP=$CUR_VAR
+			break;;
+			esac
+		let "nI+=1"
+		done
+		;;
+	
+esac
+#/proc/net/dev

Propchange: trunk/scripts/graphs.sh
------------------------------------------------------------------------------
    svn:executable = *



More information about the asterisk-gui-commits mailing list