diff --git a/httpdocs/js/cubism.rrd-server.js b/httpdocs/js/cubism.rrd-server.js index b3f579bfee..60bf940662 100644 --- a/httpdocs/js/cubism.rrd-server.js +++ b/httpdocs/js/cubism.rrd-server.js @@ -1,6 +1,77 @@ -/* Adapted from https://github.com/cliffeh/cubism-rrdserver */ +/* + * This file provides cubism.js data. Two modes are available: + * - RRD: get data from RRD. + * - LIVE: get data live counters. + * + */ -cubism.rrdserver = function(context) { + +cubism.rrdserver = function(context, resolution) { + /* + * live window keeps previous values of each live counter to work with cubism.js queries. + * This should be as near to resolution as possible. + * High values decrese performance but also increase data retention across mode change. + */ + var LIVE_WINDOW_SIZE = Math.floor(resolution * 0.7); + + function getRelevantValue(up, down, bg, showbg) { + if (showbg) + return bg; + return up >= down ? -up : down; + } + + var LiveCounter = function (step, isbg) { + this.reset = function(step, isbg) { + this.up = 0; + this.down = 0; + this.bg = 0; + this.lastpoll = -1; + this.step = step; + this.live_window = new Array(LIVE_WINDOW_SIZE).fill(0); + this.isbg = isbg; + } + + this.isValidTime = function(stop) { + return this.lastpoll==-1 ? true : (stop - this.lastpoll >= this.step); + } + + this.update = function(stop, up, down, bg) { + if (this.lastpoll != -1) { + // adjust the window + this.scrollWindow(stop); + this.live_window[LIVE_WINDOW_SIZE-1] = getRelevantValue(up-this.up, down-this.down, bg-this.bg, this.isbg) + } + + this.up = up; + this.down = down; + this.bg = bg; + this.lastpoll = stop; + } + + this.scrollWindow = function(stop) { + var scroll = (stop - this.lastpoll) / this.step; + var i; + + for (i=0; i+scroll= downval ? -upval : downval); - upval = downval = 0; + var counter = live_counters[showbg ? 1 : 0][name]; + + // fill the gaps with saved values or zeroes + var points = (stop - start) / step; + for (var i=0; i= 0) + res.push(counter.getAt(j)); + else + res.push(0); } + } else { + for (var i=0; iProtocol Activity
- User Traffic
- Background Traffic + User Traffic
+ Background Traffic
-
+
+ +
+ Resolution:  + +
@@ -1087,18 +1098,13 @@ if host["localhost"] == true then

NOTE:
The above map filters host application traffic by splitting it in real user reaffic (e.g. web page access)