Skip to content

Commit

Permalink
Small optimization in $stats
Browse files Browse the repository at this point in the history
  • Loading branch information
airforce270 committed Aug 17, 2024
1 parent 3b273c0 commit c0be83e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions commands/botinfo/botinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,22 @@ func stats(msg *base.IncomingMessage, args []arg.Arg) ([]*base.Message, error) {
return nil, fmt.Errorf("submetric failed: %w", err)
}

startPart := fmt.Sprintf("Airbot running on %s %s", sentenceCase(hostInfo.Platform), sentenceCase(hostInfo.OS))
var out strings.Builder
fmt.Fprintf(&out, "Airbot running on %s %s", sentenceCase(hostInfo.Platform), sentenceCase(hostInfo.OS))
if runningInDocker {
startPart += " (Docker)"
out.WriteString(" (Docker)")
}

parts := []string{
startPart,
fmt.Sprintf("bot uptime: %s", botUptime.Round(time.Second)),
fmt.Sprintf("system uptime: %s", (time.Duration(hostInfo.Uptime) * time.Second).Round(time.Second)),
fmt.Sprintf("CPU: %2.1f%%", cpuPercent),
fmt.Sprintf("RAM: %2.1f%%", memory.UsedPercent),
fmt.Sprintf("processed %d messages in %d channels in the last %d seconds", recentlyProcessedMessages, joinedChannels, int(recentlyProcessedMessagesInterval.Seconds())),
}
fmt.Fprintf(&out, ", bot uptime: %s", botUptime.Round(time.Second))
fmt.Fprintf(&out, ", system uptime: %s", (time.Duration(hostInfo.Uptime) * time.Second).Round(time.Second))
fmt.Fprintf(&out, ", CPU: %2.1f%%", cpuPercent)
fmt.Fprintf(&out, ", RAM: %2.1f%%", memory.UsedPercent)
fmt.Fprintf(&out, ", processed %d messages in %d channels in the last %d seconds", recentlyProcessedMessages, joinedChannels, int(recentlyProcessedMessagesInterval.Seconds()))

return []*base.Message{
{
Channel: msg.Message.Channel,
Text: strings.Join(parts, ", "),
Text: out.String(),
},
}, nil
}
Expand Down

0 comments on commit c0be83e

Please sign in to comment.