added preload estimate quote usage
This commit is contained in:
parent
0c1708e450
commit
088bd1f03e
5 changed files with 19 additions and 6 deletions
|
|
@ -33,7 +33,16 @@ func (q *queue) Add(ph *PreloadHandler, name string, prio int) {
|
||||||
return
|
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()
|
q.Sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,9 +150,10 @@ func (r *responseInterceptor) GetPaths(path string, filesystem *fs.FS, relative
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPreloads(path string, filesystem *fs.FS) (dc dirContents) {
|
func getPreloads(path string, filesystem *fs.FS) (dc dirContents, size int64) {
|
||||||
dc.Base = path
|
dc.Base = path
|
||||||
for _, p := range filesystem.Preloads() {
|
for _, p := range filesystem.Preloads() {
|
||||||
|
size += p.Size
|
||||||
dc.Files = append(dc.Files, file{
|
dc.Files = append(dc.Files, file{
|
||||||
Name: template.HTML(p.Name),
|
Name: template.HTML(p.Name),
|
||||||
URI: template.HTML(urlencode(p.Name)),
|
URI: template.HTML(urlencode(p.Name)),
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ func (ps *PlainServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
"client", r.RemoteAddr,
|
"client", r.RemoteAddr,
|
||||||
"method", r.Method,
|
"method", r.Method,
|
||||||
"status", s.Status(),
|
"status", s.Status(),
|
||||||
"uri", r.URL.Path,
|
"uri", r.RequestURI,
|
||||||
)
|
)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ const (
|
||||||
|
|
||||||
type data struct {
|
type data struct {
|
||||||
QuotaCur float64
|
QuotaCur float64
|
||||||
|
QuotaEst float64
|
||||||
QuotaMax float64
|
QuotaMax float64
|
||||||
Paths dirContents
|
Paths dirContents
|
||||||
PathAnchor string
|
PathAnchor string
|
||||||
|
|
@ -58,7 +59,7 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
"client", r.RemoteAddr,
|
"client", r.RemoteAddr,
|
||||||
"method", r.Method,
|
"method", r.Method,
|
||||||
"status", s.Status(),
|
"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" {
|
if option == "preloads" {
|
||||||
h.Set(csp, indexCSP)
|
h.Set(csp, indexCSP)
|
||||||
cur, max := fs.fs.QuotaUsage()
|
cur, max := fs.fs.QuotaUsage()
|
||||||
|
paths, size := getPreloads(p, fs.fs)
|
||||||
err = preloads.Execute(w, data{
|
err = preloads.Execute(w, data{
|
||||||
QuotaCur: math.Round(float64(cur)/gib*100) / 100,
|
QuotaCur: math.Round(float64(cur)/gib*100) / 100,
|
||||||
|
QuotaEst: math.Round(float64(cur+size)/gib*100) / 100,
|
||||||
QuotaMax: float64(max) / gib,
|
QuotaMax: float64(max) / gib,
|
||||||
Paths: getPreloads(p, fs.fs),
|
Paths: paths,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.log.Error(err, "error rendering preloads")
|
fs.log.Error(err, "error rendering preloads")
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
[+]: increase priority
|
[+]: increase priority
|
||||||
[-]: decrease priority
|
[-]: decrease priority
|
||||||
[s]: stop preloading
|
[s]: stop preloading
|
||||||
Quota: {{.QuotaCur}} / {{.QuotaMax}} GiB
|
Quota: {{.QuotaCur}} ({{.QuotaEst}}) / {{.QuotaMax}} GiB
|
||||||
</pre>
|
</pre>
|
||||||
<table>
|
<table>
|
||||||
<tr class="listitem">
|
<tr class="listitem">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue