move tool from gogs into appstats pkg
This commit is contained in:
parent
66b0945b70
commit
0286dcf214
39
admin.go
39
admin.go
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/writeas/impart"
|
"github.com/writeas/impart"
|
||||||
"github.com/writeas/web-core/auth"
|
"github.com/writeas/web-core/auth"
|
||||||
"github.com/writeas/web-core/log"
|
"github.com/writeas/web-core/log"
|
||||||
|
"github.com/writeas/writefreely/appstats"
|
||||||
"github.com/writeas/writefreely/config"
|
"github.com/writeas/writefreely/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -407,37 +408,37 @@ func handleAdminUpdateConfig(apper Apper, u *User, w http.ResponseWriter, r *htt
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateAppStats() {
|
func updateAppStats() {
|
||||||
sysStatus.Uptime = timeSincePro(appStartTime)
|
sysStatus.Uptime = appstats.TimeSincePro(appStartTime)
|
||||||
|
|
||||||
m := new(runtime.MemStats)
|
m := new(runtime.MemStats)
|
||||||
runtime.ReadMemStats(m)
|
runtime.ReadMemStats(m)
|
||||||
sysStatus.NumGoroutine = runtime.NumGoroutine()
|
sysStatus.NumGoroutine = runtime.NumGoroutine()
|
||||||
|
|
||||||
sysStatus.MemAllocated = fileSize(int64(m.Alloc))
|
sysStatus.MemAllocated = appstats.FileSize(int64(m.Alloc))
|
||||||
sysStatus.MemTotal = fileSize(int64(m.TotalAlloc))
|
sysStatus.MemTotal = appstats.FileSize(int64(m.TotalAlloc))
|
||||||
sysStatus.MemSys = fileSize(int64(m.Sys))
|
sysStatus.MemSys = appstats.FileSize(int64(m.Sys))
|
||||||
sysStatus.Lookups = m.Lookups
|
sysStatus.Lookups = m.Lookups
|
||||||
sysStatus.MemMallocs = m.Mallocs
|
sysStatus.MemMallocs = m.Mallocs
|
||||||
sysStatus.MemFrees = m.Frees
|
sysStatus.MemFrees = m.Frees
|
||||||
|
|
||||||
sysStatus.HeapAlloc = fileSize(int64(m.HeapAlloc))
|
sysStatus.HeapAlloc = appstats.FileSize(int64(m.HeapAlloc))
|
||||||
sysStatus.HeapSys = fileSize(int64(m.HeapSys))
|
sysStatus.HeapSys = appstats.FileSize(int64(m.HeapSys))
|
||||||
sysStatus.HeapIdle = fileSize(int64(m.HeapIdle))
|
sysStatus.HeapIdle = appstats.FileSize(int64(m.HeapIdle))
|
||||||
sysStatus.HeapInuse = fileSize(int64(m.HeapInuse))
|
sysStatus.HeapInuse = appstats.FileSize(int64(m.HeapInuse))
|
||||||
sysStatus.HeapReleased = fileSize(int64(m.HeapReleased))
|
sysStatus.HeapReleased = appstats.FileSize(int64(m.HeapReleased))
|
||||||
sysStatus.HeapObjects = m.HeapObjects
|
sysStatus.HeapObjects = m.HeapObjects
|
||||||
|
|
||||||
sysStatus.StackInuse = fileSize(int64(m.StackInuse))
|
sysStatus.StackInuse = appstats.FileSize(int64(m.StackInuse))
|
||||||
sysStatus.StackSys = fileSize(int64(m.StackSys))
|
sysStatus.StackSys = appstats.FileSize(int64(m.StackSys))
|
||||||
sysStatus.MSpanInuse = fileSize(int64(m.MSpanInuse))
|
sysStatus.MSpanInuse = appstats.FileSize(int64(m.MSpanInuse))
|
||||||
sysStatus.MSpanSys = fileSize(int64(m.MSpanSys))
|
sysStatus.MSpanSys = appstats.FileSize(int64(m.MSpanSys))
|
||||||
sysStatus.MCacheInuse = fileSize(int64(m.MCacheInuse))
|
sysStatus.MCacheInuse = appstats.FileSize(int64(m.MCacheInuse))
|
||||||
sysStatus.MCacheSys = fileSize(int64(m.MCacheSys))
|
sysStatus.MCacheSys = appstats.FileSize(int64(m.MCacheSys))
|
||||||
sysStatus.BuckHashSys = fileSize(int64(m.BuckHashSys))
|
sysStatus.BuckHashSys = appstats.FileSize(int64(m.BuckHashSys))
|
||||||
sysStatus.GCSys = fileSize(int64(m.GCSys))
|
sysStatus.GCSys = appstats.FileSize(int64(m.GCSys))
|
||||||
sysStatus.OtherSys = fileSize(int64(m.OtherSys))
|
sysStatus.OtherSys = appstats.FileSize(int64(m.OtherSys))
|
||||||
|
|
||||||
sysStatus.NextGC = fileSize(int64(m.NextGC))
|
sysStatus.NextGC = appstats.FileSize(int64(m.NextGC))
|
||||||
sysStatus.LastGC = fmt.Sprintf("%.1fs", float64(time.Now().UnixNano()-int64(m.LastGC))/1000/1000/1000)
|
sysStatus.LastGC = fmt.Sprintf("%.1fs", float64(time.Now().UnixNano()-int64(m.LastGC))/1000/1000/1000)
|
||||||
sysStatus.PauseTotalNs = fmt.Sprintf("%.1fs", float64(m.PauseTotalNs)/1000/1000/1000)
|
sysStatus.PauseTotalNs = fmt.Sprintf("%.1fs", float64(m.PauseTotalNs)/1000/1000/1000)
|
||||||
sysStatus.PauseNs = fmt.Sprintf("%.3fs", float64(m.PauseNs[(m.NumGC+255)%256])/1000/1000/1000)
|
sysStatus.PauseNs = fmt.Sprintf("%.3fs", float64(m.PauseNs[(m.NumGC+255)%256])/1000/1000/1000)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a MIT-style license that can be
|
// Use of this source code is governed by a MIT-style license that can be
|
||||||
// found in the LICENSE file of the Gogs project (github.com/gogs/gogs).
|
// found in the LICENSE file of the Gogs project (github.com/gogs/gogs).
|
||||||
|
|
||||||
package writefreely
|
package appstats
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -81,8 +81,8 @@ func computeTimeDiff(diff int64) (int64, string) {
|
||||||
return diff, diffStr
|
return diff, diffStr
|
||||||
}
|
}
|
||||||
|
|
||||||
// timeSincePro calculates the time interval and generate full user-friendly string.
|
// TimeSincePro calculates the time interval and generate full user-friendly string.
|
||||||
func timeSincePro(then time.Time) string {
|
func TimeSincePro(then time.Time) string {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
diff := now.Unix() - then.Unix()
|
diff := now.Unix() - then.Unix()
|
||||||
|
|
||||||
|
@ -121,8 +121,8 @@ func humanateBytes(s uint64, base float64, sizes []string) string {
|
||||||
return fmt.Sprintf(f+" %s", val, suffix)
|
return fmt.Sprintf(f+" %s", val, suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fileSize calculates the file size and generate user-friendly string.
|
// FileSize calculates the file size and generate user-friendly string.
|
||||||
func fileSize(s int64) string {
|
func FileSize(s int64) string {
|
||||||
sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"}
|
sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"}
|
||||||
return humanateBytes(uint64(s), 1024, sizes)
|
return humanateBytes(uint64(s), 1024, sizes)
|
||||||
}
|
}
|
Loading…
Reference in New Issue