]> arthur.barton.de Git - netdata.git/commitdiff
new Date().getTime() to Date.now(); #1281
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 26 Nov 2016 13:22:19 +0000 (15:22 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 26 Nov 2016 13:22:19 +0000 (15:22 +0200)
node.d/node_modules/netdata.js
web/dashboard.js
web/index.html
web/old/index.js
web/old/netdata.js

index 5e052e13c4d1f013aab115a7aef7d5328cb1fb57..6b138ee54fc08199de5c8a1bccfa672504d06183 100644 (file)
@@ -171,7 +171,7 @@ var netdata = {
         if(typeof service === 'undefined')
             service = {};
 
-        var now = new Date().getTime();
+        var now = Date.now();
 
         service._current_chart = null;  // the current chart we work on
         service._queue = '';            // data to be sent to netdata
@@ -214,7 +214,7 @@ var netdata = {
             if(this.added !== true) {
                 this.added = true;
                 
-                var now = new Date().getTime();
+                var now = Date.now();
                 this.next_run = now - (now % (service.update_every * 1000)) + (service.update_every * 1000);
 
                 netdata.services.push(this);
@@ -230,14 +230,14 @@ var netdata = {
 
             this.module.active++;
             this.running = true;
-            this.started = new Date().getTime();
+            this.started = Date.now();
             this.updates++;
 
             if(netdata.options.DEBUG === true)
                 netdata.debug(this.module.name + ': ' + this.name + ': making ' + this.processor.name + ' request: ' + netdata.stringify(this));
 
             this.processor.process(this, function(response) {
-                service.ended = new Date().getTime();
+                service.ended = Date.now();
                 service.duration = service.ended - service.started;
 
                 if(typeof response === 'undefined')
@@ -541,7 +541,7 @@ var netdata = {
     runAllServices: function() {
         if(netdata.options.DEBUG === true) netdata.debug('runAllServices()');
 
-        var now = new Date().getTime();
+        var now = Date.now();
         var len = netdata.services.length;
         while(len--) {
             var service = netdata.services[len];
@@ -551,7 +551,7 @@ var netdata = {
 
             service.update();
 
-            now = new Date().getTime();
+            now = Date.now();
             service.next_run = now - (now % (service.update_every * 1000)) + (service.update_every * 1000);
         }
 
index c47c5c0c9478a0d597cc5323ee3b55cf82ecb77d..59026f4fd3da44543a0096bfb3ed32418e3b19f1 100644 (file)
                                         // rendering the chart that is panned or zoomed).
                                         // Used with .current.global_pan_sync_time
 
-        last_resized: new Date().getTime(), // the timestamp of the last resize request
+        last_resized: Date.now(),       // the timestamp of the last resize request
 
         last_page_scroll: 0,            // the timestamp the last time the page was scrolled
 
         console.log('welcome to NETDATA');
 
     NETDATA.onresize = function() {
-        NETDATA.options.last_resized = new Date().getTime();
+        NETDATA.options.last_resized = Date.now();
         NETDATA.onscroll();
     };
 
     NETDATA.onscroll_updater = function() {
         NETDATA.onscroll_updater_running = true;
         NETDATA.onscroll_updater_count++;
-        var start = new Date().getTime();
+        var start = Date.now();
 
         var targets = NETDATA.options.targets;
         var len = targets.length;
                 targets[len].isVisible();
         }
 
-        var end = new Date().getTime();
+        var end = Date.now();
         // console.log('scroll No ' + NETDATA.onscroll_updater_count + ' calculation took ' + (end - start).toString() + ' ms');
 
         if(NETDATA.options.current.async_on_scroll === false) {
     NETDATA.onscroll = function() {
         // console.log('onscroll');
 
-        NETDATA.options.last_page_scroll = new Date().getTime();
+        NETDATA.options.last_page_scroll = Date.now();
         NETDATA.options.auto_refresher_stop_until = 0;
 
         if(NETDATA.options.targets === null) return;
     NETDATA.error = function(code, msg) {
         NETDATA.errorLast.code = code;
         NETDATA.errorLast.message = msg;
-        NETDATA.errorLast.datetime = new Date().getTime();
+        NETDATA.errorLast.datetime = Date.now();
 
         console.log("ERROR " + code + ": " + NETDATA.errorCodes[code].message + ": " + msg);
 
             if(this.master !== null && this.master !== state)
                 this.master.resetChart(true, true);
 
-            var now = new Date().getTime();
+            var now = Date.now();
             this.master = state;
             this.seq = now;
             this.force_after_ms = after;
             if(NETDATA.chartDefaults.min_width !== null)
                 $(that.element).css('min-width', NETDATA.chartDefaults.min_width);
 
-            that.tm.last_dom_created = new Date().getTime();
+            that.tm.last_dom_created = Date.now();
 
             showLoading();
         };
             that.data_before = 0;           // milliseconds - the last timestamp of the data
             that.data_update_every = 0;     // milliseconds - the frequency to update the data
 
-            that.tm.last_initialized = new Date().getTime();
+            that.tm.last_initialized = Date.now();
             createDOM();
 
             that.setMode('auto');
                     showRendering();
                     that.element_chart.style.display = 'none';
                     if(that.element_legend !== null) that.element_legend.style.display = 'none';
-                    that.tm.last_hidden = new Date().getTime();
+                    that.tm.last_hidden = Date.now();
 
                     // de-allocate data
                     // This works, but I not sure there are no corner cases somewhere
                 init();
             }
             else {
-                that.tm.last_unhidden = new Date().getTime();
+                that.tm.last_unhidden = Date.now();
                 that.element_chart.style.display = '';
                 if(that.element_legend !== null) that.element_legend.style.display = '';
                 resizeChart();
                     maxMessageFontSize();
                 }
 
-                that.tm.last_resized = new Date().getTime();
+                that.tm.last_resized = Date.now();
             }
         };
 
             if(that.settings_id !== null)
                 NETDATA.localStorageSet('chart_heights.' + that.settings_id, h);
 
-            var now = new Date().getTime();
+            var now = Date.now();
             NETDATA.options.last_page_scroll = now;
             NETDATA.options.auto_refresher_stop_until = now + NETDATA.options.current.stop_updates_while_resizing;
 
             this.event_resize.chart_last_w = this.element.clientWidth;
             this.event_resize.chart_last_h = this.element.clientHeight;
 
-            var now = new Date().getTime();
+            var now = Date.now();
             if(now - this.event_resize.last <= NETDATA.options.current.double_click_speed) {
                 // double click / double tap event
 
         var noDataToShow = function() {
             showMessageIcon('<i class="fa fa-warning"></i> empty');
             that.legendUpdateDOM();
-            that.tm.last_autorefreshed = new Date().getTime();
+            that.tm.last_autorefreshed = Date.now();
             // that.data_update_every = 30 * 1000;
             //that.element_chart.style.display = 'none';
             //if(that.element_legend !== null) that.element_legend.style.display = 'none';
             this.current.force_before_ms = null;
             this.current.force_after_ms = null;
 
-            this.tm.last_mode_switch = new Date().getTime();
+            this.tm.last_mode_switch = Date.now();
         };
 
         // ----------------------------------------------------------------------------------------------------------------
                 return;
 
             if(typeof ms === 'number')
-                NETDATA.globalSelectionSync.dont_sync_before = new Date().getTime() + ms;
+                NETDATA.globalSelectionSync.dont_sync_before = Date.now() + ms;
             else
-                NETDATA.globalSelectionSync.dont_sync_before = new Date().getTime() + NETDATA.options.current.sync_selection_delay;
+                NETDATA.globalSelectionSync.dont_sync_before = Date.now() + NETDATA.options.current.sync_selection_delay;
         };
 
         // can we globally apply selection sync?
             if(NETDATA.options.current.sync_selection === false)
                 return false;
 
-            if(NETDATA.globalSelectionSync.dont_sync_before > new Date().getTime())
+            if(NETDATA.globalSelectionSync.dont_sync_before > Date.now())
                 return false;
 
             return true;
             if(this.debug === true)
                 this.log(logme + 'ACCEPTING UPDATE: current/min duration: ' + (current_duration / 1000).toString() + '/' + (this.fixed_min_duration / 1000).toString() + ', wanted duration: ' + (wanted_duration / 1000).toString() + ', duration diff: ' + (Math.round(Math.abs(current_duration - wanted_duration) / 1000)).toString() + ', movement: ' + (movement / 1000).toString() + ', tolerance: ' + (tolerance / 1000).toString() + ', returning: ' + ret);
 
-            this.current.force_update_at = new Date().getTime() + NETDATA.options.current.pan_and_zoom_delay;
+            this.current.force_update_at = Date.now() + NETDATA.options.current.pan_and_zoom_delay;
             this.current.force_after_ms = after;
             this.current.force_before_ms = before;
             NETDATA.globalPanAndZoom.setMaster(this, after, before);
             this.updates_since_last_unhide++;
             this.updates_since_last_creation++;
 
-            var started = new Date().getTime();
+            var started = Date.now();
 
             // if the result is JSON, find the latest update-every
             this.data_update_every = data.view_update_every * 1000;
                 NETDATA.globalSelectionSync.stop();
 
             // update the performance counters
-            var now = new Date().getTime();
+            var now = Date.now();
             this.tm.last_updated = now;
 
             // don't update last_autorefreshed if this chart is
             if(nocache === false && this.tm.last_visible_check > NETDATA.options.last_page_scroll)
                 return this.___isVisible___;
 
-            this.tm.last_visible_check = new Date().getTime();
+            this.tm.last_visible_check = Date.now();
 
             var wh = window.innerHeight;
             var x = this.element.getBoundingClientRect();
         };
 
         this.canBeAutoRefreshed = function() {
-            var now = new Date().getTime();
+            var now = Date.now();
 
             if(this.running === true) {
                 if(this.debug === true)
             this.chart_url = chart.url;
             this.data_update_every = chart.update_every * 1000;
             this.data_points = Math.round(this.chartWidth() / this.chartPixelsPerPoint());
-            this.tm.last_info_downloaded = new Date().getTime();
+            this.tm.last_info_downloaded = Date.now();
 
             if(this.title === null)
                 this.title = chart.title;
     };
 
     NETDATA.parseDom = function(callback) {
-        NETDATA.options.last_page_scroll = new Date().getTime();
+        NETDATA.options.last_page_scroll = Date.now();
         NETDATA.options.updated_dom = false;
 
         var targets = $('div[data-netdata]'); //.filter(':visible');
             dygraph.updateOptions(options);
         }
 
-        state.dygraph_last_rendered = new Date().getTime();
+        state.dygraph_last_rendered = Date.now();
         return true;
     };
 
                     // the internal default of dygraphs
                     context.touchDirections = { x: true, y: false };
 
-                    state.dygraph_last_touch_start = new Date().getTime();
+                    state.dygraph_last_touch_start = Date.now();
                     state.dygraph_last_touch_move = 0;
 
                     if(typeof event.touches[0].pageX === 'number')
                     state.dygraph_user_action = true;
                     Dygraph.defaultInteractionModel.touchmove(event, dygraph, context);
 
-                    state.dygraph_last_touch_move = new Date().getTime();
+                    state.dygraph_last_touch_move = Date.now();
                 },
                 touchend: function(event, dygraph, context) {
                     if(NETDATA.options.debug.dygraph === true || state.debug === true)
                     }
 
                     // if it was double tap within double click time, reset the charts
-                    var now = new Date().getTime();
+                    var now = Date.now();
                     if(typeof state.dygraph_last_touch_end !== 'undefined') {
                         if(state.dygraph_last_touch_move === 0) {
                             var dt = now - state.dygraph_last_touch_end;
 
         state.dygraph_force_zoom = false;
         state.dygraph_user_action = false;
-        state.dygraph_last_rendered = new Date().getTime();
+        state.dygraph_last_rendered = Date.now();
 
         if(typeof state.dygraph_instance.axes_[0].extremeRange !== 'undefined') {
             state.__commonMin = self.data('common-min') || null;
                 NETDATA.registry.machines = {};
                 NETDATA.registry.machines_array = new Array();
 
-                var now = new Date().getTime();
+                var now = Date.now();
                 var apu = person_urls;
                 var i = apu.length;
                 while(i--) {
index e6079e2d1b465bfb6cf8d982ac4bd7c2794cbde2..e8e0b18c90319f6c4d79d85db1569a454ee6d23d 100644 (file)
             }
 
             // find the proper family of each alarm
-            var now = new Date().getTime();
+            var now = Date.now();
             var x;
             var count_active = 0;
             var count_all = 0;
     function notifyForUpdate(force) {
         versionLog('<p>checking for updates...</p>');
 
-        var now = new Date().getTime();
+        var now = Date.now();
 
         if(typeof force === 'undefined' || force !== true) {
             var last = loadLocalStorage('last_update_check');
index 3a28daf738b4ef98076aa532b0f1e8ac1cb3fe89..370cf1bb05f0be9eae03f8f655a14ce0c8d96cc6 100644 (file)
@@ -228,7 +228,7 @@ function refreshHiddenChart(doNext) {
        }
 
        // is it too soon for a refresh?
-       var now = new Date().getTime();
+       var now = Date.now();
        if((now - mainchart.hiddenchart.last_updated) < (mainchart.update_every * 10 * 1000) || (now - mainchart.hiddenchart.last_updated) < (mainchart.hiddenchart.group * mainchart.hiddenchart.update_every * 1000)) {
                if(typeof doNext == "function") doNext();
                return;
@@ -319,7 +319,7 @@ function refreshHiddenChart(doNext) {
                }
 
                mainchart.dashboard.draw(mainchart.control_data);
-               mainchart.hiddenchart.last_updated = new Date().getTime();
+               mainchart.hiddenchart.last_updated = Date.now();
                mainchart.hiddenchart.refreshCount++;
        })
        .always(function() {
@@ -583,7 +583,7 @@ function playGraphs() {
        $('.global_play_button').button('play');
 
        // check if the thread died due to a javascript error
-       var now = new Date().getTime();
+       var now = Date.now();
        if((now - last_refresh) > 60000) {
                // it died or never started
                //mylog('It seems the refresh thread died. Restarting it.');
@@ -607,7 +607,7 @@ function checkRefreshThread() {
                return;
        }
 
-       var now = new Date().getTime();
+       var now = Date.now();
        if(now - last_refresh > 60000) {
                mylog('Refresh thread died. Restarting it.');
                renderChartCallback();
@@ -619,7 +619,7 @@ function checkRefreshThread() {
 // never call it directly, or new javascript threads will be spawn
 var timeout = null;
 function renderChartCallback() {
-       last_refresh = new Date().getTime();
+       last_refresh = Date.now();
 
        if(!page_is_visible) {
                timeout = setTimeout(triggerRefresh, CHARTS_CHECK_NO_FOCUS);
@@ -635,7 +635,7 @@ function renderChartCallback() {
        }
 
        if(last_user_scroll) {
-               var now = new Date().getTime();
+               var now = Date.now();
                if((now - last_user_scroll) >= CHARTS_SCROLL_IDLE) {
                        last_user_scroll = 0;
                        mylog('Scrolling: resuming refresh...');
@@ -672,7 +672,7 @@ function triggerRefresh() {
        //mylog('triggerRefresh()');
 
        if(!page_is_visible || (refresh_mode == REFRESH_PAUSED && mode != MODE_MAIN)) {
-               last_refresh = new Date().getTime();
+               last_refresh = Date.now();
                timeout = setTimeout(triggerRefresh, CHARTS_REFRESH_IDLE);
                return;
        }
@@ -1028,7 +1028,7 @@ function initCharts() {
        var height = TARGET_THUMB_GRAPH_HEIGHT;
 
        window.onscroll = function (e) {
-               last_user_scroll = new Date().getTime();
+               last_user_scroll = Date.now();
                mylog('Scrolling: detected');
        }
 
index f1af0a67d2b7f5e27e62920879c05b84ebba309b..db0e456853c11772fe330bf6b03c264cfd9c04ee 100644 (file)
@@ -13,7 +13,7 @@ function canChartBeRefreshed(chart) {
        if(chart.chart && chart.chart.getSelection()[0]) return false;
 
        // is it too soon for a refresh?
-       var now = new Date().getTime();
+       var now = Date.now();
        if((now - chart.last_updated) < (chart.group * chart.update_every * 1000)) return false;
 
        // is the chart in the visible area?
@@ -79,7 +79,7 @@ function renderChart(chart, doNext) {
                if(chart.chart) {
                        chart.chart.draw(chart.datatable, chart.chartOptions);
                        chart.refreshCount++;
-                       chart.last_updated = new Date().getTime();
+                       chart.last_updated = Date.now();
                }
                else console.log('Cannot create chart for ' + chart.url);
        })
@@ -89,7 +89,7 @@ function renderChart(chart, doNext) {
                chart.chart = null;
                chart.refreshCount = 0;
                showChartIsLoading(chart.div, chart.name, chart.chartOptions.width, chart.chartOptions.height, "failed to refresh");
-               chart.last_updated = new Date().getTime();
+               chart.last_updated = Date.now();
        })
        .always(function() {
                if(typeof doNext == "function") doNext();
@@ -128,7 +128,7 @@ function calculateChartPointsToShow(c, divisor, maxtime, group, enable_curve) {
 
        if(!divisor) divisor = 2;
 
-       var before = c.before?c.before:new Date().getTime() / 1000;
+       var before = c.before?c.before:Date.now() / 1000;
        var after = c.after?c.after:c.first_entry_t;
 
        var dt = before - after;