diff options
-rw-r--r-- | html/rrdui.js | 46 | ||||
-rwxr-xr-x | tools/rrdui-cgi.py | 43 |
2 files changed, 51 insertions, 38 deletions
diff --git a/html/rrdui.js b/html/rrdui.js index 468fdc3..d5b80bb 100644 --- a/html/rrdui.js +++ b/html/rrdui.js @@ -103,6 +103,11 @@ function displayCurrentPage() if(img != null) continue; + var interval = child.getAttribute("interval"); + if(!interval || isNaN(interval) || interval <= 0) + interval = 0; + interval = Number(interval); + img = gdoc.createElement("img"); var title = child.getAttribute("title"); @@ -124,6 +129,7 @@ function displayCurrentPage() img._name = name; img._tbeg = tbeg; img._tend = tend; + img._tinterval = interval; reloadGraph(img); @@ -131,6 +137,14 @@ function displayCurrentPage() { actionGotoCancel(); return zoomGraphStart(evt || gwindow.event); } img.onmouseover = function(evt) { return actionsDisplay(gwindow.event ? gwindow.event : evt); } + + /* Setup for an auto scroll */ + if(interval) + { + /* Bump up auto scroll interval to 5 seconds */ + var interval = img._tinterval < 5 ? 5 : img._tinterval; + window.setInterval(autoScroll, interval * 1000, img); + } } } @@ -157,9 +171,13 @@ function reloadGraph(img) img._loading = true; updateCursors(img); + /* HACK: The onload event for IMG is called with a strange event target */ img.onload = new Function("reloadedGraph('" + img.id + "');"); img.setAttribute("src", uri); + + var now = nowTime(); + img._last = now; } function reloadedGraph(id) @@ -181,6 +199,34 @@ function updateCursors(img) img.style.cursor = img._loading ? "wait" : "crosshair"; } +function autoScroll(img) +{ + /* Don't auto scroll if we have loading issues */ + if(img._loading) + return; + + /* If we're displaying 'now' somewhere in the graph... */ + var now = nowTime(); + if((img._tend + img._tinterval + 2) >= now) + { + var diff = now - img._last; + + if(diff > 0) + { + /* ... then scroll by X seconds to scroll the graph */ + img._tbeg += diff; + img._tend += diff; + reloadGraph(img); + } + } +} + + + +/* ----------------------------------------------------------------------------- + * ZOOM + */ + function zoomGraphStart(evt) { /* COMPAT: In IE the left button is 1, Mozilla is 0 */ diff --git a/tools/rrdui-cgi.py b/tools/rrdui-cgi.py index 7390547..1584555 100755 --- a/tools/rrdui-cgi.py +++ b/tools/rrdui-cgi.py @@ -35,6 +35,7 @@ class GraphDef: self.filedata = "%s/%s.rrd" % (WORKDIR, name) self.category = "All" self.name = name + self.interval = 0 self.valid = False cfg = self.__config = ConfigParser.RawConfigParser() @@ -59,43 +60,9 @@ class GraphDef: self.options = cfg.get("graph", "options") self.valid = True - - def getCreateInfo(self): - cfg = self.__config - rra = None - fields = {} - - # The RRA info - if cfg.has_option("create", "rra"): - rra = cfg.get("create", "rra").split() - - # The various fields - for field in cfg.options("create"): - if not field.startswith("field."): - continue - fieldname = field[6:] - fields[fieldname] = cfg.get("create", field) - - return (fields, rra) - - - def getPollingInfo(self): - cfg = self.__config - interval = 300 - fields = {} - - # The interval + # Polling stuff if cfg.has_option("poll", "interval"): - interval = int(cfg.get("poll", "interval")) - - # The various fields - for field in cfg.options("poll"): - if not field.startswith("field."): - continue - fieldname = field[6:] - fields[fieldname] = cfg.get("poll", field) - - return (fields, interval) + self.interval = cfg.get("poll", "interval") def loadGraphs(path = ""): @@ -132,8 +99,8 @@ def listGraphs(): print " <category name=\"%s\">" % group categories[group].sort() for item in categories[group]: - print " <graph name=\"%s\" width=\"%d\" height=\"%d\" title=\"%s\"/>" % \ - (item.name, item.width, item.height, item.title) + print " <graph name=\"%s\" width=\"%d\" height=\"%d\" title=\"%s\" interval=\"%s\"/>" % \ + (item.name, item.width, item.height, item.title, item.interval) print " </category>" print "</data>" |