Last active
August 29, 2015 14:09
-
-
Save fndiaz/4b71ff242e54019feea7 to your computer and use it in GitHub Desktop.
Json with Ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//varialvel_json={"load": {"l2": 1.07, "l3": 0.83, "l1": 0.83}, "discos": {"/": {"used": 21804589056, "percent": 28.5, "free": 50897387520, "fstype": "ext4", "device": "/dev/sda5", "total": 76617515008}}, "memory": {"virtual_memory": {"used": 3819962368, "cached": 1232351232, "percent": 60.5, "free": 289218560, "total": 4109180928, "buffers": 100450304}, "swap_memory": {"total": 2048913408, "percent": 0.0, "free": 2048913408, "used": 0}}} | |
function poll() { //poll | |
$.ajax({ | |
method: "get", | |
url: "{{=URL(a='projeto', c='initial', f='consulta_server')}}", | |
dataType: "json", | |
success: function(lista){ //success | |
//alert(lista['memory']['virtual_memory']['used']) | |
jQuery.each( lista, function( i, val ) { //loop Master | |
//alert(i) | |
//alert(val) | |
$("#load1").text(lista['load']['l1']); | |
$("#load2").text(lista['load']['l2']); | |
$("#load3").text(lista['load']['l3']); | |
//setnado valor google graph | |
data.setValue(0, 1, lista['load']['l1']); | |
chart.draw(data, options); | |
if (i == 'discos') { //if discos | |
//alert('entrou discos') | |
var discos = val | |
for (var item in discos) { | |
if (item == '/'){ | |
$("#discos_total").text(discos[item]['total']); | |
$("#discos_used").text(discos[item]['used']); | |
$("#discos_free").text(discos[item]['free']); | |
$("#discos_fstype").text(discos[item]['fstype']); | |
$("#discos_device").text(discos[item]['device']); | |
$("#discos_percent").text(discos[item]['percent']); | |
$('#bar_barra').css('width', discos[item]['percent']+"%"); | |
} | |
} | |
} //if discos | |
if (i == 'memory') { //if memory | |
//alert('entrou mem') | |
var memory = val | |
for (var item in memory) { | |
if (item == 'virtual_memory'){ | |
$("#mem_total").text(memory[item]['total']); | |
$("#mem_used").text(memory[item]['used']); | |
$("#mem_free").text(memory[item]['free']); | |
$("#mem_cached").text(memory[item]['cached']); | |
$("#mem_percent").text(memory[item]['percent']); | |
$("#mem_buffers").text(memory[item]['buffers']); | |
$('#bar_mem').css('width', memory[item]['percent']+"%"); | |
} | |
if (item == 'swap_memory'){ | |
$("#swap_total").text(memory[item]['total']); | |
$("#swap_used").text(memory[item]['used']); | |
$("#swap_free").text(memory[item]['free']); | |
$("#swap_percent").text(memory[item]['percent']); | |
$('#bar_swap').css('width', memory[item]['percent']+"%"); | |
} | |
} | |
} //if memory | |
});//loop master | |
} //success | |
});//ajax | |
} //poll | |
setInterval(poll, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment