首页折线图添加缓存
This commit is contained in:
@@ -15,8 +15,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
//"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -173,6 +171,7 @@ func (self *HomeController) Start() {
|
|||||||
self.Data["okNum"] = okNum
|
self.Data["okNum"] = okNum
|
||||||
self.Data["errNum"] = errNum
|
self.Data["errNum"] = errNum
|
||||||
self.Data["expiredNum"] = expiredNum
|
self.Data["expiredNum"] = expiredNum
|
||||||
|
|
||||||
self.Data["cpuNum"] = runtime.NumCPU()
|
self.Data["cpuNum"] = runtime.NumCPU()
|
||||||
|
|
||||||
//系统运行信息
|
//系统运行信息
|
||||||
|
|||||||
@@ -8,7 +8,11 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/astaxie/beego/cache"
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TaskLog struct {
|
type TaskLog struct {
|
||||||
@@ -23,6 +27,8 @@ type TaskLog struct {
|
|||||||
CreateTime int64
|
CreateTime int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var RunNumCache, _ = cache.NewCache("memory", `{"interval":60}`)
|
||||||
|
|
||||||
func (t *TaskLog) TableName() string {
|
func (t *TaskLog) TableName() string {
|
||||||
return TableName("task_log")
|
return TableName("task_log")
|
||||||
}
|
}
|
||||||
@@ -81,12 +87,32 @@ type SumDays struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SumByDays(limit int, status string) orm.Params {
|
func SumByDays(limit int, status string) orm.Params {
|
||||||
|
|
||||||
|
var m = map[string]string{
|
||||||
|
"0": "okNum",
|
||||||
|
"-1": "errNum",
|
||||||
|
"-2": "expiredRun"}
|
||||||
|
|
||||||
res := make(orm.Params)
|
res := make(orm.Params)
|
||||||
|
key := m[status]
|
||||||
|
|
||||||
|
if RunNumCache.IsExist(key) {
|
||||||
|
json.Unmarshal(RunNumCache.Get(key).([]byte), &res)
|
||||||
|
logs.Info("cache")
|
||||||
|
return res
|
||||||
|
}
|
||||||
_, err := orm.NewOrm().Raw("SELECT FROM_UNIXTIME(create_time,'%Y-%m-%d') days,COUNT(id) count FROM pp_task_log WHERE status in(?) GROUP BY days ORDER BY days DESC limit ?;",
|
_, err := orm.NewOrm().Raw("SELECT FROM_UNIXTIME(create_time,'%Y-%m-%d') days,COUNT(id) count FROM pp_task_log WHERE status in(?) GROUP BY days ORDER BY days DESC limit ?;",
|
||||||
status, limit).RowsToMap(&res, "days", "count")
|
status, limit).RowsToMap(&res, "days", "count")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data, err := json.Marshal(res)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
RunNumCache.Put(key, data, 2*time.Hour)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user