From 9d688821aa8bb8d766793aeaec6920f9985a30a3 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Thu, 1 Oct 2015 13:02:04 -0700 Subject: PLT-462 Adding diagnostic info --- mattermost.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'mattermost.go') diff --git a/mattermost.go b/mattermost.go index ff7b0f3f3..3e8b73e94 100644 --- a/mattermost.go +++ b/mattermost.go @@ -8,6 +8,8 @@ import ( "fmt" "os" "os/signal" + "runtime" + "strconv" "strings" "syscall" "time" @@ -61,6 +63,8 @@ func main() { manualtesting.InitManualTesting() } + diagnosticsJob() + // wait for kill signal before attempting to gracefully shutdown // the running service c := make(chan os.Signal) @@ -71,6 +75,53 @@ func main() { } } +func diagnosticsJob() { + go func() { + for { + if utils.Cfg.PrivacySettings.EnableDiagnostic && model.BuildNumber != "_BUILD_NUMBER_" { + if result := <-api.Srv.Store.System().Get(); result.Err == nil { + props := result.Data.(model.StringMap) + lastTime, _ := strconv.ParseInt(props["LastDiagnosticTime"], 10, 0) + currentTime := model.GetMillis() + + if (currentTime - lastTime) > 1000*60*60*24*7 { + l4g.Info("Sending error and diagnostic information to mattermost") + + id := props["DiagnosticId"] + if len(id) == 0 { + id = model.NewId() + systemId := &model.System{Name: "DiagnosticId", Value: id} + <-api.Srv.Store.System().Save(systemId) + } + + systemLastTime := &model.System{Name: "LastDiagnosticTime", Value: strconv.FormatInt(currentTime, 10)} + if lastTime == 0 { + <-api.Srv.Store.System().Save(systemLastTime) + } else { + <-api.Srv.Store.System().Update(systemLastTime) + } + + m := make(map[string]string) + m[utils.PROP_DIAGNOSTIC_ID] = id + m[utils.PROP_DIAGNOSTIC_BUILD] = model.CurrentVersion + "." + model.BuildNumber + m[utils.PROP_DIAGNOSTIC_DATABASE] = utils.Cfg.SqlSettings.DriverName + m[utils.PROP_DIAGNOSTIC_OS] = runtime.GOOS + m[utils.PROP_DIAGNOSTIC_CATEGORY] = utils.VAL_DIAGNOSTIC_CATEGORY_DEFALUT + + if ucr := <-api.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil { + m[utils.PROP_DIAGNOSTIC_USER_COUNT] = strconv.FormatInt(ucr.Data.(int64), 10) + } + + utils.SendDiagnostic(m) + } + } + } + + time.Sleep(time.Hour * 24) + } + }() +} + func parseCmds() { flag.Usage = func() { fmt.Fprintln(os.Stderr, usage) -- cgit v1.2.3-1-g7c22