diff --git a/controllers/home.go b/controllers/home.go
index cfe622f..357665b 100644
--- a/controllers/home.go
+++ b/controllers/home.go
@@ -8,11 +8,13 @@
package controllers
import (
+ "fmt"
"github.com/astaxie/beego"
"github.com/george518/PPGo_Job/jobs"
"github.com/george518/PPGo_Job/libs"
"github.com/george518/PPGo_Job/models"
"runtime"
+ //"strconv"
"time"
)
@@ -111,7 +113,13 @@ func (self *HomeController) Start() {
// this.Data["errLogs"] = errLogs
self.Data["jobs"] = jobList
self.Data["cpuNum"] = runtime.NumCPU()
- self.display()
+
+ //系统运行信息
+
+ fmt.Println(models.StartTime)
+
+ info := libs.SystemInfo(models.StartTime)
+ self.Data["sysInfo"] = info
self.Data["pageTitle"] = "系统概况"
self.display()
diff --git a/libs/file.go b/libs/file.go
new file mode 100644
index 0000000..6f1d78e
--- /dev/null
+++ b/libs/file.go
@@ -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)
+}
diff --git a/libs/monitor.go b/libs/monitor.go
new file mode 100644
index 0000000..952d64a
--- /dev/null
+++ b/libs/monitor.go
@@ -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),
+ }
+}
diff --git a/main.go b/main.go
index b7708d4..ecb1392 100644
--- a/main.go
+++ b/main.go
@@ -8,19 +8,22 @@
package main
import (
+ //"fmt"
"github.com/astaxie/beego"
"github.com/george518/PPGo_Job/jobs"
"github.com/george518/PPGo_Job/models"
_ "github.com/george518/PPGo_Job/routers"
+ "time"
)
const (
- VERSION = "1.0.0"
+ VERSION = "2.2.0"
)
func init() {
//初始化数据模型
- models.Init()
+ var StartTime = time.Now().Unix()
+ models.Init(StartTime)
jobs.InitJobs()
}
diff --git a/models/init.go b/models/init.go
index be05a18..abd9bbc 100644
--- a/models/init.go
+++ b/models/init.go
@@ -17,7 +17,10 @@ import (
_ "github.com/go-sql-driver/mysql"
)
-func Init() {
+var StartTime int64
+
+func Init(startTime int64) {
+ StartTime = startTime
dbhost := beego.AppConfig.String("db.host")
dbport := beego.AppConfig.String("db.port")
dbuser := beego.AppConfig.String("db.user")
diff --git a/views/home/start.html b/views/home/start.html
index d781b5b..dc9982a 100644
--- a/views/home/start.html
+++ b/views/home/start.html
@@ -43,131 +43,161 @@
text-align: center;
}
-
-
-
-
-
-
-
-
-
-
- 最近执行成功
- {{.okJob}}
-
+
+
+
+
+
+
+
+
+
+
+ 最近执行成功
+ {{.okJob}}
-
-
-
-
- 最近执行失败
- {{.failJob}}
-
+
+
+
+
+
+ 最近执行失败
+ {{.failJob}}
-
-
-
-
- 即将执行的任务
- {{.startJob}}
-
+
+
+
+
+
+ 即将执行的任务
+ {{.startJob}}
-
-
-
-
- 定时任务总数量
- {{.totalJob}}
-
+
+
+
+
+
+ 定时任务总数量
+ {{.totalJob}}
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | 序号 |
+ 任务名称 |
+ 开始时间 |
+ 执行结果 |
+
+
+
+ {{range $k, $v := .recentLogs}}
- | 序号 |
- 任务名称 |
- 开始时间 |
- 执行结果 |
+ {{$k}} |
+
+ {{$v.task_name}} # {{$v.id}}
+ |
+ {{$v.start_time}} |
+ {{if eq $v.status 0}}
+ 正常
+ {{else if eq $v.status -1}}
+ 异常
+ {{else}}
+ 超时
+ {{end}} |
-
-
-
- {{range $k, $v := .recentLogs}}
-
- | {{$k}} |
-
- {{$v.task_name}} # {{$v.id}}
- |
- {{$v.start_time}} |
- {{if eq $v.status 0}}
- 正常
- {{else if eq $v.status -1}}
- 异常
- {{else}}
- 超时
- {{end}} |
-
- {{else}}
-
- | 暂无信息 |
-
- {{end}}
-
-
-
+ {{else}}
+
+ | 暂无信息 |
+
+ {{end}}
+
+
-
-
-
-
-
-
-
-
-
-
-
- | 任务名称 |
- 执行时间 |
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | 参数 |
+ 值 |
+
+
+
+ {{range $k, $v := .sysInfo}}
+
+ | # {{$k}} |
+ {{$v}} |
+
+ {{else}}
+
+ | 暂无信息 |
+
+ {{end}}
+
+
+
+
+
-
\ No newline at end of file
+