2018-05-27 09:36:35 +00:00
|
|
|
package panel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"runtime"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
2019-04-19 06:36:26 +00:00
|
|
|
c "github.com/Azareal/Gosora/common"
|
2020-03-18 09:21:34 +00:00
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
2018-05-27 09:36:35 +00:00
|
|
|
)
|
|
|
|
|
2020-03-18 09:21:34 +00:00
|
|
|
func Debug(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
|
|
|
basePage, ferr := buildBasePage(w, r, user, "debug", "debug")
|
2018-05-27 09:36:35 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
|
|
|
}
|
|
|
|
|
|
|
|
goVersion := runtime.Version()
|
|
|
|
dbVersion := qgen.Builder.DbVersion()
|
2021-04-07 14:23:11 +00:00
|
|
|
upDur := time.Since(c.StartTime)
|
|
|
|
hours := int(upDur.Hours())
|
|
|
|
mins := int(upDur.Minutes())
|
|
|
|
secs := int(upDur.Seconds())
|
2019-10-12 22:49:08 +00:00
|
|
|
var uptime string
|
2018-05-27 09:36:35 +00:00
|
|
|
if hours > 24 {
|
|
|
|
days := hours / 24
|
|
|
|
hours -= days * 24
|
|
|
|
uptime += strconv.Itoa(days) + "d"
|
|
|
|
uptime += strconv.Itoa(hours) + "h"
|
|
|
|
} else if hours >= 1 {
|
2020-02-24 11:48:16 +00:00
|
|
|
mins -= hours * 60
|
2018-05-27 09:36:35 +00:00
|
|
|
uptime += strconv.Itoa(hours) + "h"
|
2020-02-24 11:48:16 +00:00
|
|
|
uptime += strconv.Itoa(mins) + "m"
|
|
|
|
} else if mins >= 1 {
|
|
|
|
secs -= mins * 60
|
|
|
|
uptime += strconv.Itoa(mins) + "m"
|
|
|
|
uptime += strconv.Itoa(secs) + "s"
|
2018-05-27 09:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dbStats := qgen.Builder.GetConn().Stats()
|
|
|
|
openConnCount := dbStats.OpenConnections
|
|
|
|
// Disk I/O?
|
|
|
|
// TODO: Fetch the adapter from Builder rather than getting it from a global?
|
2018-08-16 05:27:26 +00:00
|
|
|
goroutines := runtime.NumGoroutine()
|
|
|
|
cpus := runtime.NumCPU()
|
2021-04-07 14:23:11 +00:00
|
|
|
httpConns := c.ConnWatch.Count()
|
2020-02-23 09:08:47 +00:00
|
|
|
|
2021-05-03 00:45:39 +00:00
|
|
|
debugTasks := c.DebugPageTasks{c.Tasks.HalfSec.Count(), c.Tasks.Sec.Count(), c.Tasks.FifteenMin.Count(), c.Tasks.Hour.Count(), c.Tasks.Shutdown.Count()}
|
2018-08-16 05:27:26 +00:00
|
|
|
var memStats runtime.MemStats
|
|
|
|
runtime.ReadMemStats(&memStats)
|
2018-05-27 09:36:35 +00:00
|
|
|
|
2019-05-17 08:40:41 +00:00
|
|
|
var tlen, ulen, rlen int
|
2019-05-17 10:38:46 +00:00
|
|
|
var tcap, ucap, rcap int
|
2021-04-07 14:23:11 +00:00
|
|
|
tc := c.Topics.GetCache()
|
|
|
|
if tc != nil {
|
|
|
|
tlen, tcap = tc.Length(), tc.GetCapacity()
|
2019-05-13 09:17:44 +00:00
|
|
|
}
|
2021-04-07 14:23:11 +00:00
|
|
|
uc := c.Users.GetCache()
|
|
|
|
if uc != nil {
|
|
|
|
ulen, ucap = uc.Length(), uc.GetCapacity()
|
2019-05-13 09:17:44 +00:00
|
|
|
}
|
2021-04-07 14:23:11 +00:00
|
|
|
rc := c.Rstore.GetCache()
|
|
|
|
if rc != nil {
|
|
|
|
rlen, rcap = rc.Length(), rc.GetCapacity()
|
2019-05-17 08:40:41 +00:00
|
|
|
}
|
2019-05-13 09:17:44 +00:00
|
|
|
topicListThawed := c.TopicListThaw.Thawed()
|
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
debugCache := c.DebugPageCache{tlen, ulen, rlen, tcap, ucap, rcap, topicListThawed}
|
2019-06-03 00:35:25 +00:00
|
|
|
|
2019-06-09 03:21:48 +00:00
|
|
|
var fErr error
|
2019-10-12 22:49:08 +00:00
|
|
|
count := func(tbl string) int {
|
2019-06-09 03:21:48 +00:00
|
|
|
if fErr != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
c, err := qgen.NewAcc().Count(tbl).Total()
|
|
|
|
fErr = err
|
|
|
|
return c
|
2019-06-03 05:26:27 +00:00
|
|
|
}
|
2019-06-09 03:21:48 +00:00
|
|
|
|
2019-06-03 00:35:25 +00:00
|
|
|
// TODO: Call Count on an attachment store
|
2019-06-09 03:21:48 +00:00
|
|
|
attachs := count("attachments")
|
2019-06-03 00:35:25 +00:00
|
|
|
// TODO: Implement a PollStore and call Count on that instead
|
2019-06-09 03:21:48 +00:00
|
|
|
polls := count("polls")
|
2019-06-05 01:46:45 +00:00
|
|
|
|
2019-06-09 03:21:48 +00:00
|
|
|
loginLogs := count("login_logs")
|
|
|
|
regLogs := count("registration_logs")
|
|
|
|
modLogs := count("moderation_logs")
|
|
|
|
adminLogs := count("administration_logs")
|
2020-03-18 09:21:34 +00:00
|
|
|
|
2019-06-09 03:21:48 +00:00
|
|
|
views := count("viewchunks")
|
|
|
|
viewsAgents := count("viewchunks_agents")
|
|
|
|
viewsForums := count("viewchunks_forums")
|
|
|
|
viewsLangs := count("viewchunks_langs")
|
|
|
|
viewsReferrers := count("viewchunks_referrers")
|
|
|
|
viewsSystems := count("viewchunks_systems")
|
|
|
|
postChunks := count("postchunks")
|
|
|
|
topicChunks := count("topicchunks")
|
|
|
|
if fErr != nil {
|
2020-03-18 09:21:34 +00:00
|
|
|
return c.InternalError(fErr, w, r)
|
2019-06-03 00:35:25 +00:00
|
|
|
}
|
2019-06-09 03:21:48 +00:00
|
|
|
|
2020-03-18 09:21:34 +00:00
|
|
|
debugDatabase := c.DebugPageDatabase{c.Topics.Count(), c.Users.Count(), c.Rstore.Count(), c.Prstore.Count(), c.Activity.Count(), c.Likes.Count(), attachs, polls, loginLogs, regLogs, modLogs, adminLogs, views, viewsAgents, viewsForums, viewsLangs, viewsReferrers, viewsSystems, postChunks, topicChunks}
|
2019-06-01 12:31:48 +00:00
|
|
|
|
2019-10-12 22:49:08 +00:00
|
|
|
dirSize := func(path string) int {
|
2019-06-09 03:21:48 +00:00
|
|
|
if fErr != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
c, err := c.DirSize(path)
|
|
|
|
fErr = err
|
|
|
|
return c
|
2019-06-01 12:31:48 +00:00
|
|
|
}
|
2019-06-09 03:21:48 +00:00
|
|
|
|
|
|
|
staticSize := dirSize("./public/")
|
|
|
|
attachSize := dirSize("./attachs/")
|
|
|
|
uploadsSize := dirSize("./uploads/")
|
2021-03-24 08:08:37 +00:00
|
|
|
logsSize := dirSize(c.Config.LogDir)
|
2019-06-09 03:21:48 +00:00
|
|
|
backupsSize := dirSize("./backups/")
|
|
|
|
if fErr != nil {
|
2020-03-18 09:21:34 +00:00
|
|
|
return c.InternalError(fErr, w, r)
|
2019-06-01 12:31:48 +00:00
|
|
|
}
|
2021-04-07 14:23:11 +00:00
|
|
|
// TODO: How can we measure this without freezing up the entire page?
|
2020-02-23 09:08:47 +00:00
|
|
|
//gitSize, _ := c.DirSize("./.git")
|
|
|
|
gitSize := 0
|
2019-06-09 03:21:48 +00:00
|
|
|
|
2020-03-18 09:21:34 +00:00
|
|
|
debugDisk := c.DebugPageDisk{staticSize, attachSize, uploadsSize, logsSize, backupsSize, gitSize}
|
2019-06-01 12:31:48 +00:00
|
|
|
|
2021-04-07 14:23:11 +00:00
|
|
|
pi := c.PanelDebugPage{basePage, goVersion, dbVersion, uptime, openConnCount, qgen.Builder.GetAdapter().GetName(), goroutines, cpus, httpConns, debugTasks, memStats, debugCache, debugDatabase, debugDisk}
|
2019-05-13 09:17:44 +00:00
|
|
|
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_dashboard_right", "debug_page", "panel_debug", pi})
|
2018-05-27 09:36:35 +00:00
|
|
|
}
|
2021-01-02 21:46:24 +00:00
|
|
|
|
|
|
|
func DebugTasks(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
|
|
|
basePage, ferr := buildBasePage(w, r, user, "debug", "debug")
|
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
|
|
|
}
|
|
|
|
|
|
|
|
var debugTasks []c.PanelDebugTaskTask
|
|
|
|
|
|
|
|
pi := c.PanelDebugTaskPage{basePage, debugTasks}
|
|
|
|
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_dashboard_right", "debug_page", "panel_debug_task", pi})
|
|
|
|
}
|