var updateInterval = 60000, monitorEndPoint = 'http://eddn-monitor.ed-td.space:9091/', gatewayBottlePort = 8080, relayBottlePort = 9090, relays = [ 'eddn-gateway.elite-markets.net', 'eddn-gateway.ed-td.space' ]; // Must find a way to bind them to monitor var stats = { 'gateway' : {}, 'relay' : {} }; // Stats placeholder secondsToDurationString = function(seconds) { var hours = Math.floor(seconds / 3600); var minutes = Math.floor((seconds - (hours * 3600)) / 60); var seconds = seconds - (hours * 3600) - (minutes * 60); var days = 0; if (hours > 24) { days = Math.floor(hours / 24) hours = Math.floor((hours - days * 24) / 3600); } if (hours < 10) {hours = "0" + hours;} if (minutes < 10) {minutes = "0" + minutes;} if (seconds < 10) {seconds = "0" + seconds;} if (days > 0) { return days + "d " + hours + ":" + minutes + ":" + seconds; } else { return hours + ":" + minutes + ":" + seconds; } } var doUpdates = function(type){ $("select[name=" + type + "] option").each(function(){ var currentItem = $(this).html(), isSelected = $(this).is(':selected'); $.ajax({ dataType: "json", url: $(this).val(), success: function(data){ d = new Date(); stats[type][currentItem]['lastUpdate'] = d.toString("yyyy-MM-dd HH:mm:ss"); stats[type][currentItem]['last'] = data; if(isSelected) showStats(type, currentItem); var chart = $("#" + type + " .chart[data-name='" + currentItem + "']").highcharts(); shift = chart.get('inbound').data.length > 60; chart.get('inbound').addPoint([d.getTime(), (data['inbound'] || {})['1min'] || 0], true, shift); shift = chart.get('outbound').data.length > 60; chart.get('outbound').addPoint([d.getTime(), (data['outbound'] || {})['1min'] || 0], true, shift); if(type == 'gateway') { shift = chart.get('invalid').data.length > 60; chart.get('invalid').addPoint([d.getTime(), (data['invalid'] || {})['1min'] || 0], true, shift); } } }); }); }; var showStats = function(type, currentItem){ var el = $('#' + type), currentItemStats = stats[type][currentItem]['last']; el.find(".inbound_1min").html((currentItemStats['inbound'] || {})['1min'] || 0); el.find(".inbound_5min").html((currentItemStats["inbound"] || {})['5min'] || 0); el.find(".inbound_60min").html((currentItemStats["inbound"] || {})['60min'] || 0); if(type == 'gateway') { el.find(".invalid_1min").html((currentItemStats["invalid"] || {})['1min'] || 0); el.find(".invalid_5min").html((currentItemStats["invalid"] || {})['5min'] || 0); el.find(".invalid_60min").html((currentItemStats["invalid"] || {})['60min'] || 0); } el.find(".outbound_1min").html((currentItemStats["outbound"] || {})['1min'] || 0); el.find(".outbound_5min").html((currentItemStats["outbound"] || {})['5min'] || 0); el.find(".outbound_60min").html((currentItemStats["outbound"] || {})['60min'] || 0); el.find(".update_timestamp").html(stats[type][currentItem]['lastUpdate']); el.find(".version").html(currentItemStats['version'] || 'N/A'); if (currentItemStats['uptime']) el.find(".uptime").html(secondsToDurationString(currentItemStats['uptime'])); else el.find(".uptime").html('N/A'); el.find(".stat").removeClass("warning").each(function() { if ($(this).html() == "0") $(this).addClass("warning"); }); el.find(".chart").hide(); el.find(".chart[data-name='" + currentItem + "']").show(); $(window).trigger('resize'); // Fix wrong size in chart }; /** * Launch monitoring */ var start = function(){ Highcharts.setOptions({global: {useUTC: false}}); // Grab gateways from monitor $.ajax({ dataType: "json", url: monitorEndPoint + 'getGateways/', success: function(gateways){ gateways = gateways.sort(); $.each(gateways, function(k, gateway){ gateway = gateway.replace('tcp://', ''); gateway = gateway.replace(':8500', ''); $("select[name=gateway]").append($('