added preload estimate quote usage

This commit is contained in:
ston1th 2022-10-11 23:03:46 +02:00
commit 088bd1f03e
5 changed files with 19 additions and 6 deletions

View file

@ -33,7 +33,16 @@ func (q *queue) Add(ph *PreloadHandler, name string, prio int) {
return
}
}
*q = append(*q, &Preload{Name: name, ph: ph})
p := &Preload{Name: name, ph: ph}
*q = append(*q, p)
file, err := ph.fs.Open(name)
if err == nil {
defer file.Close()
f, ok := file.(*File)
if ok {
p.Size = f.size()
}
}
q.Sort()
}

View file

@ -150,9 +150,10 @@ func (r *responseInterceptor) GetPaths(path string, filesystem *fs.FS, relative
return
}
func getPreloads(path string, filesystem *fs.FS) (dc dirContents) {
func getPreloads(path string, filesystem *fs.FS) (dc dirContents, size int64) {
dc.Base = path
for _, p := range filesystem.Preloads() {
size += p.Size
dc.Files = append(dc.Files, file{
Name: template.HTML(p.Name),
URI: template.HTML(urlencode(p.Name)),

View file

@ -36,7 +36,7 @@ func (ps *PlainServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
"client", r.RemoteAddr,
"method", r.Method,
"status", s.Status(),
"uri", r.URL.Path,
"uri", r.RequestURI,
)
}()
}

View file

@ -26,6 +26,7 @@ const (
type data struct {
QuotaCur float64
QuotaEst float64
QuotaMax float64
Paths dirContents
PathAnchor string
@ -58,7 +59,7 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
"client", r.RemoteAddr,
"method", r.Method,
"status", s.Status(),
"uri", r.URL.Path,
"uri", r.RequestURI,
)
}()
}
@ -118,10 +119,12 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if option == "preloads" {
h.Set(csp, indexCSP)
cur, max := fs.fs.QuotaUsage()
paths, size := getPreloads(p, fs.fs)
err = preloads.Execute(w, data{
QuotaCur: math.Round(float64(cur)/gib*100) / 100,
QuotaEst: math.Round(float64(cur+size)/gib*100) / 100,
QuotaMax: float64(max) / gib,
Paths: getPreloads(p, fs.fs),
Paths: paths,
})
if err != nil {
fs.log.Error(err, "error rendering preloads")

View file

@ -3,7 +3,7 @@
[+]: increase priority
[-]: decrease priority
[s]: stop preloading
Quota: {{.QuotaCur}} / {{.QuotaMax}} GiB
Quota: {{.QuotaCur}} ({{.QuotaEst}}) / {{.QuotaMax}} GiB
</pre>
<table>
<tr class="listitem">