Show database file size on info page
This commit is contained in:
parent
a03baca498
commit
f98df478bb
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -286,5 +287,11 @@ func (m *BookmarkManager) Stats() (entity.DBStats, error) {
|
||||
if err != nil && err != bolthold.ErrNotFound {
|
||||
return stats, fmt.Errorf("could not load stats: %s", err)
|
||||
}
|
||||
// get the DB size
|
||||
fi, err := os.Stat(m.db.file)
|
||||
if err != nil {
|
||||
return stats, fmt.Errorf("could not load db file size: %s", err)
|
||||
}
|
||||
stats.FileSize = int(fi.Size())
|
||||
return stats, nil
|
||||
}
|
||||
|
2
db/db.go
2
db/db.go
@ -10,6 +10,7 @@ import (
|
||||
|
||||
type DB struct {
|
||||
store *bolthold.Store
|
||||
file string
|
||||
}
|
||||
|
||||
func (db *DB) Open(path string) error {
|
||||
@ -21,6 +22,7 @@ func (db *DB) Open(path string) error {
|
||||
return fmt.Errorf("cannot open '%s' - %s", path, err)
|
||||
}
|
||||
db.store = store
|
||||
db.file = path
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
type DBStats struct {
|
||||
History map[time.Time]BookmarkInfo
|
||||
FileSize int
|
||||
Searches int
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,6 @@ func MemInfo() string {
|
||||
stats := runtime.MemStats{}
|
||||
runtime.ReadMemStats(&stats)
|
||||
|
||||
return fmt.Sprintf("%.3fMb", float64(stats.Alloc)/1024.0/1024.0)
|
||||
return fmt.Sprintf("%.1fMb", float64(stats.Alloc)/1024.0/1024.0)
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"golang.org/x/mod/semver"
|
||||
)
|
||||
|
||||
const Tag = "v0.0.32"
|
||||
const Tag = "v0.0.33"
|
||||
|
||||
type Info struct {
|
||||
Local struct {
|
||||
|
@ -1,12 +1,16 @@
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="large-12 cell">
|
||||
<div class="large-6 medium-12 cell">
|
||||
|
||||
<h5>System information</h5>
|
||||
<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>
|
||||
<tr><th>Database disk size</th><td>{{ niceSizeMB .stats.FileSize }}Mb</td></tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
<div class="large-6 medium-12 cell">
|
||||
|
||||
<h5>Release info</h5>
|
||||
{{ if not version.Remote.Valid }}
|
||||
|
@ -81,6 +81,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
template.FuncMap{
|
||||
"nicetime": niceTime,
|
||||
"niceURL": niceURL,
|
||||
"niceSizeMB": func(s int) string { return fmt.Sprintf("%.1f", float32(s)/1024/1024) },
|
||||
"join": strings.Join,
|
||||
"version": func() *version.Info { return &version.VersionInfo },
|
||||
"meminfo": meta.MemInfo,
|
||||
|
Loading…
x
Reference in New Issue
Block a user