Show database statstics on the info page.
This commit is contained in:
parent
6f93f2ff50
commit
db72e8fb7d
@ -280,3 +280,12 @@ func (m *BookmarkManager) UpdateContent() {
|
|||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *BookmarkManager) Stats() (entity.DBStats, error) {
|
||||||
|
stats := entity.DBStats{}
|
||||||
|
err := m.db.store.Get("stats", &stats)
|
||||||
|
if err != nil && err != bolthold.ErrNotFound {
|
||||||
|
return stats, fmt.Errorf("could not load stats: %s", err)
|
||||||
|
}
|
||||||
|
return stats, nil
|
||||||
|
}
|
||||||
|
@ -32,3 +32,16 @@ func (stats DBStats) String() string {
|
|||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (stats DBStats) MostRecentBookmarkInfo() BookmarkInfo {
|
||||||
|
mostRecent := time.Time{}
|
||||||
|
for k := range stats.History {
|
||||||
|
if k.After(mostRecent) {
|
||||||
|
mostRecent = k
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !mostRecent.IsZero() {
|
||||||
|
return stats.History[mostRecent]
|
||||||
|
}
|
||||||
|
return BookmarkInfo{}
|
||||||
|
}
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
<div class="top-bar-right">
|
<div class="top-bar-right">
|
||||||
<ul class="menu">
|
<ul class="menu">
|
||||||
<li>
|
<li>
|
||||||
<a href="/releaseinfo">{{ version.Local.Tag }}
|
<a href="/info">{{ version.Local.Tag }}
|
||||||
{{ if version.UpgradeAvailable }}
|
{{ if version.UpgradeAvailable }}
|
||||||
❗
|
❗
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@ -63,8 +63,8 @@
|
|||||||
{{ template "config.html" . }}
|
{{ template "config.html" . }}
|
||||||
{{ else if eq .page "edit" }}
|
{{ else if eq .page "edit" }}
|
||||||
{{ template "edit.html" . }}
|
{{ template "edit.html" . }}
|
||||||
{{ else if eq .page "releaseinfo" }}
|
{{ else if eq .page "info" }}
|
||||||
{{ template "release_info.html" . }}
|
{{ template "info.html" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{/* template "foundation_sample.html" . */}}
|
{{/* template "foundation_sample.html" . */}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
<div class="grid-x grid-padding-x">
|
<div class="grid-x grid-padding-x">
|
||||||
<div class="large-12 cell">
|
<div class="large-12 cell">
|
||||||
|
|
||||||
<h5>Memory Usage</h5>
|
<h5>System information</h5>
|
||||||
<p>{{ meminfo }}</p>
|
<table>
|
||||||
|
<tr><th>Memory in use</th><td>{{ meminfo }}</td></tr>
|
||||||
|
<tr><th>Bookmarks</th><td>{{ .stats.MostRecentBookmarkInfo.Bookmarks }}</td></tr>
|
||||||
|
<tr><th>Words Indexed</th><td>{{ .stats.MostRecentBookmarkInfo.IndexedWords }}</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
<h5>Release info</h5>
|
<h5>Release info</h5>
|
||||||
{{ if not version.Remote.Valid }}
|
{{ if not version.Remote.Valid }}
|
||||||
|
@ -396,8 +396,12 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
r.GET("/releaseinfo", func(c *gin.Context) {
|
r.GET("/info", func(c *gin.Context) {
|
||||||
meta := gin.H{"page": "releaseinfo", "config": config}
|
dbStats, err := bmm.Stats()
|
||||||
|
if err != nil {
|
||||||
|
panic("could not load stats for info page")
|
||||||
|
}
|
||||||
|
meta := gin.H{"page": "info", "stats": dbStats, "config": config}
|
||||||
c.HTML(http.StatusOK,
|
c.HTML(http.StatusOK,
|
||||||
"_layout.html", meta,
|
"_layout.html", meta,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user