コード例 #1
0
ファイル: statistic.go プロジェクト: unaxfromsibiria/roolet
func (stat *Statistic) SendResult() {
	if (*stat).silent {
		return
	}
	var lines []string
	var label string
	for code, value := range (*stat).items {
		if itemLabel, exists := (*stat).labels[code]; exists {
			label = itemLabel
		} else {
			label = code
		}
		lines = append(lines, fmt.Sprintf("%s: %s", label, value))
	}
	sort.Strings(lines)
	allLines := make([]string, 1+len(lines))
	allLines[0] = fmt.Sprintf("Message count: %d", (*stat).msgCount)
	for index, ln := range lines {
		allLines[1+index] = ln
	}
	rllogger.OutputLines(rllogger.LogInfo, "statistic", &allLines)
	if len((*stat).outHandlers) > 0 {
		for _, outHandler := range (*stat).outHandlers {
			outHandler((*stat).lastSendTime, &allLines)
		}
	}
}
コード例 #2
0
ファイル: rlserver.go プロジェクト: unaxfromsibiria/roolet
func (stat *RlStatistic) Run(server *RlServer) {
	options := (*server).GetOption()
	(*stat).workerCount = options.Workers
	(*stat).used = options.Statistic
	(*stat).SetActive(options.Statistic)
	statItems := make(map[int]StatValueType)

	(*stat).items = statItems
	if options.Statistic {
		// print logs
		go func() {
			startTime := time.Now()
			for server.IsActive() {
				time.Sleep(time.Duration(server.option.StatisticCheckTime) * time.Second)
				var lines []string
				for item, value := range (*stat).items {
					lines = append(lines, fmt.Sprintf("%s : %f", statItemName(item), value))
				}
				rllogger.OutputLines(rllogger.LogInfo, "statistic", &lines)
				(*stat).update(float32(time.Since(startTime).Seconds()))
			}
			(*stat).SetActive(false)
		}()
	}
}