Added Metrics

This commit is contained in:
kolaente 2019-09-14 19:15:41 +02:00
parent 6cd54f7005
commit e66bd64a07
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
6 changed files with 53 additions and 2 deletions

View File

@ -13,3 +13,6 @@ DBFile = ./data.db
; Ob Fenster geöffnet werden sollen, oder nicht.
OpenWindows = false
OpenBrowser = false
; Metrics
SaveMetrics = true

View File

@ -12,4 +12,7 @@ Interface = 127.0.0.1:8080
DBFile = ./data.db
; Ob Fenster geöffnet werden sollen, oder nicht.
OpenWindows = true
OpenBrowser = false
OpenBrowser = false
; Metrics
SaveMetrics = false

10
main.go
View File

@ -53,6 +53,16 @@ func main() {
}
}()
if config.GetSaveMetrics() {
log.Info("Saving Metrics.")
go func() {
for {
models.AddMetric()
time.Sleep(60 * time.Second)
}
}()
}
// Windows
if config.GetOpenWindows() {
go windows.OpenWindows()

View File

@ -13,6 +13,7 @@ type Configuration struct {
Mode int
OpenWindows bool
OpenBrowser bool
SaveMetrics bool
}
var siteConf = &Configuration{}
@ -59,3 +60,8 @@ func GetOpenWindows() bool {
func GetOpenBrowser() bool {
return siteConf.OpenBrowser
}
// GetSaveMetrics returns whether to use metrics or not
func GetSaveMetrics() bool {
return siteConf.SaveMetrics
}

View File

@ -22,7 +22,7 @@ func DBinit() {
x.ShowSQL(false)
x.Logger().SetLevel(core.LOG_DEBUG)
x.Sync(&Kofi{}, &Community{})
x.Sync(&Kofi{}, &Community{}, &Metric{})
return
}

29
pkg/models/metri.go Normal file
View File

@ -0,0 +1,29 @@
package models
import "github.com/labstack/gommon/log"
type Metric struct {
ID int64 `xorm:"pk autoincr" json:"id" form:"id"`
Kcoins int64 `xorm:"bigint(11)"`
CommunityID int64 `xorm:"bigint(11)"`
CreatedUnix int64 `xorm:"created"`
}
func AddMetric() {
allCommunites := []Community{}
err := x.Find(&allCommunites)
if err != nil {
log.Error("Error getting metric data", err)
}
for _, community := range allCommunites {
m := Metric{
Kcoins: community.KCoins,
CommunityID: community.ID,
}
_, err := x.Insert(m)
if err != nil {
log.Error("Error saving metrics", err)
}
}
}