mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-25 16:08:25 +00:00
Show data as it comes in (cached for one hour)
This commit is contained in:
parent
d8f9c096f3
commit
85bb725eb6
42
main.go
42
main.go
@ -96,18 +96,49 @@ var cache map[string]interface{}
|
|||||||
var cacheDate string
|
var cacheDate string
|
||||||
var cacheMut sync.Mutex
|
var cacheMut sync.Mutex
|
||||||
|
|
||||||
|
func fileList() ([]string, error) {
|
||||||
|
files := make(map[string]string)
|
||||||
|
t0 := time.Now().Add(-24 * time.Hour).Format("20060102")
|
||||||
|
t1 := time.Now().Format("20060102")
|
||||||
|
|
||||||
|
dir := filepath.Join(*dbDir, t0)
|
||||||
|
gr, err := filepath.Glob(filepath.Join(dir, "*.json"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, f := range gr {
|
||||||
|
bn := filepath.Base(f)
|
||||||
|
files[bn] = f
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = filepath.Join(*dbDir, t1)
|
||||||
|
gr, err = filepath.Glob(filepath.Join(dir, "*.json"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, f := range gr {
|
||||||
|
bn := filepath.Base(f)
|
||||||
|
files[bn] = f
|
||||||
|
}
|
||||||
|
|
||||||
|
l := make([]string, 0, len(files))
|
||||||
|
for _, f := range files {
|
||||||
|
l = append(l, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
return l, nil
|
||||||
|
}
|
||||||
|
|
||||||
func reportHandler(w http.ResponseWriter, r *http.Request) {
|
func reportHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
yesterday := time.Now().Add(-24 * time.Hour).Format("20060102")
|
cd := time.Now().Format("20060102T15")
|
||||||
|
|
||||||
cacheMut.Lock()
|
cacheMut.Lock()
|
||||||
cacheMut.Unlock()
|
cacheMut.Unlock()
|
||||||
|
|
||||||
if cacheDate != yesterday {
|
if cacheDate != cd {
|
||||||
cache = make(map[string]interface{})
|
cache = make(map[string]interface{})
|
||||||
|
|
||||||
dir := filepath.Join(*dbDir, yesterday)
|
files, err := fileList()
|
||||||
|
|
||||||
files, err := filepath.Glob(filepath.Join(dir, "*.json"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Glob error", 500)
|
http.Error(w, "Glob error", 500)
|
||||||
return
|
return
|
||||||
@ -156,6 +187,7 @@ func reportHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cache = make(map[string]interface{})
|
cache = make(map[string]interface{})
|
||||||
|
cache["cache"] = cd
|
||||||
cache["nodes"] = nodes
|
cache["nodes"] = nodes
|
||||||
cache["versions"] = versions
|
cache["versions"] = versions
|
||||||
cache["platforms"] = platforms
|
cache["platforms"] = platforms
|
||||||
|
@ -29,7 +29,7 @@ found in the LICENSE file.
|
|||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h1>Syncthing Usage Data</h1>
|
<h1>Syncthing Usage Data</h1>
|
||||||
<p>
|
<p>
|
||||||
This is the aggregated usage report data for yesterday. Data based on <b>{{ report.nodes }}</b> nodes that have reported in.
|
This is the aggregated usage report data for today and yesterday. Data based on <b>{{ report.nodes }}</b> nodes that have reported in.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user