Added Metrics
This commit is contained in:
parent
6cd54f7005
commit
e66bd64a07
|
@ -13,3 +13,6 @@ DBFile = ./data.db
|
||||||
; Ob Fenster geöffnet werden sollen, oder nicht.
|
; Ob Fenster geöffnet werden sollen, oder nicht.
|
||||||
OpenWindows = false
|
OpenWindows = false
|
||||||
OpenBrowser = false
|
OpenBrowser = false
|
||||||
|
|
||||||
|
; Metrics
|
||||||
|
SaveMetrics = true
|
|
@ -13,3 +13,6 @@ DBFile = ./data.db
|
||||||
; Ob Fenster geöffnet werden sollen, oder nicht.
|
; Ob Fenster geöffnet werden sollen, oder nicht.
|
||||||
OpenWindows = true
|
OpenWindows = true
|
||||||
OpenBrowser = false
|
OpenBrowser = false
|
||||||
|
|
||||||
|
; Metrics
|
||||||
|
SaveMetrics = false
|
10
main.go
10
main.go
|
@ -53,6 +53,16 @@ func main() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if config.GetSaveMetrics() {
|
||||||
|
log.Info("Saving Metrics.")
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
models.AddMetric()
|
||||||
|
time.Sleep(60 * time.Second)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
// Windows
|
// Windows
|
||||||
if config.GetOpenWindows() {
|
if config.GetOpenWindows() {
|
||||||
go windows.OpenWindows()
|
go windows.OpenWindows()
|
||||||
|
|
|
@ -13,6 +13,7 @@ type Configuration struct {
|
||||||
Mode int
|
Mode int
|
||||||
OpenWindows bool
|
OpenWindows bool
|
||||||
OpenBrowser bool
|
OpenBrowser bool
|
||||||
|
SaveMetrics bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var siteConf = &Configuration{}
|
var siteConf = &Configuration{}
|
||||||
|
@ -59,3 +60,8 @@ func GetOpenWindows() bool {
|
||||||
func GetOpenBrowser() bool {
|
func GetOpenBrowser() bool {
|
||||||
return siteConf.OpenBrowser
|
return siteConf.OpenBrowser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetSaveMetrics returns whether to use metrics or not
|
||||||
|
func GetSaveMetrics() bool {
|
||||||
|
return siteConf.SaveMetrics
|
||||||
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ func DBinit() {
|
||||||
x.ShowSQL(false)
|
x.ShowSQL(false)
|
||||||
x.Logger().SetLevel(core.LOG_DEBUG)
|
x.Logger().SetLevel(core.LOG_DEBUG)
|
||||||
|
|
||||||
x.Sync(&Kofi{}, &Community{})
|
x.Sync(&Kofi{}, &Community{}, &Metric{})
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
29
pkg/models/metri.go
Normal file
29
pkg/models/metri.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user