Merge branch 'main' into check_upload_size

check_upload_size
matlorr 1 year ago
commit 1050c8b24f

@ -122,25 +122,10 @@ function LandingPage() {
/** Parse `games/stats.csv` if present and display server capacity. */ /** Parse `games/stats.csv` if present and display server capacity. */
React.useEffect(() => { React.useEffect(() => {
fetch(`${window.location.origin}/data/stats`) const interval = setInterval(() => {
.then(response => {if (response.ok) { fetch_stats();
return response.text() } else {throw ""}}) }, 2000)
.then(data => { return () => clearInterval(interval)
// Parse the CSV content
const lines = data.split('\n');
const [header, line2] = lines;
if (!(header.replace(' ', '').startsWith("CPU,MEM"))) {
console.info("Not displaying server stats: received unexpected: ", header)
}
if (line2) {
let values = line2.split(',')
setUsageCPU(100 * parseFloat(values[0]));
setUsageMem(100 * parseFloat(values[1]));
}
}).catch(err => {
console.info('server stats unavailable')
console.debug(err)
})
}, []) }, [])
return <div className="landing-page"> return <div className="landing-page">
@ -193,8 +178,8 @@ function LandingPage() {
</p> </p>
</Trans> </Trans>
<p> <p>
{ usageMem >= 0 && <> {t("RAM")}: <strong>{usageMem} %</strong>{t(" used")}.<br/></> } { usageMem >= 0 && <> {t("RAM")}: <strong>{usageMem.toFixed(2)} %</strong>{t(" used")}.<br/></> }
{ usageCPU >= 0 && <> {t("CPU")}: <strong>{usageCPU} %</strong>{t(" used")}. </> } { usageCPU >= 0 && <> {t("CPU")}: <strong>{usageCPU.toFixed(2)} %</strong>{t(" used")}. </> }
</p> </p>
</div> </div>
</section> </section>
@ -254,6 +239,31 @@ function LandingPage() {
</footer> </footer>
</div> </div>
function fetch_stats() {
fetch(`${window.location.origin}/data/stats`)
.then(response => {
if (response.ok) {
return response.text();
} else { throw ""; }
})
.then(data => {
// Parse the CSV content
const lines = data.split('\n');
const [header, line2] = lines;
if (!(header.replace(' ', '').startsWith("CPU,MEM"))) {
console.info("Not displaying server stats: received unexpected: ", header);
}
if (line2) {
let values = line2.split(',');
setUsageCPU(100 * parseFloat(values[0]));
setUsageMem(100 * parseFloat(values[1]));
}
}).catch(err => {
console.info('server stats unavailable');
console.debug(err);
});
}
} }
export default LandingPage export default LandingPage

@ -3,7 +3,8 @@
"leanprover-community/nng4", "leanprover-community/nng4",
"hhu-adam/robo", "hhu-adam/robo",
"djvelleman/stg4", "djvelleman/stg4",
"trequetrum/lean4game-logic" "trequetrum/lean4game-logic",
"jadabouhawili/knightsandknaves-lean4game"
], ],
"languages": [ "languages": [

@ -24,7 +24,11 @@ You should see a white screen which shows import updates and eventually reports
Now you can immediately play the game at `adam.math.hhu.de/#/g/{USER}/{REPOSITORY}`! Now you can immediately play the game at `adam.math.hhu.de/#/g/{USER}/{REPOSITORY}`!
## 4. Main page ## 4. Update
To upload a new version of the game you will have to repeat 1. and 2. whenever you want to publish the updated version.
## 5. Main page
Adding games to the main page happens manually by the server maintainers. Tell us if you want us Adding games to the main page happens manually by the server maintainers. Tell us if you want us
to add a tile for your game! to add a tile for your game!

@ -3,10 +3,10 @@
# Load python interpreter # Load python interpreter
python=/usr/bin/python3 python=/usr/bin/python3
# Load python script # Load python script
cpu_usage=$L4G_DIR/lean4game/relay/cpu_usage.py cpu_usage=relay/cpu_usage.py
# Execute python script # Execute python script
cpu=$($python $cpu_usage) cpu=$($python $cpu_usage)
# Calculate memory usage by computing used_memory/total_memory # Calculate memory usage by computing 1 - %free_memory
mem=$(free | sed '2q;d' | awk '{print $3/$2}') mem=$(free | sed '2q;d' | awk '{print 1 - ($4/$2)}')
printf "CPU, MEM\n%.2f, %.2f\n" $cpu $mem printf "CPU, MEM\n%f, %f\n" $cpu $mem

Loading…
Cancel
Save