新增系统概况
This commit is contained in:
@@ -8,11 +8,13 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/george518/PPGo_Job/jobs"
|
"github.com/george518/PPGo_Job/jobs"
|
||||||
"github.com/george518/PPGo_Job/libs"
|
"github.com/george518/PPGo_Job/libs"
|
||||||
"github.com/george518/PPGo_Job/models"
|
"github.com/george518/PPGo_Job/models"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
//"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -111,7 +113,13 @@ func (self *HomeController) Start() {
|
|||||||
// this.Data["errLogs"] = errLogs
|
// this.Data["errLogs"] = errLogs
|
||||||
self.Data["jobs"] = jobList
|
self.Data["jobs"] = jobList
|
||||||
self.Data["cpuNum"] = runtime.NumCPU()
|
self.Data["cpuNum"] = runtime.NumCPU()
|
||||||
self.display()
|
|
||||||
|
//系统运行信息
|
||||||
|
|
||||||
|
fmt.Println(models.StartTime)
|
||||||
|
|
||||||
|
info := libs.SystemInfo(models.StartTime)
|
||||||
|
self.Data["sysInfo"] = info
|
||||||
|
|
||||||
self.Data["pageTitle"] = "系统概况"
|
self.Data["pageTitle"] = "系统概况"
|
||||||
self.display()
|
self.display()
|
||||||
|
|||||||
88
libs/file.go
Normal file
88
libs/file.go
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/************************************************************
|
||||||
|
** @Description: libs
|
||||||
|
** @Author: george hao
|
||||||
|
** @Date: 2018-08-13 11:17
|
||||||
|
** @Last Modified by: george hao
|
||||||
|
** @Last Modified time: 2018-08-13 11:17
|
||||||
|
*************************************************************/
|
||||||
|
package libs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Exist(path string) bool {
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
return err == nil || os.IsExist(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCurrentDirectory() (string, error) {
|
||||||
|
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return filepath.Clean(strings.Replace(dir, "\\", "/", -1)), nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsTextFile(data []byte) bool {
|
||||||
|
if len(data) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return strings.Contains(http.DetectContentType(data), "text/")
|
||||||
|
}
|
||||||
|
func IsImageFile(data []byte) bool {
|
||||||
|
return strings.Contains(http.DetectContentType(data), "image/")
|
||||||
|
}
|
||||||
|
func IsPDFFile(data []byte) bool {
|
||||||
|
return strings.Contains(http.DetectContentType(data), "application/pdf")
|
||||||
|
}
|
||||||
|
func IsVideoFile(data []byte) bool {
|
||||||
|
return strings.Contains(http.DetectContentType(data), "video/")
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
Byte = 1
|
||||||
|
KByte = Byte * 1024
|
||||||
|
MByte = KByte * 1024
|
||||||
|
GByte = MByte * 1024
|
||||||
|
TByte = GByte * 1024
|
||||||
|
PByte = TByte * 1024
|
||||||
|
EByte = PByte * 1024
|
||||||
|
)
|
||||||
|
|
||||||
|
var bytesSizeTable = map[string]uint64{
|
||||||
|
"b": Byte,
|
||||||
|
"kb": KByte,
|
||||||
|
"mb": MByte,
|
||||||
|
"gb": GByte,
|
||||||
|
"tb": TByte,
|
||||||
|
"pb": PByte,
|
||||||
|
"eb": EByte,
|
||||||
|
}
|
||||||
|
|
||||||
|
func logn(n, b float64) float64 {
|
||||||
|
return math.Log(n) / math.Log(b)
|
||||||
|
}
|
||||||
|
func humanateBytes(s uint64, base float64, sizes []string) string {
|
||||||
|
if s < 10 {
|
||||||
|
return fmt.Sprintf("%d B", s)
|
||||||
|
}
|
||||||
|
e := math.Floor(logn(float64(s), base))
|
||||||
|
suffix := sizes[int(e)]
|
||||||
|
val := float64(s) / math.Pow(base, math.Floor(e))
|
||||||
|
f := "%.0f"
|
||||||
|
if val < 10 {
|
||||||
|
f = "%.1f"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(f+" %s", val, suffix)
|
||||||
|
}
|
||||||
|
func FileSize(s int64) string {
|
||||||
|
sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"}
|
||||||
|
return humanateBytes(uint64(s), 1024, sizes)
|
||||||
|
}
|
||||||
65
libs/monitor.go
Normal file
65
libs/monitor.go
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/************************************************************
|
||||||
|
** @Description: libs
|
||||||
|
** @Author: george hao
|
||||||
|
** @Date: 2018-08-13 11:16
|
||||||
|
** @Last Modified by: george hao
|
||||||
|
** @Last Modified time: 2018-08-13 11:16
|
||||||
|
*************************************************************/
|
||||||
|
package libs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SystemInfo(startTime int64) map[string]interface{} {
|
||||||
|
|
||||||
|
var afterLastGC string
|
||||||
|
goNum := runtime.NumGoroutine()
|
||||||
|
cpuNum := runtime.NumCPU()
|
||||||
|
mstat := &runtime.MemStats{}
|
||||||
|
runtime.ReadMemStats(mstat)
|
||||||
|
now := time.Now().Unix()
|
||||||
|
//costTime := int(time.Now().Sub(startTime).Seconds())
|
||||||
|
costTime := int(now - startTime)
|
||||||
|
mb := 1024 * 1024
|
||||||
|
|
||||||
|
if mstat.LastGC != 0 {
|
||||||
|
afterLastGC = fmt.Sprintf("%.1fs", float64(time.Now().UnixNano()-int64(mstat.LastGC))/1000/1000/1000)
|
||||||
|
} else {
|
||||||
|
afterLastGC = "0"
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println()
|
||||||
|
//fmt.Println(startTime)
|
||||||
|
//fmt.Println(now)
|
||||||
|
//fmt.Println(costTime)
|
||||||
|
|
||||||
|
return map[string]interface{}{
|
||||||
|
"服务运行时间": fmt.Sprintf("%d天%d小时%d分%d秒", costTime/(3600*24), costTime%(3600*24)/3600, costTime%3600/60, costTime%(60)),
|
||||||
|
"goroute数量": goNum,
|
||||||
|
"cpu核心数": cpuNum,
|
||||||
|
|
||||||
|
"当前内存使用量": FileSize(int64(mstat.Alloc)),
|
||||||
|
"所有被分配的内存": FileSize(int64(mstat.TotalAlloc)),
|
||||||
|
"内存占用量": FileSize(int64(mstat.Sys)),
|
||||||
|
"指针查找次数": mstat.Lookups,
|
||||||
|
"内存分配次数": mstat.Mallocs,
|
||||||
|
"内存释放次数": mstat.Frees,
|
||||||
|
"距离上次GC时间": afterLastGC,
|
||||||
|
|
||||||
|
// "当前 Heap 内存使用量": file.FileSize(int64(mstat.HeapAlloc)),
|
||||||
|
// "Heap 内存占用量": file.FileSize(int64(mstat.HeapSys)),
|
||||||
|
// "Heap 内存空闲量": file.FileSize(int64(mstat.HeapIdle)),
|
||||||
|
// "正在使用的 Heap 内存": file.FileSize(int64(mstat.HeapInuse)),
|
||||||
|
// "被释放的 Heap 内存": file.FileSize(int64(mstat.HeapReleased)),
|
||||||
|
// "Heap 对象数量": mstat.HeapObjects,
|
||||||
|
|
||||||
|
"下次GC内存回收量": fmt.Sprintf("%.3fMB", float64(mstat.NextGC)/float64(mb)),
|
||||||
|
"GC暂停时间总量": fmt.Sprintf("%.3fs", float64(mstat.PauseTotalNs)/1000/1000/1000),
|
||||||
|
"上次GC暂停时间": fmt.Sprintf("%.3fs", float64(mstat.PauseNs[(mstat.NumGC+255)%256])/1000/1000/1000),
|
||||||
|
}
|
||||||
|
}
|
||||||
7
main.go
7
main.go
@@ -8,19 +8,22 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
//"fmt"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/george518/PPGo_Job/jobs"
|
"github.com/george518/PPGo_Job/jobs"
|
||||||
"github.com/george518/PPGo_Job/models"
|
"github.com/george518/PPGo_Job/models"
|
||||||
_ "github.com/george518/PPGo_Job/routers"
|
_ "github.com/george518/PPGo_Job/routers"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "1.0.0"
|
VERSION = "2.2.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//初始化数据模型
|
//初始化数据模型
|
||||||
models.Init()
|
var StartTime = time.Now().Unix()
|
||||||
|
models.Init(StartTime)
|
||||||
jobs.InitJobs()
|
jobs.InitJobs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ import (
|
|||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
var StartTime int64
|
||||||
|
|
||||||
|
func Init(startTime int64) {
|
||||||
|
StartTime = startTime
|
||||||
dbhost := beego.AppConfig.String("db.host")
|
dbhost := beego.AppConfig.String("db.host")
|
||||||
dbport := beego.AppConfig.String("db.port")
|
dbport := beego.AppConfig.String("db.port")
|
||||||
dbuser := beego.AppConfig.String("db.user")
|
dbuser := beego.AppConfig.String("db.user")
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<div>
|
|
||||||
<div class="layui-row">
|
<div class="layui-row">
|
||||||
<div class="layui-col-md12">
|
<div class="layui-col-md12">
|
||||||
<div class="layui-card">
|
<div class="layui-card">
|
||||||
@@ -89,10 +89,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-col-md6">
|
<div class="layui-col-md4">
|
||||||
<div class="layui-card">
|
<div class="layui-card">
|
||||||
<div class="layui-card-header">最近执行的任务</div>
|
<div class="layui-card-header">最近执行的任务</div>
|
||||||
<div class="layui-card-body" style="height: 300px; padding-bottom: 10px; overflow: auto">
|
<div class="layui-card-body" style="height: 465px; padding-bottom: 10px; overflow: auto">
|
||||||
<table class="layui-table" lay-size="sm">
|
<table class="layui-table" lay-size="sm">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col width="50">
|
<col width="50">
|
||||||
@@ -109,7 +109,6 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
{{range $k, $v := .recentLogs}}
|
{{range $k, $v := .recentLogs}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{$k}}</td>
|
<td>{{$k}}</td>
|
||||||
@@ -135,10 +134,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-col-md6">
|
<div class="layui-col-md4">
|
||||||
<div class="layui-card" style="background: #fff">
|
<div class="layui-card" style="background: #fff">
|
||||||
<div class="layui-card-header">即将执行的任务</div>
|
<div class="layui-card-header">即将执行的任务</div>
|
||||||
<div class="layui-card-body" style="height: 300px; padding-bottom: 10px; overflow: auto">
|
<div class="layui-card-body" style="height: 465px; padding-bottom: 10px; overflow: auto">
|
||||||
<table class="layui-table" lay-size="sm">
|
<table class="layui-table" lay-size="sm">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col>
|
<col>
|
||||||
@@ -167,7 +166,38 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="layui-col-md4">
|
||||||
|
<div class="layui-card" style="background: #fff">
|
||||||
|
<div class="layui-card-header">系统概况</div>
|
||||||
|
<div class="layui-card-body" style="height: 465px; padding-bottom: 10px; overflow: auto">
|
||||||
|
<table class="layui-table" lay-size="sm">
|
||||||
|
<colgroup>
|
||||||
|
<col>
|
||||||
|
<col>
|
||||||
|
</colgroup>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>参数</th>
|
||||||
|
<th>值</th>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{range $k, $v := .sysInfo}}
|
||||||
|
<tr>
|
||||||
|
<td># {{$k}} </td>
|
||||||
|
<td>{{$v}}</td>
|
||||||
|
</tr>
|
||||||
|
{{else}}
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">暂无信息</td>
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user