(no commit message)
authorStephen Soltesz <soltesz@cs.princeton.edu>
Wed, 24 Sep 2008 16:04:35 +0000 (16:04 +0000)
committerStephen Soltesz <soltesz@cs.princeton.edu>
Wed, 24 Sep 2008 16:04:35 +0000 (16:04 +0000)
www/gadgets/gadget.php [new file with mode: 0644]
www/gadgets/gadget.xml [new file with mode: 0644]
www/gadgets/regions.xml [new file with mode: 0644]
www/gadgets/sitemonitor.py [new file with mode: 0755]
www/gadgets/sitemonitor.xml [new file with mode: 0644]

diff --git a/www/gadgets/gadget.php b/www/gadgets/gadget.php
new file mode 100644 (file)
index 0000000..391bab7
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+#function get_comon_count()
+#{
+#      $url = "http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeview&format=nameonly";
+#      $count = `wget --quiet -O - "$url" | wc -l`;
+#      return $count;
+#}
+#function get_comon_count_for($query)
+#{
+#      $url = "http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=nameonly&select='$query'";
+#      $count = `wget --quiet -O - "$url" | wc -l`;
+#      return $count;
+#}
+#$total = get_comon_count();
+#$alive = get_comon_count_for("lastcotop==0");
+#$fc2 = get_comon_count_for("fcname==2");
+#$fc4 = get_comon_count_for("fcname==4");
+#$not_alive = $total - $alive;
+#$nossh = get_comon_count_for("sshstatus>0||sshstatus<0");
+#$unknown = abs($not_alive - $nossh);
+#$time = date("D M j G:i:s");
+#$monday_csv_list= trim(file_get_contents("monday.txt"));
+#$monday_array = split(",", $monday_csv_list);
+
+$bad_csv_list= trim(file_get_contents("badcsv.txt"));
+$sarray = split(",", $bad_csv_list);   # split on comma
+
+$alpha_running = $sarray[0];
+$prod_running = $sarray[1];
+$oldboot_running = $sarray[2];
+$alpha_debug = $sarray[3];
+
+$prod_debug = $sarray[4];
+$oldboot_debug = $sarray[5];
+$down = $sarray[6];
+#$prod_since_monday = $alpha_running - $monday_array[0];
+#$oldboot_since_monday = $monday_array[1] - $oldboot_running;
+$monitor_total = $prod_running + $prod_debug + $down +$oldboot_running + $oldboot_debug + $alpha_running + $alpha_debug;
+?>
+
+<table cellspacing=3>
+<!--/table>
+
+<table cellspacing=3-->
+<tr>
+<th align=left>MONITOR</th>
+<th align=right>Boot</th>
+<th align=right>Debug</th>
+<th align=right>Down</th>
+<th align=right></th>
+</tr> 
+<tr> 
+<th align=left>Production 4.2</th> 
+<td bgcolor=lightgrey align=right><?php echo $alpha_running ?></td> 
+<td align=right><?php echo $alpha_debug + $prod_debug ?></td> 
+<td align=right><?php echo $down ?></td>
+<td align=right><?php echo ($alpha_running + $alpha_debug + $prod_debug + $down) ?></td> 
+</tr> 
+<tr> 
+<th align=left>Production 4.1</th> 
+<td align=right><?php echo $prod_running ?></td> 
+<td align=right>--</td> 
+<td align=right>--</td> 
+<td align=right><?php echo ($prod_running) ?></td>
+</tr> 
+<tr> 
+<th align=left>Old BootCD</th> 
+<td align=right><?php echo $oldboot_running ?></td> 
+<td align=right><?php echo $oldboot_debug ?></td> 
+<td align=right>--</td> 
+<td align=right><?php echo ($oldboot_running + $oldboot_debug) ?></td> 
+<tr> 
+<th align=left>Sums</th> 
+<td align=right><?php echo $prod_running+$alpha_running+$oldboot_running ?></td> 
+<td align=right><?php echo $prod_debug+$oldboot_debug+$alpha_debug ?></td> 
+<td align=right>--</td>
+<td bgcolor=lightgrey align=right><?php echo ($prod_running + $prod_debug + $down +$oldboot_running + $oldboot_debug + $alpha_running + $alpha_debug) ?></td>
+</tr> 
+<tr> 
+<th align=left></th> 
+<td align=right><?php echo sprintf("%.1f%%", ($prod_running+$alpha_running+$oldboot_running)/1.0/$monitor_total*100) ?></td> 
+<td align=right><?php echo sprintf("%.1f%%", (($prod_debug+$oldboot_debug+$alpha_debug)/1.0/$monitor_total*100)) ?></td>
+<td align=right><?php echo sprintf("%.1f%%", ($down/1.0/$monitor_total*100)) ?></td>
+<td align=right></td>
+</tr> 
+<tr> 
+<td>
+<a target=_blank href="http://monitor.planet-lab.org/monitor/gadget.php">Direct Link</a>
+</td>
+</tr> 
+</table>
diff --git a/www/gadgets/gadget.xml b/www/gadgets/gadget.xml
new file mode 100644 (file)
index 0000000..d860f0c
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Module>
+<ModulePrefs title="Monitor Node Count" title_url="http://www.planet-lab.org">
+<Require feature="dynamic-height"/>
+</ModulePrefs>
+<Content type="html"><![CDATA[
+<div id="content_div"></div>
+<script type="text/javascript">
+var displaycontent = function (responseText) {
+       _gel('content_div').innerHTML = responseText; 
+       _IG_AdjustIFrameHeight();
+};
+_IG_FetchContent('http://pl-virtual-03.cs.princeton.edu/monitor/comon.php', displaycontent, { refreshInterval: 300 }); 
+</script>
+]]></Content>
+</Module>
diff --git a/www/gadgets/regions.xml b/www/gadgets/regions.xml
new file mode 100644 (file)
index 0000000..580207f
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Module>
+<ModulePrefs title="Monitor Node Count" title_url="http://www.planet-lab.org">
+<Require feature="dynamic-height"/>
+</ModulePrefs>
+<Content type="html"><![CDATA[
+<div id="content_div"></div>
+<script type="text/javascript">
+var displaycontent = function (responseText) {
+       _gel('content_div').innerHTML = responseText; 
+       _IG_AdjustIFrameHeight();
+};
+_IG_FetchContent('http://pl-virtual-03.cs.princeton.edu/monitor/regions.html', displaycontent, { refreshInterval: 1200 }); 
+</script>
+]]></Content>
+</Module>
diff --git a/www/gadgets/sitemonitor.py b/www/gadgets/sitemonitor.py
new file mode 100755 (executable)
index 0000000..e92a9cc
--- /dev/null
@@ -0,0 +1,143 @@
+#!/usr/bin/python
+
+import cgi
+import cgitb
+cgitb.enable()
+print "Content-Type: text/html\r\n"
+
+import time
+from unified_model import *
+from monitor import database
+from HyperText.HTML import A, BR, IMG, TABLE, TR, TH, TD, EM, quote_body, CENTER
+from HyperText.Documents import Document
+
+form = cgi.FieldStorage()
+
+print """
+<style>
+table {
+       align: center;
+    border-color: #ccc;
+    border-width: 0 0 1px 1px;
+    border-style: solid;
+}
+th {
+    border-color: #fff;
+    border-width: 1px 1px 1px 1px;
+    border-style: solid;
+    margin: 0;
+    padding: 0px;
+}
+td {
+    border-color: #ccc;
+    border-width: 1px 1px 0 0;
+    border-style: solid;
+    margin: 0;
+    padding: 3px;
+}
+</style>
+"""
+
+def get(fb, path):
+    indexes = path.split("/")
+    values = fb
+    for index in indexes:
+        if index in values:
+            values = values[index]
+        else:
+            return None
+    return values
+
+def diff_time(timestamp, abstime=True):
+       import math
+       now = time.time()
+       if timestamp == None:
+               return "unknown"
+       if abstime:
+               diff = now - timestamp
+       else:
+               diff = timestamp
+       # return the number of seconds as a difference from current time.
+       t_str = ""
+       if diff < 60: # sec in min.
+               t = diff / 1
+               t_str = "%s sec ago" % int(math.ceil(t))
+       elif diff < 60*60: # sec in hour
+               t = diff / (60)
+               t_str = "%s min ago" % int(math.ceil(t))
+       elif diff < 60*60*24: # sec in day
+               t = diff / (60*60)
+               t_str = "%s hrs ago" % int(math.ceil(t))
+       elif diff < 60*60*24*14: # sec in week
+               t = diff / (60*60*24)
+               t_str = "%s days ago" % int(math.ceil(t))
+       elif diff <= 60*60*24*30: # approx sec in month
+               t = diff / (60*60*24*7)
+               t_str = "%s weeks ago" % int(math.ceil(t))
+       elif diff > 60*60*24*30: # approx sec in month
+               t = diff / (60*60*24*30)
+               t_str = "%s months ago" % int(t)
+       return t_str
+
+def get_value(val):
+       
+       if form.has_key(val):
+               retvalue = form.getvalue(val)
+       else:
+               retvalue = None
+       
+       return retvalue
+
+def state_to_color(state):
+       if state == "BOOT":
+               return "darkseagreen"
+       elif state == "DEBUG":
+               return "gold"
+       elif state == "DOWN":
+               return "indianred"
+       else:
+               return "lightgrey"
+
+def main():
+       
+       if form.has_key('loginbase'):
+               loginbase = form.getvalue('loginbase')
+       else:
+               loginbase = "undefined"
+
+       fb = database.dbLoad("findbad")
+       lb2hn = database.dbLoad("plcdb_lb2hn")
+       pf = database.dbLoad("node_persistflags")
+
+       # SETUP header
+       t = TABLE(border="0", cellspacing="0", cellpadding="0")
+       r = TR()
+
+       if loginbase not in lb2hn:
+               value = ("Select 'Edit settings' to enter your Site's loginbase.", "")
+               r = TR(TD(value[0]))
+               t.append(r)
+       else:
+               for value in ['Hostname', 'Since']:
+                       r.append(TH(value))
+               t.append(r)
+               nodes = lb2hn[loginbase]
+               hostnames = [ n['hostname'] for n in nodes ]
+               hostnames.sort()
+
+               for host in hostnames:
+                       r = TR()
+                       color = state_to_color(fb['nodes'][host]['values']['state'])
+                       url = 'http://www.planet-lab.org/db/nodes/index.php?nodepattern=%s' % host
+                       td = TD(A(host, target='_blank', href=url), bgcolor=color)
+                       r.append(td)
+                       lc = pf[host].last_changed
+                       td = TD(diff_time(lc))
+                       r.append(td)
+                       t.append(r)
+                       
+       #d = Document(t)
+       print CENTER(t)
+
+if __name__ == "__main__":
+       main()
diff --git a/www/gadgets/sitemonitor.xml b/www/gadgets/sitemonitor.xml
new file mode 100644 (file)
index 0000000..4eb2922
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Module>
+       <ModulePrefs title="PlanetLab Site Status" title_url="http://www.planet-lab.org">
+               <Require feature="dynamic-height"/>
+       </ModulePrefs>
+       <UserPref name="loginBase" display_name="Site Login Base" 
+                         default_value="loginbase" datatype="string"></UserPref>
+       <!--UserPref name="reloadRandom" display_name="reset" 
+                         default_value="true" datatype="bool"></UserPref-->
+       <Content type="html"><![CDATA[
+<div id="content_div"></div>
+<script type="text/javascript">
+var prefs = new _IG_Prefs(__MODULE_ID__);
+var displaycontent = function (responseText) {
+       _gel('content_div').innerHTML = responseText; 
+       _IG_AdjustIFrameHeight();
+};
+var url = 'http://monitor.planet-lab.org/cgi-bin/monitorgadget.py?loginbase=' + prefs.getString("loginBase");
+_IG_FetchContent(url, displaycontent, { refreshInterval: 1200 }); 
+</script>
+]]></Content>
+</Module>