Web UI -- persistent stats by writing them into stats.json at exit

This commit is contained in:
Eugene Bujak
2018-10-04 02:17:37 +03:00
parent c6eabb5b67
commit 51ec58b0ce
4 changed files with 125 additions and 56 deletions

18
app.go
View File

@@ -6,6 +6,7 @@ import (
"net"
"net/http"
"os"
"os/signal"
"path/filepath"
"strconv"
@@ -15,7 +16,12 @@ import (
// VersionString will be set through ldflags, contains current version
var VersionString = "undefined"
func cleanup() {
writeStats()
}
func main() {
c := make(chan os.Signal, 1)
log.Printf("AdGuard DNS web interface backend, version %s\n", VersionString)
box := packr.NewBox("build/static")
{
@@ -114,6 +120,18 @@ func main() {
log.Fatal(err)
}
err = loadStats()
if err != nil {
log.Fatal(err)
}
signal.Notify(c, os.Interrupt)
go func() {
<-c
cleanup()
os.Exit(1)
}()
address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort))
runStatsCollectors()