first draft of system statistics page (needs some more formatting work)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
module git.erbosoft.com/amy/amsterdam
|
||||
|
||||
go 1.25.0
|
||||
go 1.26
|
||||
|
||||
require (
|
||||
github.com/CloudyKit/jet/v6 v6.3.1
|
||||
@@ -9,6 +9,7 @@ require (
|
||||
github.com/bits-and-blooms/bitset v1.24.0
|
||||
github.com/derekparker/trie v0.0.0-20230829180723-39f4de51ef7d
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/dustin/go-humanize v1.0.1
|
||||
github.com/go-sql-driver/mysql v1.9.3
|
||||
github.com/hashicorp/golang-lru v1.0.2
|
||||
github.com/jmoiron/sqlx v1.4.0
|
||||
|
||||
@@ -19,6 +19,8 @@ github.com/derekparker/trie v0.0.0-20230829180723-39f4de51ef7d h1:hUWoLdw5kvo2xC
|
||||
github.com/derekparker/trie v0.0.0-20230829180723-39f4de51ef7d/go.mod h1:C7Es+DLenIpPc9J6IYw4jrK0h7S9bKj4DNl8+KxGEXU=
|
||||
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
|
||||
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
|
||||
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
|
||||
|
||||
@@ -113,6 +113,7 @@ func setupEcho() *echo.Echo {
|
||||
sysGroup.POST("/ipban/add", ui.AmWrap(AddIPBan))
|
||||
sysGroup.Match(GetAndPost, "/audit", ui.AmWrap(SystemAudit))
|
||||
sysGroup.Match(GetAndPost, "/import", ui.AmWrap(UserImport))
|
||||
sysGroup.GET("/sysstat", ui.AmWrap(SysStats))
|
||||
|
||||
// community group
|
||||
uiset2 := make([]echo.MiddlewareFunc, len(uiset), len(uiset)+1)
|
||||
@@ -206,9 +207,12 @@ func setupEcho() *echo.Echo {
|
||||
// ampool is the worker pool for one-shot background tasks.
|
||||
var ampool *util.WorkerPool
|
||||
|
||||
// SystemStartTime records the time since the system was started.
|
||||
var SystemStartTime time.Time
|
||||
|
||||
// main is Ye Olde Main Function.
|
||||
func main() {
|
||||
start := time.Now()
|
||||
SystemStartTime = time.Now()
|
||||
// Configure the system.
|
||||
config.SetupConfig()
|
||||
closer, err := database.SetupDb()
|
||||
@@ -250,7 +254,7 @@ func main() {
|
||||
database.AmStoreAudit(database.AmNewAudit(database.AuditShutdown, 0, myIP.String()))
|
||||
}()
|
||||
|
||||
stime := time.Since(start)
|
||||
stime := time.Since(SystemStartTime)
|
||||
log.Infof("Amsterdam %s startup sequence completed in %v", config.AMSTERDAM_VERSION, stime)
|
||||
|
||||
// Start server
|
||||
|
||||
+34
@@ -16,6 +16,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -25,6 +26,7 @@ import (
|
||||
"git.erbosoft.com/amy/amsterdam/ui"
|
||||
"git.erbosoft.com/amy/amsterdam/util"
|
||||
"github.com/CloudyKit/jet/v6"
|
||||
"github.com/dustin/go-humanize"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -809,3 +811,35 @@ func UserImport(ctxt ui.AmContext) (string, any) {
|
||||
ctxt.SetFrameTitle("Import Results")
|
||||
return "framed", "import_results.jet"
|
||||
}
|
||||
|
||||
/* SysStats displays system statistics.
|
||||
* Parameters:
|
||||
* ctxt - The AmContext for the request.
|
||||
* Returns:
|
||||
* Command string dictating what to be rendered.
|
||||
* Data as a parameter for the command string.
|
||||
*/
|
||||
func SysStats(ctxt ui.AmContext) (string, any) {
|
||||
if !database.AmTestPermission("Global.SysAdminAccess", ctxt.CurrentUser().BaseLevel) {
|
||||
return "error", ENOACCESS
|
||||
}
|
||||
|
||||
mstat := new(runtime.MemStats)
|
||||
runtime.ReadMemStats(mstat)
|
||||
ctxt.VarMap().Set("mstat", mstat)
|
||||
ctxt.VarMap().Set("numgo", runtime.NumGoroutine())
|
||||
ctxt.VarMap().Set("uptime", time.Since(SystemStartTime).String())
|
||||
ctxt.VarMap().Set("memAlloc", humanize.IBytes(mstat.Alloc))
|
||||
ctxt.VarMap().Set("memTotalAlloc", humanize.IBytes(mstat.TotalAlloc))
|
||||
ctxt.VarMap().Set("memSys", humanize.IBytes(mstat.Sys))
|
||||
ctxt.VarMap().Set("memHeapAlloc", humanize.IBytes(mstat.HeapAlloc))
|
||||
ctxt.VarMap().Set("memHeapSys", humanize.IBytes(mstat.HeapSys))
|
||||
ctxt.VarMap().Set("memHeapIdle", humanize.IBytes(mstat.HeapIdle))
|
||||
ctxt.VarMap().Set("memHeapInuse", humanize.IBytes(mstat.HeapInuse))
|
||||
ctxt.VarMap().Set("memHeapReleased", humanize.IBytes(mstat.HeapReleased))
|
||||
ctxt.VarMap().Set("memLastGCTime", time.Unix(0, int64(mstat.LastGC)).Format(time.RFC3339))
|
||||
ctxt.VarMap().Set("memTotalPause", fmt.Sprintf("%.3f ms", float64(mstat.PauseTotalNs)/1000/1000))
|
||||
ctxt.VarMap().Set("memGCPercent", fmt.Sprintf("%.5f%%", float64(mstat.GCCPUFraction)*100))
|
||||
ctxt.SetFrameTitle("System Statistics")
|
||||
return "framed", "sysstat.jet"
|
||||
}
|
||||
|
||||
@@ -54,6 +54,9 @@ menudefs:
|
||||
- text: "Import User Accounts"
|
||||
link: "/sysadmin/import"
|
||||
permission: "Global.SysAdminAccess"
|
||||
- text: "System Statistics"
|
||||
link: "/sysadmin/sysstat"
|
||||
permission: "Global.SysAdminAccess"
|
||||
- id: "communityadmin"
|
||||
title: "Community Administration:"
|
||||
subtitle: "[CNAME]"
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
{*
|
||||
* Amsterdam Web Communities System
|
||||
* Copyright (c) 2025-2026 Erbosoft Metaverse Design Solutions, All Rights Reserved
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*}
|
||||
<div class="p-4">
|
||||
<!-- Page Title -->
|
||||
<div class="mb-6">
|
||||
<h1 class="text-blue-800 text-4xl font-bold mb-2">System Statistics</h1>
|
||||
<hr class="border-2 border-gray-400 w-4/5 mb-6">
|
||||
</div>
|
||||
|
||||
<!-- Backlink -->
|
||||
<div class="mb-4">
|
||||
<a class="text-blue-700 hover:text-blue-900 text-sm flex items-center gap-2 w-fit" href="/sysadmin">
|
||||
<span>←</span> Return to System Administration Menu
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- General Statistics -->
|
||||
<h2 class="text-blue-800 text-2xl font-bold mb-2">General Statistics</h2>
|
||||
<div class="overflow-x-auto mb-2">
|
||||
<div class="bg-white border border-gray-300 rounded-lg overflow-hidden">
|
||||
<table class="w-xl space-x-4 table-fixed">
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Amsterdam Uptime</td>
|
||||
<td class="text-sm px-4">{{ uptime }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Active Goroutines</td>
|
||||
<td class="text-sm px-4">{{ numgo }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Memory Usage</td>
|
||||
<td class="text-sm px-4">{{ memAlloc }} allocated of {{ memTotalAlloc }} ({{ memSys }} from system)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Pointer Lookups</td>
|
||||
<td class="text-sm px-4">{{ mstat.Lookups }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Memory Allocations</td>
|
||||
<td class="text-sm px-4">{{ mstat.Mallocs }} mallocs, {{ mstat.Frees }} frees</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Heap Statistics -->
|
||||
<h2 class="text-blue-800 text-2xl font-bold mb-2">Heap Statistics</h2>
|
||||
<div class="overflow-x-auto mb-2">
|
||||
<div class="bg-white border border-gray-300 rounded-lg overflow-hidden">
|
||||
<table class="w-xl space-x-4 table-fixed">
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Heap Usage</td>
|
||||
<td class="text-sm px-4">{{ memHeapAlloc }} allocated ({{ memHeapSys }} from system)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Heap Activity</td>
|
||||
<td class="text-sm px-4">{{ memHeapIdle }} idle, {{ memHeapInuse }} in use, {{ memHeapReleased }} released to OS</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Heap Objects</td>
|
||||
<td class="text-sm px-4">{{ mstat.HeapObjects }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- System Allocations -->
|
||||
<h2 class="text-blue-800 text-2xl font-bold mb-2">System Allocations</h2>
|
||||
<div class="overflow-x-auto mb-2">
|
||||
<div class="bg-white border border-gray-300 rounded-lg overflow-hidden">
|
||||
<table class="w-xl space-x-4 table-fixed">
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Stack Usage</td>
|
||||
<td class="text-sm px-4">{{ mstat.StackInuse }} in use ({{ mstat.StackSys }} from system)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">MSpan Usage</td>
|
||||
<td class="text-sm px-4">{{ mstat.MSpanInuse }} in use ({{ mstat.MSpanSys }} from system)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">MCache Usage</td>
|
||||
<td class="text-sm px-4">{{ mstat.MCacheInuse }} in use ({{ mstat.MCacheSys }} from system)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Bucket Hashtable Usage</td>
|
||||
<td class="text-sm px-4">{{ mstat.BuckHashSys }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">GC Usage</td>
|
||||
<td class="text-sm px-4">{{ mstat.GCSys }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Miscellaneous Usage</td>
|
||||
<td class="text-sm px-4">{{ mstat.OtherSys }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- GC Statistics -->
|
||||
<h2 class="text-blue-800 text-2xl font-bold mb-2">GC Statistics</h2>
|
||||
<div class="overflow-x-auto mb-2">
|
||||
<div class="bg-white border border-gray-300 rounded-lg overflow-hidden">
|
||||
<table class="w-xl space-x-4 table-fixed">
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Next GC Run At</td>
|
||||
<td class="text-sm px-4">{{ mstat.NextGC }} bytes heap</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Last GC Run At</td>
|
||||
<td class="text-sm px-4">{{ memLastGCTime }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Total GC Pause Time</td>
|
||||
<td class="text-sm px-4">{{ memTotalPause }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">Total GCs</td>
|
||||
<td class="text-sm px-4">{{ mstat.NumGC }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="font-bold text-sm px-4">GC CPU Percent</td>
|
||||
<td class="text-sm px-4">{{ memGCPercent }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user