Пример #1
0
func sendServerDiagnostics() {
	var userCount int64
	var activeUserCount int64
	var teamCount int64

	if ucr := <-app.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil {
		userCount = ucr.Data.(int64)
	}

	if ucr := <-app.Srv.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil {
		activeUserCount = ucr.Data.(int64)
	}

	if tcr := <-app.Srv.Store.Team().AnalyticsTeamCount(); tcr.Err == nil {
		teamCount = tcr.Data.(int64)
	}

	utils.SendDiagnostic(utils.TRACK_ACTIVITY, map[string]interface{}{
		"registered_users": userCount,
		"active_users":     activeUserCount,
		"teams":            teamCount,
	})

	edition := model.BuildEnterpriseReady
	version := model.CurrentVersion
	database := utils.Cfg.SqlSettings.DriverName
	operatingSystem := runtime.GOOS

	utils.SendDiagnostic(utils.TRACK_VERSION, map[string]interface{}{
		"edition":          edition,
		"version":          version,
		"database":         database,
		"operating_system": operatingSystem,
	})
}
Пример #2
0
func diagnosticsJob() {
	go func() {
		for {
			if utils.Cfg.PrivacySettings.EnableDiagnostic && !model.IsOfficalBuild() {
				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)
		}
	}()
}