Add uptime to /stats
All checks were successful
CI / build (push) Successful in 4m0s

This commit is contained in:
Fijxu 2024-11-04 12:05:59 -03:00
parent 654610ecd3
commit 3b89ea41e7
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
2 changed files with 17 additions and 8 deletions

View file

@ -20,11 +20,13 @@ func videoplayback(w http.ResponseWriter, req *http.Request) {
mn := strings.Split(q.Get("mn"), ",")
if len(mvi) <= 0 {
w.WriteHeader(400)
io.WriteString(w, "No `mvi` in query parameters")
return
}
if len(mn) <= 0 {
w.WriteHeader(400)
io.WriteString(w, "No `mn` in query parameters")
return
}
@ -35,6 +37,7 @@ func videoplayback(w http.ResponseWriter, req *http.Request) {
parts := strings.Split(strings.ToLower(host), ".")
if len(parts) < 2 {
w.WriteHeader(400)
io.WriteString(w, "Invalid hostname.")
return
}
@ -49,6 +52,7 @@ func videoplayback(w http.ResponseWriter, req *http.Request) {
}
if disallowed {
w.WriteHeader(401)
io.WriteString(w, "Non YouTube domains are not supported.")
return
}

View file

@ -96,6 +96,8 @@ var version string
var h3s bool
var programInit = time.Now()
type ConnectionWatcher struct {
totalEstablished int64
established int64
@ -135,6 +137,7 @@ var cw ConnectionWatcher
type statusJson struct {
Version string `json:"version"`
Uptime time.Duration `json:"uptime"`
RequestCount int64 `json:"requestCount"`
RequestPerSecond int64 `json:"requestPerSecond"`
RequestPerMinute int64 `json:"requestPerMinute"`
@ -151,6 +154,7 @@ type statusJson struct {
var stats_ = statusJson{
Version: version + "-" + runtime.GOARCH,
Uptime: 0,
RequestCount: 0,
RequestPerSecond: 0,
RequestPerMinute: 0,
@ -182,6 +186,7 @@ func root(w http.ResponseWriter, req *http.Request) {
func stats(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
stats_.Uptime = time.Duration(time.Since(programInit).Seconds())
stats_.TotalEstablished = int64(cw.totalEstablished)
stats_.EstablishedConnections = int64(cw.established)
// stats_.ActiveConnections = int64(cw.active)