X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=web%2Findex.html;h=e8e821f43193fbba30f396a505bfacf2d00c0c3e;hb=3b051b5a2e2a09d4c57f7a7b4354150a1acf9ce8;hp=e95e31513aabd23fd494642c238d56b5b107bc27;hpb=6a0aee81aba1b0dabdb6dddd0ef37056a65855a1;p=netdata.git diff --git a/web/index.html b/web/index.html index e95e3151..e8e821f4 100644 --- a/web/index.html +++ b/web/index.html @@ -508,16 +508,36 @@ // -------------------------------------------------------------------- // check options that should be processed before loading netdata.js + var localStorageTested = -1; + function localStorageTest() { + if(localStorageTested !== -1) + return localStorageTested; + + if(typeof Storage !== "undefined" && typeof localStorage === 'object') { + var test = 'test'; + try { + localStorage.setItem(test, test); + localStorage.removeItem(test); + localStorageTested = true; + } + catch (e) { + localStorageTested = false; + } + } + else + localStorageTested = false; + + return localStorageTested; + } + function loadLocalStorage(name) { var ret = null; try { - if(typeof Storage !== "undefined" && typeof localStorage === 'object') + if(localStorageTest() === true) ret = localStorage.getItem(name); } - catch(error) { - ; - } + catch(error) {} if(typeof ret === 'undefined' || ret === null) return null; @@ -530,14 +550,12 @@ function saveLocalStorage(name, value) { // console.log('saving: ' + name.toString() + ' = ' + value.toString()); try { - if(typeof Storage !== "undefined" && typeof localStorage === 'object') { + if(localStorageTest() === true) { localStorage.setItem(name, value.toString()); return true; } } - catch(error) { - ; - } + catch(error) {} return false; } @@ -663,10 +681,7 @@ this_is_demo = true; } } - catch(error) { - ; - } - + catch(error) {} return this_is_demo; } @@ -685,9 +700,7 @@ } function netdataReload(url) { - var t = netdataURL(url); - // console.log('netdataReload: ' + t); - document.location = t; + document.location = netdataURL(url); // since we play with hash // this is needed to reload the page @@ -830,6 +843,8 @@ var deleteRegistryUrl = null; function deleteRegistryModalHandler(guid, name, url) { + void(guid); + deleteRegistryUrl = url; document.getElementById('deleteRegistryServerName').innerHTML = name; document.getElementById('deleteRegistryServerName2').innerHTML = name; @@ -854,45 +869,23 @@ } var options = { - sparklines_registry: {}, menus: {}, submenu_names: {}, data: null, hostname: 'netdata_server', // will be overwritten by the netdata server - categories: new Array(), + categories: [], categories_idx: {}, - families: new Array(), + families: [], families_idx: {}, chartsPerRow: 0, chartsMinWidth: 1450, - chartsHeight: 180, - sparklinesHeight: 60, + chartsHeight: 180 }; - // generate a sparkline - // used in the documentation - function sparkline(chart, dimension, units) { - var key = chart + '.' + dimension; - - if(typeof units === 'undefined') - units = ''; - - if(typeof options.sparklines_registry[key] === 'undefined') - options.sparklines_registry[key] = { count: 1 }; - else - options.sparklines_registry[key].count++; - - key = key + '.' + options.sparklines_registry[key].count; - - var h = '
(X' + units + ')'; - - return h; - } - function chartsPerRow(total) { if(options.chartsPerRow === 0) { - width = Math.floor(total / options.chartsMinWidth); + var width = Math.floor(total / options.chartsMinWidth); if(width === 0) width = 1; return width; } @@ -908,9 +901,11 @@ function sortObjectByPriority(object) { var idx = {}; - var sorted = new Array(); + var sorted = []; for(var i in object) { + if(!object.hasOwnProperty(i)) continue; + if(typeof idx[i] === 'undefined') { idx[i] = object[i]; sorted.push(i); @@ -945,10 +940,43 @@ // ---------------------------------------------------------------------------- var netdataDashboard = { + sparklines_registry: {}, + os: 'unknown', + menu: {}, submenu: {}, context: {}, + // generate a sparkline + // used in the documentation + sparkline: function (prefix, chart, dimension, units, suffix) { + if(options.data === null || typeof options.data.charts === 'undefined') + return ''; + + if(typeof options.data.charts[chart] === 'undefined') + return ''; + + if(typeof options.data.charts[chart].dimensions === 'undefined') + return ''; + + if(typeof options.data.charts[chart].dimensions[dimension] === 'undefined') + return ''; + + var key = chart + '.' + dimension; + + if(typeof units === 'undefined') + units = ''; + + if(typeof this.sparklines_registry[key] === 'undefined') + this.sparklines_registry[key] = { count: 1 }; + else + this.sparklines_registry[key].count++; + + key = key + '.' + this.sparklines_registry[key].count; + + return prefix + '
(X' + units + ')' + suffix; + }, + gaugeChart: function(title, width, dimensions, colors) { if(typeof colors === 'undefined') colors = ''; @@ -957,53 +985,69 @@ dimensions = ''; return '
'; + + ' data-dimensions="' + dimensions + '"' + + ' data-chart-library="gauge"' + + ' data-gauge-adjust="width"' + + ' data-title="' + title + '"' + + ' data-width="' + width + '"' + + ' data-before="0"' + + ' data-after="-CHART_DURATION"' + + ' data-points="CHART_DURATION"' + + ' data-colors="' + colors + '"' + + ' role="application">'; }, anyAttribute: function(obj, attr, key, def) { - if(typeof obj[key] !== 'undefined') { - if(typeof obj[key][attr] !== 'undefined') - return obj[key][attr]; + if(typeof(obj[key]) !== 'undefined') { + var x = obj[key][attr]; + + if(typeof(x) === 'undefined') + return def; + + if(typeof(x) === 'function') { + return x(netdataDashboard.os); + } + + return x; } + return def; }, menuTitle: function(chart) { if(typeof chart.menu_pattern !== 'undefined') { - return (netdataDashboard.anyAttribute(netdataDashboard.menu, 'title', chart.menu_pattern, chart.menu_pattern).toString() + return (this.anyAttribute(this.menu, 'title', chart.menu_pattern, chart.menu_pattern).toString() + ' ' + chart.type.slice(-(chart.type.length - chart.menu_pattern.length - 1)).toString()).replace(/_/g, ' '); } - return (netdataDashboard.anyAttribute(netdataDashboard.menu, 'title', chart.menu, chart.menu)).toString().replace(/_/g, ' '); + return (this.anyAttribute(this.menu, 'title', chart.menu, chart.menu)).toString().replace(/_/g, ' '); }, menuIcon: function(chart) { if(typeof chart.menu_pattern !== 'undefined') - return netdataDashboard.anyAttribute(netdataDashboard.menu, 'icon', chart.menu_pattern, '').toString(); + return this.anyAttribute(this.menu, 'icon', chart.menu_pattern, '').toString(); - return netdataDashboard.anyAttribute(netdataDashboard.menu, 'icon', chart.menu, ''); + return this.anyAttribute(this.menu, 'icon', chart.menu, ''); }, - menuInfo: function(menu) { - return netdataDashboard.anyAttribute(netdataDashboard.menu, 'info', menu, null); + menuInfo: function(chart) { + if(typeof chart.menu_pattern !== 'undefined') + return this.anyAttribute(this.menu, 'info', chart.menu_pattern, null); + + return this.anyAttribute(this.menu, 'info', chart.menu, null); }, - menuHeight: function(menu, relative) { - return netdataDashboard.anyAttribute(netdataDashboard.menu, 'height', menu, 1.0) * relative; + menuHeight: function(chart) { + if(typeof chart.menu_pattern !== 'undefined') + return this.anyAttribute(this.menu, 'height', chart.menu_pattern, 1.0); + + return this.anyAttribute(this.menu, 'height', chart.menu, 1.0); }, submenuTitle: function(menu, submenu) { var key = menu + '.' + submenu; - var title = netdataDashboard.anyAttribute(netdataDashboard.submenu, 'title', key, submenu).toString().replace(/_/g, ' ');; + // console.log(key); + var title = this.anyAttribute(this.submenu, 'title', key, submenu).toString().replace(/_/g, ' '); if(title.length > 28) { var a = title.substring(0, 13); var b = title.substring(title.length - 12, title.length); @@ -1014,31 +1058,33 @@ submenuInfo: function(menu, submenu) { var key = menu + '.' + submenu; - return netdataDashboard.anyAttribute(netdataDashboard.submenu, 'info', key, null); + return this.anyAttribute(this.submenu, 'info', key, null); }, submenuHeight: function(menu, submenu, relative) { var key = menu + '.' + submenu; - return netdataDashboard.anyAttribute(netdataDashboard.submenu, 'height', key, 1.0) * relative; + return this.anyAttribute(this.submenu, 'height', key, 1.0) * relative; }, contextInfo: function(id) { - if(typeof netdataDashboard.context[id] !== 'undefined' && typeof netdataDashboard.context[id].info !== 'undefined') - return '
' + netdataDashboard.context[id].info + '
'; + var x = this.anyAttribute(this.context, 'info', id, null); + + if(x !== null) + return '
' + x + '
'; else return ''; }, contextValueRange: function(id) { - if(typeof netdataDashboard.context[id] !== 'undefined' && typeof netdataDashboard.context[id].valueRange !== 'undefined') - return netdataDashboard.context[id].valueRange; + if(typeof this.context[id] !== 'undefined' && typeof this.context[id].valueRange !== 'undefined') + return this.context[id].valueRange; else return '[null, null]'; }, contextHeight: function(id, def) { - if(typeof netdataDashboard.context[id] !== 'undefined' && typeof netdataDashboard.context[id].height !== 'undefined') - return def * netdataDashboard.context[id].height; + if(typeof this.context[id] !== 'undefined' && typeof this.context[id].height !== 'undefined') + return def * this.context[id].height; else return def; } @@ -1048,8 +1094,10 @@ // enrich the data structure returned by netdata // to reflect our menu system and content + // FIXME: this is a shame - we should fix charts naming (issue #807) function enrichChartData(chart) { - var tmp = chart.type.split('_')[0]; + var parts = chart.type.split('_'); + var tmp = parts[0]; switch(tmp) { case 'ap': @@ -1058,6 +1106,18 @@ chart.menu = tmp; break; + case 'apache': + chart.menu = chart.type; + if(parts.length > 2 && parts[1] === 'cache') + chart.menu_pattern = tmp + '_' + parts[1]; + break; + + case 'bind': + chart.menu = chart.type; + if(parts.length > 2 && parts[1] === 'rndc') + chart.menu_pattern = tmp + '_' + parts[1]; + break; + case 'cgroup': chart.menu = chart.type; if(chart.id.match(/.*[\._\/-:]qemu[\._\/-:]*/) || chart.id.match(/.*[\._\/-:]kvm[\._\/-:]*/)) @@ -1066,9 +1126,27 @@ chart.menu_pattern = 'cgroup'; break; - case 'apache': - case 'exim': + case 'isc': + chart.menu = chart.type; + if(parts.length > 2 && parts[1] === 'dhcpd') + chart.menu_pattern = tmp + '_' + parts[1]; + break; + + case 'ovpn': + chart.menu = chart.type; + if(parts.length > 3 && parts[1] === 'status' && parts[2] === 'log') + chart.menu_pattern = tmp + '_' + parts[1]; + break; + + case 'smartd': + case 'web': + chart.menu = chart.type; + if(parts.length > 2 && parts[1] === 'log') + chart.menu_pattern = tmp + '_' + parts[1]; + break; + case 'dovecot': + case 'exim': case 'hddtemp': case 'ipfs': case 'memcached': @@ -1094,7 +1172,7 @@ // find a name for this device from fireqos info // we strip '_(in|out)' or '(in|out)_' - if(typeof options.submenu_names[chart.family] === 'undefined' || options.submenu_names[chart.family] === chart.family) { + if(chart.context === 'tc.qos' && (typeof options.submenu_names[chart.family] === 'undefined' || options.submenu_names[chart.family] === chart.family)) { var n = chart.name.split('.')[1]; if(n.endsWith('_in')) options.submenu_names[chart.family] = n.slice(0, n.lastIndexOf('_in')); @@ -1104,6 +1182,8 @@ options.submenu_names[chart.family] = n.slice(3, n.length); else if(n.startsWith('out_')) options.submenu_names[chart.family] = n.slice(4, n.length); + else + options.submenu_names[chart.family] = n; } // increase the priority of IFB devices @@ -1123,7 +1203,9 @@ // ---------------------------------------------------------------------------- - function headMain(charts, duration) { + function headMain(os, charts, duration) { + void(os); + var head = ''; if(typeof charts['system.swap'] !== 'undefined') @@ -1244,7 +1326,7 @@ var hi = 0, hlen = hcharts.length; while(hi < hlen) { if(typeof hcharts[hi] === 'function') - head += hcharts[hi](chart.id).replace('CHART_DURATION', duration.toString()).replace('CHART_UNIQUE_ID', chart.id); + head += hcharts[hi](netdataDashboard.os, chart.id).replace('CHART_DURATION', duration.toString()).replace('CHART_UNIQUE_ID', chart.id); else head += hcharts[hi].replace('CHART_DURATION', duration.toString()).replace('CHART_UNIQUE_ID', chart.id); hi++; @@ -1261,7 +1343,7 @@ var duration = Math.round(($(div).width() * pcent_width / 100 * data.update_every / 3) / 60) * 60; var html = ''; var sidebar = '