Skip to content

Commit

Permalink
Uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
dhcgn committed Jun 21, 2024
1 parent 5db7ea6 commit b7fcb71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func templateHandler(tmpl *template.Template, stats *stats.Stats) http.HandlerFu
Version: Version,
BuildTime: BuildTime,

Uptime: stats.GetUptime(),

StateData: stats.GetCurrentStats(),
}
tmpl.Execute(w, data)
Expand Down
8 changes: 8 additions & 0 deletions stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type StatsData struct {
Last24hHTTPErrorCount int
RateLimitHitCount int
RateLimitedIPs []RateLimitedIP
StartTime time.Time
}

type RateLimitedIP struct {
Expand All @@ -40,6 +41,9 @@ type RateLimitedIP struct {
func NewStats() *Stats {
return &Stats{
last24h: make(map[time.Time]StatsData),
data: StatsData{
StartTime: time.Now(),
},
}
}

Expand Down Expand Up @@ -127,3 +131,7 @@ func (s *Stats) updateLast24hStats() {
}
}
}

func (s *Stats) GetUptime() time.Duration {
return time.Since(s.data.StartTime)
}

0 comments on commit b7fcb71

Please sign in to comment.