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"
|
2018-10-27 03:21:02 +00:00
|
|
|
"github.com/Azareal/Gosora/query_gen"
|
2018-05-27 09:36:35 +00:00
|
|
|
)
|
|
|
|
|
2019-04-19 06:36:26 +00:00
|
|
|
func Debug(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError {
|
2018-06-17 07:28:18 +00:00
|
|
|
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()
|
|
|
|
var uptime string
|
2019-04-19 06:36:26 +00:00
|
|
|
upDuration := time.Since(c.StartTime)
|
2018-05-27 09:36:35 +00:00
|
|
|
hours := int(upDuration.Hours())
|
|
|
|
minutes := int(upDuration.Minutes())
|
|
|
|
if hours > 24 {
|
|
|
|
days := hours / 24
|
|
|
|
hours -= days * 24
|
|
|
|
uptime += strconv.Itoa(days) + "d"
|
|
|
|
uptime += strconv.Itoa(hours) + "h"
|
|
|
|
} else if hours >= 1 {
|
|
|
|
uptime += strconv.Itoa(hours) + "h"
|
|
|
|
}
|
|
|
|
uptime += strconv.Itoa(minutes) + "m"
|
|
|
|
|
|
|
|
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()
|
|
|
|
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
|
2019-05-13 09:17:44 +00:00
|
|
|
tcache := c.Topics.GetCache()
|
|
|
|
if tcache != nil {
|
|
|
|
tlen = tcache.Length()
|
2019-05-17 10:38:46 +00:00
|
|
|
tcap = tcache.GetCapacity()
|
2019-05-13 09:17:44 +00:00
|
|
|
}
|
|
|
|
ucache := c.Users.GetCache()
|
|
|
|
if ucache != nil {
|
|
|
|
ulen = ucache.Length()
|
2019-05-17 10:38:46 +00:00
|
|
|
ucap = ucache.GetCapacity()
|
2019-05-13 09:17:44 +00:00
|
|
|
}
|
2019-05-17 08:40:41 +00:00
|
|
|
rcache := c.Rstore.GetCache()
|
|
|
|
if rcache != nil {
|
|
|
|
rlen = rcache.Length()
|
2019-05-17 10:38:46 +00:00
|
|
|
rcap = rcache.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-03 05:26:27 +00:00
|
|
|
var count = func(tbl string) (int, error) {
|
|
|
|
return qgen.NewAcc().Count(tbl).Total()
|
|
|
|
}
|
2019-06-03 00:35:25 +00:00
|
|
|
// TODO: Implement a LikeStore and call Count on that instead
|
2019-06-03 05:26:27 +00:00
|
|
|
likes, err := count("likes")
|
2019-06-03 00:35:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
// TODO: Call Count on an attachment store
|
2019-06-03 05:26:27 +00:00
|
|
|
attachs, err := count("attachments")
|
2019-06-03 00:35:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
// TODO: Implement a PollStore and call Count on that instead
|
2019-06-03 05:26:27 +00:00
|
|
|
polls, err := count("polls")
|
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
2019-06-05 01:46:45 +00:00
|
|
|
|
|
|
|
loginLogs, err := count("login_logs")
|
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
regLogs, err := count("registration_logs")
|
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
modLogs, err := count("moderation_logs")
|
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
adminLogs, err := count("administration_logs")
|
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
|
2019-06-03 05:26:27 +00:00
|
|
|
views, err := count("viewchunks")
|
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
viewsAgents, err := count("viewchunks_agents")
|
2019-06-03 00:35:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
2019-06-03 05:26:27 +00:00
|
|
|
viewsForums, err := count("viewchunks_forums")
|
2019-06-03 00:35:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
2019-06-03 05:26:27 +00:00
|
|
|
viewsLangs, err := count("viewchunks_langs")
|
2019-06-03 00:35:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
2019-06-03 05:26:27 +00:00
|
|
|
viewsReferrers, err := count("viewchunks_referrers")
|
2019-06-03 00:35:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
2019-06-03 05:26:27 +00:00
|
|
|
viewsSystems, err := count("viewchunks_systems")
|
2019-06-03 00:35:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
2019-06-03 05:26:27 +00:00
|
|
|
postChunks, err := count("postchunks")
|
2019-06-03 00:35:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
2019-06-03 05:26:27 +00:00
|
|
|
topicChunks, err := count("topicchunks")
|
2019-06-03 00:35:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
2019-06-05 01:46:45 +00:00
|
|
|
debugDatabase := c.DebugPageDatabase{c.Topics.Count(),c.Users.Count(),c.Rstore.Count(),c.Prstore.Count(),c.Activity.Count(),likes,attachs,polls,loginLogs,regLogs,modLogs,adminLogs,views,viewsAgents,viewsForums,viewsLangs,viewsReferrers,viewsSystems,postChunks,topicChunks}
|
2019-06-01 12:31:48 +00:00
|
|
|
|
|
|
|
staticSize, err := c.DirSize("./public/")
|
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
attachSize, err := c.DirSize("./attachs/")
|
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
uploadsSize, err := c.DirSize("./uploads/")
|
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
logsSize, err := c.DirSize("./logs/")
|
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
backupsSize, err := c.DirSize("./backups/")
|
|
|
|
if err != nil {
|
|
|
|
return c.InternalError(err,w,r)
|
|
|
|
}
|
|
|
|
debugDisk := c.DebugPageDisk{staticSize,attachSize,uploadsSize,logsSize,backupsSize}
|
|
|
|
|
|
|
|
pi := c.PanelDebugPage{basePage, goVersion, dbVersion, uptime, openConnCount, qgen.Builder.GetAdapter().GetName(), goroutines, cpus, 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
|
|
|
}
|