$(document).ready(function() { renew(); setInterval(renew,5000); }); function renew(){ $.getJSON("renew.json",function(data){ console.log(data); $('#uptime').text(data.uptime.days+' days '+data.uptime.hours+'h '+data.uptime.minutes+'m'); $('#cpu_total').css('width',data.cpu+'%'); $('#cpu_total').text(data.cpu+'%'); danger('#cpu_total_handler',data.cpu); danger('#ram_usage_handler',data.mem_usage.ram_per); $('#ram').text('used '+data.mem_usage.ram[1]+'Gb from '+data.mem_usage.ram[0]+'Gb total'); $('#ram_usage').css('width',data.mem_usage.ram_per+'%'); $('#ram_usage').text(data.mem_usage.ram_per+'%'); danger('#swap_usage_handler',data.mem_usage.swap_per); $('#swap').text('used '+data.mem_usage.swap[1]+'Gb from '+data.mem_usage.swap[0]+'Gb total'); $('#swap_usage').css('width',data.mem_usage.swap_per+'%'); $('#swap_usage').text(data.mem_usage.swap_per+'%'); var disks=[] $.each(data.disks_usage, function(key, value){ disks.push('

'+key+' ('+value[4]+') used '+value[2]+'Gb from '+value[1]+'Gb total

'+value[0]+'%
'); }); $('#disks').html(disks.join('')); var interfaces=[] $.each(data.network, function(key, value){ ip=(data.interfaces[key])?(data.interfaces[key]):(''); interfaces.push('

'+key+' '+ip+'

Down: '+value[0]+'KB/s

Up: '+value[1]+'KB/s

'); }); $('#traffic').html(interfaces.join('')); removeNotify($('#notification')); }).fail(function() { createNotify('Connection lost!', $('#notification')); }); } function danger(bar,value){ if(value>50&&value<80){ $(bar).addClass("uk-progress-warning"); $(bar).removeClass("uk-progress-success"); $(bar).removeClass("uk-progress-danger"); } if(value<=50){ $(bar).removeClass("uk-progress-warning"); $(bar).addClass("uk-progress-success"); $(bar).removeClass("uk-progress-danger"); } if(value>=80){ $(bar).removeClass("uk-progress-warning"); $(bar).removeClass("uk-progress-success"); $(bar).addClass("uk-progress-danger"); } }