Nathanwoodburn.github.io/templates/assets/js/info.min.js
Nathan Woodburn 5bed9dbbc8
All checks were successful
Build Docker / Build Image (push) Successful in 31s
feat: Add python server
2023-11-02 20:26:15 +11:00

1 line
1.3 KiB
JavaScript

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)))}