Nathanwoodburn.github.io/assets/js/info.min.js

1 line
1.3 KiB
JavaScript
Raw Normal View History

2023-05-31 14:42:15 +10:00
onload=function(){dockerInfo(),systemUptime(),systemLoad()},setInterval((function(){dockerInfo(),systemUptime(),systemLoad(),console.log("Updated")}),1e3);const api="https://glances.woodburn.au/api/3/";function dockerInfo(){fetch(api+"docker").then((e=>e.json())).then((e=>{let n=[],t=[];for(let o=0;o<e.containers.length;o++)"running"===e.containers[o].Status?n.push(e.containers[o].name):t.push(e.containers[o].name);let o="Total Containers: "+e.containers.length+"<br>";o+="Running Containers: "+n.length+"<br>",o+="Stopped Containers: "+t.length+"<br><br>",document.getElementById("containers").innerHTML=o})).catch((e=>console.log(e)))}function systemUptime(){fetch(api+"uptime").then((e=>e.text())).then((e=>{let n=e.replace(/['"]+/g,"");document.getElementById("uptime").innerHTML=n})).catch((e=>console.log(e)))}function systemLoad(){fetch(api+"mem").then((e=>e.json())).then((e=>{let n=e.percent+"% RAM";document.getElementById("mem").innerHTML=n})).catch((e=>console.log(e))),fetch(api+"cpu").then((e=>e.json())).then((e=>{let n=e.total+"% CPU";document.getElementById("cpu").innerHTML=n})).catch((e=>console.log(e))),fetch(api+"fs").then((e=>e.json())).then((e=>{let n=e[0].percent+"% Disk",t=e[0].free;t/=1e9,t=t.toFixed(2),n+="<br>"+t+" GB Free",document.getElementById("disk").innerHTML=n})).catch((e=>console.log(e)))}