Add server transfer speed too footer

This commit is contained in:
2024-09-09 23:59:04 +02:00
parent 239c0c6523
commit f1db1dab14
3 changed files with 81 additions and 21 deletions

View File

@@ -61,6 +61,7 @@ function resetMenu() {
<div style="display: inline-block; margin: 0 8px;">
Pixeldrain is a product by <a href="//fornaxian.tech" target="_blank">Fornaxian Technologies</a>
</div>
<br/>
<div style="display: inline-block; margin: 0 8px;">
<a href="https://www.patreon.com/pixeldrain" target="_blank">{{template `patreon.svg` .}} Patreon</a> |
<a href="https://twitter.com/Fornax96" target="_blank">{{template `twitter.svg` .}} Twitter</a> |
@@ -69,6 +70,13 @@ function resetMenu() {
<a href="https://mastodon.social/web/@fornax" target="_blank">{{template `mastodon.svg` .}} Mastodon</a>
</div>
<br/>
<div style="display: inline-block; margin: 0 8px;">
{{$speed := .PixelAPI.GetMiscClusterSpeed}}
Server speed: {{ formatDataBits $speed.ServerTX }}ps |
Cache cluster: {{ formatDataBits $speed.CacheTX }}ps |
Storage cluster: {{ formatDataBits $speed.StorageTX }}ps
</div>
<br/>
<span class="small_footer_text" style="font-size: .75em; line-height: .75em;">
page rendered by {{.Hostname}}
</span>

View File

@@ -1,10 +1,30 @@
<script>
import { onMount } from "svelte";
import Discord from "../icons/Discord.svelte";
import Github from "../icons/Github.svelte";
import Mastodon from "../icons/Mastodon.svelte";
import Patreon from "../icons/Patreon.svelte";
import Reddit from "../icons/Reddit.svelte";
import Twitter from "../icons/Twitter.svelte";
import { formatDataVolumeBits } from "../util/Formatting.svelte";
let server_tx = 0
let cache_tx = 0
let storage_tx = 0
onMount(async () => {
try {
const resp = await fetch(window.api_endpoint+"/misc/cluster_speed")
if (resp.status >= 400) {
throw Error(await resp.text())
}
const speed = await resp.json()
server_tx = speed.server_tx
cache_tx = speed.cache_tx
storage_tx = speed.storage_tx
} catch (err) {
console.error("Failed to get speed stats", err)
}
})
</script>
<footer>
@@ -35,6 +55,12 @@ import Twitter from "../icons/Twitter.svelte";
</a>
</div>
<br/>
<div style="display: inline-block; margin: 0 8px;">
Server speed: {formatDataVolumeBits(server_tx, 4)}ps |
Cache cluster: {formatDataVolumeBits(cache_tx, 4)}ps |
Storage cluster: {formatDataVolumeBits(storage_tx, 4)}ps
</div>
<br/>
<span class="small_footer_text" style="font-size: .75em; line-height: .75em;">
page rendered by {window.server_hostname}
</span>

View File

@@ -133,6 +133,7 @@ func (tm *TemplateManager) ParseTemplates(silent bool) {
"mul": tm.mul,
"div": tm.div,
"formatData": tm.formatData,
"formatDataBits": tm.formatDataBits,
"formatSC": tm.formatSC,
"noescape": tm.noEscape,
"noescapeJS": tm.noEscapeJS,
@@ -238,6 +239,39 @@ func (tm *TemplateManager) div(a, b interface{}) float64 { return toFloat(a) / t
func (tm *TemplateManager) formatData(i interface{}) string {
return util.FormatData(detectInt(i))
}
func (tm *TemplateManager) formatDataBits(i interface{}) string {
var size = detectInt(i) * 8
var sizef = float64(size)
var fmtSize = func(n float64, u string) string {
var f string
if n >= 100 {
f = "%.1f"
} else if n >= 10 {
f = "%.2f"
} else {
f = "%.3f"
}
return fmt.Sprintf(f+" "+u, n)
}
if size >= 1e18 {
// An exabyte is the largest volume of data you can express in a signed
// 64-bit integer
return fmtSize(sizef/1e18, "Eb")
} else if sizef >= 1e15 {
return fmtSize(sizef/1e15, "Pb")
} else if sizef >= 1e12 {
return fmtSize(sizef/1e12, "Tb")
} else if sizef >= 1e9 {
return fmtSize(sizef/1e9, "Gb")
} else if sizef >= 1e6 {
return fmtSize(sizef/1e6, "Mb")
} else if sizef >= 1e3 {
return fmtSize(sizef/1e3, "kb")
}
return fmt.Sprintf("%.0f b", sizef)
}
func (tm *TemplateManager) formatSC(amt float64) string {
var fmtSize = func(n float64, u string) string {
var f string
@@ -250,14 +284,6 @@ func (tm *TemplateManager) formatSC(amt float64) string {
}
return fmt.Sprintf(f+" "+u, n)
}
// if amt >= 1e12 {
// return fmtSize(amt/1e12, "TS")
// } else if amt >= 1e9 {
// return fmtSize(amt/1e9, "GS")
// } else if amt >= 1e6 {
// return fmtSize(amt/1e6, "MS")
// } else if amt >= 1e3 {
// return fmtSize(amt/1e3, "KS")
if amt >= 1 {
return fmtSize(amt, "SC")
} else if amt >= 1e-3 {