459d745cb1
add tasks to debug page ignore .git on debug page for speed add perfchunks table Renamed phrases (changed statistics to stats): panel_menu_stats panel_menu_stats_posts panel_menu_stats_topics panel_menu_stats_forums panel_menu_stats_routes panel_menu_stats_agents panel_menu_stats_systems panel_menu_stats_languages panel_menu_stats_referrers panel_menu_stats_memory panel_menu_stats_active_memory panel_menu_stats_perf panel_stats_views_head_suffix panel_stats_user_agents_head panel_stats_forums_head panel_stats_languages_head panel_stats_post_counts_head panel_stats_referrers_head panel_stats_routes_head panel_stats_operating_systems_head panel_stats_topic_counts_head panel_stats_requests_head panel_stats_memory_head panel_stats_active_memory_head panel_stats_spam_hide panel_stats_spam_show panel_stats_memory_type_total panel_stats_memory_type_stack panel_stats_memory_type_heap panel_stats_time_range_one_year panel_stats_time_range_three_months panel_stats_time_range_one_month panel_stats_time_range_one_week panel_stats_time_range_two_days panel_stats_time_range_one_day panel_stats_time_range_twelve_hours panel_stats_time_range_six_hours panel_stats_post_counts_chart_aria panel_stats_topic_counts_chart_aria panel_stats_requests_chart_aria panel_stats_memory_chart_aria panel_stats_details_head panel_stats_post_counts_table_aria panel_stats_topic_counts_table_aria panel_stats_route_views_table_aria panel_stats_requests_table_aria panel_stats_memory_table_aria panel_stats_views_suffix panel_stats_posts_suffix panel_stats_topics_suffix panel_stats_user_agents_no_user_agents panel_stats_forums_no_forums panel_stats_languages_no_languages panel_stats_post_counts_no_post_counts panel_stats_referrers_no_referrers panel_stats_routes_no_routes panel_stats_operating_systems_no_operating_systems panel_stats_memory_no_memory Added phrases: panel_debug_tasks panel_debug_tasks_half_second panel_debug_tasks_second panel_debug_tasks_fifteen_minute panel_debug_tasks_hour panel_debug_tasks_shutdown panel_stats_perf_head panel_stats_perf_low panel_stats_perf_high panel_stats_perf_avg You will need to run the updater / patcher for this commit.
126 lines
3.7 KiB
Go
126 lines
3.7 KiB
Go
package panel
|
|
|
|
import (
|
|
"net/http"
|
|
"runtime"
|
|
"strconv"
|
|
"time"
|
|
|
|
c "github.com/Azareal/Gosora/common"
|
|
"github.com/Azareal/Gosora/query_gen"
|
|
)
|
|
|
|
func Debug(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError {
|
|
basePage, ferr := buildBasePage(w, r, &user, "debug", "debug")
|
|
if ferr != nil {
|
|
return ferr
|
|
}
|
|
|
|
goVersion := runtime.Version()
|
|
dbVersion := qgen.Builder.DbVersion()
|
|
upDuration := time.Since(c.StartTime)
|
|
hours := int(upDuration.Hours())
|
|
minutes := int(upDuration.Minutes())
|
|
var uptime string
|
|
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?
|
|
goroutines := runtime.NumGoroutine()
|
|
cpus := runtime.NumCPU()
|
|
|
|
debugTasks := c.DebugPageTasks{c.ScheduledHalfSecondTaskCount(),c.ScheduledSecondTaskCount(),c.ScheduledFifteenMinuteTaskCount(),c.ScheduledHourTaskCount(),c.ShutdownTaskCount()}
|
|
var memStats runtime.MemStats
|
|
runtime.ReadMemStats(&memStats)
|
|
|
|
var tlen, ulen, rlen int
|
|
var tcap, ucap, rcap int
|
|
tcache := c.Topics.GetCache()
|
|
if tcache != nil {
|
|
tlen = tcache.Length()
|
|
tcap = tcache.GetCapacity()
|
|
}
|
|
ucache := c.Users.GetCache()
|
|
if ucache != nil {
|
|
ulen = ucache.Length()
|
|
ucap = ucache.GetCapacity()
|
|
}
|
|
rcache := c.Rstore.GetCache()
|
|
if rcache != nil {
|
|
rlen = rcache.Length()
|
|
rcap = rcache.GetCapacity()
|
|
}
|
|
topicListThawed := c.TopicListThaw.Thawed()
|
|
|
|
debugCache := c.DebugPageCache{tlen, ulen, rlen, tcap, ucap, rcap, topicListThawed}
|
|
|
|
var fErr error
|
|
count := func(tbl string) int {
|
|
if fErr != nil {
|
|
return 0
|
|
}
|
|
c, err := qgen.NewAcc().Count(tbl).Total()
|
|
fErr = err
|
|
return c
|
|
}
|
|
|
|
// TODO: Call Count on an attachment store
|
|
attachs := count("attachments")
|
|
// TODO: Implement a PollStore and call Count on that instead
|
|
polls := count("polls")
|
|
|
|
loginLogs := count("login_logs")
|
|
regLogs := count("registration_logs")
|
|
modLogs := count("moderation_logs")
|
|
adminLogs := count("administration_logs")
|
|
|
|
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 {
|
|
return c.InternalError(fErr,w,r)
|
|
}
|
|
|
|
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}
|
|
|
|
dirSize := func(path string) int {
|
|
if fErr != nil {
|
|
return 0
|
|
}
|
|
c, err := c.DirSize(path)
|
|
fErr = err
|
|
return c
|
|
}
|
|
|
|
staticSize := dirSize("./public/")
|
|
attachSize := dirSize("./attachs/")
|
|
uploadsSize := dirSize("./uploads/")
|
|
logsSize := dirSize("./logs/")
|
|
backupsSize := dirSize("./backups/")
|
|
if fErr != nil {
|
|
return c.InternalError(fErr,w,r)
|
|
}
|
|
//gitSize, _ := c.DirSize("./.git")
|
|
gitSize := 0
|
|
|
|
debugDisk := c.DebugPageDisk{staticSize,attachSize,uploadsSize,logsSize,backupsSize,gitSize}
|
|
|
|
pi := c.PanelDebugPage{basePage, goVersion, dbVersion, uptime, openConnCount, qgen.Builder.GetAdapter().GetName(), goroutines, cpus,debugTasks, memStats, debugCache, debugDatabase, debugDisk}
|
|
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_dashboard_right", "debug_page", "panel_debug", pi})
|
|
}
|