kon/pon/paths/status/status.go

48 lines
878 B
Go
Raw Permalink Normal View History

2024-04-01 21:09:41 +02:00
package status
import (
"encoding/json"
"kon/auth"
"kon/utils"
"os"
"github.com/mackerelio/go-osstat/memory"
"github.com/mackerelio/go-osstat/uptime"
"github.com/gofiber/fiber/v2"
)
type Status struct {
Hostname string
MemUsed uint64
MemTotal uint64
Uptime uint64
}
func GetStatus() Status {
hostname, err := os.Hostname()
utils.CheckError(err)
memory, err := memory.Get()
utils.CheckError(err)
uptime, err := uptime.Get()
utils.CheckError(err)
return Status{
Hostname: hostname,
MemUsed: memory.Used,
MemTotal: memory.Total,
Uptime: uint64(uptime) / 1000000000,
}
}
func HandleFunc(c *fiber.Ctx) error {
queryValue := c.Query("token")
if auth.VerifyToken(queryValue) {
statusJSON, err := json.Marshal(GetStatus())
utils.CheckError(err)
return c.SendString(string(statusJSON))
} else {
2024-04-01 22:04:54 +02:00
return c.SendString("Auth failed!")
2024-04-01 21:09:41 +02:00
}
}