Add the dashboard monitor.
This commit is contained in:
@ -132,6 +132,8 @@ func (this *AlienService) PreviewOrDownload(
|
||||
}
|
||||
|
||||
//文件下载次数加一,为了加快访问速度,异步进行
|
||||
go this.matterDao.TimesIncrement(uuid)
|
||||
go SafeMethod(func() {
|
||||
this.matterDao.TimesIncrement(uuid)
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package rest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DashboardController struct {
|
||||
@ -33,7 +34,7 @@ func (this *DashboardController) RegisterRoutes() map[string]func(writer http.Re
|
||||
routeMap := make(map[string]func(writer http.ResponseWriter, request *http.Request))
|
||||
|
||||
//每个Controller需要主动注册自己的路由。
|
||||
routeMap["/api/dashboard/invoke/list"] = this.Wrap(this.InvokeList, USER_ROLE_ADMINISTRATOR)
|
||||
routeMap["/api/dashboard/page"] = this.Wrap(this.Page, USER_ROLE_ADMINISTRATOR)
|
||||
|
||||
return routeMap
|
||||
}
|
||||
@ -44,3 +45,51 @@ func (this *DashboardController) InvokeList(writer http.ResponseWriter, request
|
||||
return this.Success("")
|
||||
|
||||
}
|
||||
|
||||
//按照分页的方式获取某个图片缓存夹下图片缓存和子图片缓存夹的列表,通常情况下只有一页。
|
||||
func (this *DashboardController) Page(writer http.ResponseWriter, request *http.Request) *WebResult {
|
||||
|
||||
//如果是根目录,那么就传入root.
|
||||
pageStr := request.FormValue("page")
|
||||
pageSizeStr := request.FormValue("pageSize")
|
||||
orderCreateTime := request.FormValue("orderCreateTime")
|
||||
orderUpdateTime := request.FormValue("orderUpdateTime")
|
||||
orderSort := request.FormValue("orderSort")
|
||||
orderDt := request.FormValue("orderDt")
|
||||
|
||||
var page int
|
||||
if pageStr != "" {
|
||||
page, _ = strconv.Atoi(pageStr)
|
||||
}
|
||||
|
||||
pageSize := 200
|
||||
if pageSizeStr != "" {
|
||||
tmp, err := strconv.Atoi(pageSizeStr)
|
||||
if err == nil {
|
||||
pageSize = tmp
|
||||
}
|
||||
}
|
||||
|
||||
sortArray := []OrderPair{
|
||||
{
|
||||
key: "create_time",
|
||||
value: orderCreateTime,
|
||||
},
|
||||
{
|
||||
key: "update_time",
|
||||
value: orderUpdateTime,
|
||||
},
|
||||
{
|
||||
key: "sort",
|
||||
value: orderSort,
|
||||
},
|
||||
{
|
||||
key: "dt",
|
||||
value: orderDt,
|
||||
},
|
||||
}
|
||||
|
||||
pager := this.dashboardDao.Page(page, pageSize, "", sortArray)
|
||||
|
||||
return this.Success(pager)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
"github.com/nu7hatch/gouuid"
|
||||
"time"
|
||||
@ -17,6 +18,7 @@ func (this *DashboardDao) Create(dashboard *Dashboard) *Dashboard {
|
||||
dashboard.Uuid = string(timeUUID.String())
|
||||
dashboard.CreateTime = time.Now()
|
||||
dashboard.UpdateTime = time.Now()
|
||||
dashboard.Sort = time.Now().UnixNano() / 1e6
|
||||
db := CONTEXT.DB.Create(dashboard)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
@ -33,7 +35,6 @@ func (this *DashboardDao) Save(dashboard *Dashboard) *Dashboard {
|
||||
return dashboard
|
||||
}
|
||||
|
||||
|
||||
//删除一条记录
|
||||
func (this *DashboardDao) Delete(dashboard *Dashboard) {
|
||||
|
||||
@ -41,7 +42,6 @@ func (this *DashboardDao) Delete(dashboard *Dashboard) {
|
||||
this.PanicError(db.Error)
|
||||
}
|
||||
|
||||
|
||||
//按照dt查询
|
||||
func (this *DashboardDao) FindByDt(dt string) *Dashboard {
|
||||
|
||||
@ -53,3 +53,27 @@ func (this *DashboardDao) FindByDt(dt string) *Dashboard {
|
||||
}
|
||||
return &dashboard
|
||||
}
|
||||
|
||||
//获取某个文件夹下所有的文件和子文件
|
||||
func (this *DashboardDao) Page(page int, pageSize int, dt string, sortArray []OrderPair) *Pager {
|
||||
|
||||
var wp = &WherePair{}
|
||||
|
||||
if dt != "" {
|
||||
wp = wp.And(&WherePair{Query: "dt = ?", Args: []interface{}{dt}})
|
||||
}
|
||||
|
||||
var conditionDB *gorm.DB
|
||||
conditionDB = CONTEXT.DB.Model(&Dashboard{}).Where(wp.Query, wp.Args...)
|
||||
|
||||
count := 0
|
||||
db := conditionDB.Count(&count)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
var dashboards []*Dashboard
|
||||
db = conditionDB.Order(this.GetSortString(sortArray)).Offset(page * pageSize).Limit(pageSize).Find(&dashboards)
|
||||
this.PanicError(db.Error)
|
||||
pager := NewPager(page, pageSize, count, dashboards)
|
||||
|
||||
return pager
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ func (this *DashboardService) Init() {
|
||||
}
|
||||
|
||||
//立即执行数据清洗任务
|
||||
go this.maintain()
|
||||
go SafeMethod(this.maintain)
|
||||
|
||||
}
|
||||
|
||||
//每日清洗离线数据表。
|
||||
@ -59,7 +60,7 @@ func (this *DashboardService) maintain() {
|
||||
duration := nextTime.Sub(now)
|
||||
this.logger.Info("每日数据汇总,下次时间:%s ", ConvertTimeToDateTimeString(nextTime))
|
||||
this.maintainTimer = time.AfterFunc(duration, func() {
|
||||
go this.maintain()
|
||||
go SafeMethod(this.maintain)
|
||||
})
|
||||
|
||||
//准备日期开始结尾
|
||||
@ -125,4 +126,5 @@ func (this *DashboardService) maintain() {
|
||||
}
|
||||
|
||||
this.dashboardDao.Create(dashboard)
|
||||
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func (this *DownloadTokenDao) Create(downloadToken *DownloadToken) *DownloadToke
|
||||
|
||||
downloadToken.CreateTime = time.Now()
|
||||
downloadToken.UpdateTime = time.Now()
|
||||
|
||||
downloadToken.Sort = time.Now().UnixNano() / 1e6
|
||||
db := CONTEXT.DB.Create(downloadToken)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
|
@ -66,6 +66,7 @@ func (this *FootprintDao) Create(footprint *Footprint) *Footprint {
|
||||
footprint.Uuid = string(timeUUID.String())
|
||||
footprint.CreateTime = time.Now()
|
||||
footprint.UpdateTime = time.Now()
|
||||
footprint.Sort = time.Now().UnixNano() / 1e6
|
||||
db := CONTEXT.DB.Create(footprint)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
|
@ -67,13 +67,15 @@ func (this *ImageCacheController) Detail(writer http.ResponseWriter, request *ht
|
||||
|
||||
//按照分页的方式获取某个图片缓存夹下图片缓存和子图片缓存夹的列表,通常情况下只有一页。
|
||||
func (this *ImageCacheController) Page(writer http.ResponseWriter, request *http.Request) *WebResult {
|
||||
|
||||
//如果是根目录,那么就传入root.
|
||||
pageStr := request.FormValue("page")
|
||||
pageSizeStr := request.FormValue("pageSize")
|
||||
orderCreateTime := request.FormValue("orderCreateTime")
|
||||
orderUpdateTime := request.FormValue("orderUpdateTime")
|
||||
orderSort := request.FormValue("orderSort")
|
||||
|
||||
userUuid := request.FormValue("userUuid")
|
||||
matterUuid := request.FormValue("matterUuid")
|
||||
orderCreateTime := request.FormValue("orderCreateTime")
|
||||
orderSize := request.FormValue("orderSize")
|
||||
|
||||
user := this.checkUser(writer, request)
|
||||
@ -99,6 +101,15 @@ func (this *ImageCacheController) Page(writer http.ResponseWriter, request *http
|
||||
key: "create_time",
|
||||
value: orderCreateTime,
|
||||
},
|
||||
{
|
||||
key: "update_time",
|
||||
value: orderUpdateTime,
|
||||
},
|
||||
{
|
||||
key: "sort",
|
||||
value: orderSort,
|
||||
},
|
||||
|
||||
{
|
||||
key: "size",
|
||||
value: orderSize,
|
||||
|
@ -122,6 +122,7 @@ func (this *ImageCacheDao) Create(imageCache *ImageCache) *ImageCache {
|
||||
imageCache.Uuid = string(timeUUID.String())
|
||||
imageCache.CreateTime = time.Now()
|
||||
imageCache.UpdateTime = time.Now()
|
||||
imageCache.Sort = time.Now().UnixNano() / 1e6
|
||||
db := CONTEXT.DB.Create(imageCache)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
|
@ -70,9 +70,9 @@ func (this *Logger) Init() {
|
||||
//日志需要自我备份,自我维护。明天第一秒触发
|
||||
nextTime := FirstSecondOfDay(Tomorrow())
|
||||
duration := nextTime.Sub(time.Now())
|
||||
go this.Info("%vs后将进行下一次日志维护 下次时间%v ", int64(duration/time.Second), nextTime)
|
||||
this.Info("%vs后将进行下一次日志维护 下次时间%v ", int64(duration/time.Second), nextTime)
|
||||
this.maintainTimer = time.AfterFunc(duration, func() {
|
||||
go this.maintain()
|
||||
go SafeMethod(this.maintain)
|
||||
})
|
||||
|
||||
}
|
||||
@ -83,7 +83,7 @@ func (this *Logger) maintain() {
|
||||
this.Lock()
|
||||
defer this.Unlock()
|
||||
|
||||
go this.Info("每日维护日志")
|
||||
this.Info("每日维护日志")
|
||||
|
||||
//首先关闭文件。
|
||||
this.closeFile()
|
||||
@ -94,7 +94,7 @@ func (this *Logger) maintain() {
|
||||
//直接重命名文件
|
||||
err := os.Rename(this.fileName(), destPath)
|
||||
if err != nil {
|
||||
go this.Error("重命名文件出错", err.Error())
|
||||
this.Error("重命名文件出错", err.Error())
|
||||
}
|
||||
|
||||
//再次打开文件
|
||||
@ -104,9 +104,9 @@ func (this *Logger) maintain() {
|
||||
now := time.Now()
|
||||
nextTime := FirstSecondOfDay(Tomorrow())
|
||||
duration := nextTime.Sub(now)
|
||||
go this.Info("%vs 后将进行下一次日志维护 下次时间维护时间:%v ", int64(duration/time.Second), nextTime)
|
||||
this.Info("%vs 后将进行下一次日志维护 下次时间维护时间:%v ", int64(duration/time.Second), nextTime)
|
||||
this.maintainTimer = time.AfterFunc(duration, func() {
|
||||
go this.maintain()
|
||||
go SafeMethod(this.maintain)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type MatterController struct {
|
||||
@ -152,14 +152,17 @@ func (this *MatterController) CreateDirectory(writer http.ResponseWriter, reques
|
||||
func (this *MatterController) Page(writer http.ResponseWriter, request *http.Request) *WebResult {
|
||||
|
||||
//如果是根目录,那么就传入root.
|
||||
puuid := request.FormValue("puuid")
|
||||
pageStr := request.FormValue("page")
|
||||
pageSizeStr := request.FormValue("pageSize")
|
||||
orderCreateTime := request.FormValue("orderCreateTime")
|
||||
orderUpdateTime := request.FormValue("orderUpdateTime")
|
||||
orderSort := request.FormValue("orderSort")
|
||||
|
||||
puuid := request.FormValue("puuid")
|
||||
userUuid := request.FormValue("userUuid")
|
||||
name := request.FormValue("name")
|
||||
dir := request.FormValue("dir")
|
||||
orderDir := request.FormValue("orderDir")
|
||||
orderCreateTime := request.FormValue("orderCreateTime")
|
||||
orderSize := request.FormValue("orderSize")
|
||||
orderName := request.FormValue("orderName")
|
||||
extensionsStr := request.FormValue("extensions")
|
||||
@ -194,14 +197,22 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req
|
||||
}
|
||||
|
||||
sortArray := []OrderPair{
|
||||
{
|
||||
key: "dir",
|
||||
value: orderDir,
|
||||
},
|
||||
{
|
||||
key: "create_time",
|
||||
value: orderCreateTime,
|
||||
},
|
||||
{
|
||||
key: "update_time",
|
||||
value: orderUpdateTime,
|
||||
},
|
||||
{
|
||||
key: "sort",
|
||||
value: orderSort,
|
||||
},
|
||||
{
|
||||
key: "dir",
|
||||
value: orderDir,
|
||||
},
|
||||
{
|
||||
key: "size",
|
||||
value: orderSize,
|
||||
|
@ -200,6 +200,7 @@ func (this *MatterDao) Create(matter *Matter) *Matter {
|
||||
matter.Uuid = string(timeUUID.String())
|
||||
matter.CreateTime = time.Now()
|
||||
matter.UpdateTime = time.Now()
|
||||
matter.Sort = time.Now().UnixNano() / 1e6
|
||||
db := CONTEXT.DB.Create(matter)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
|
@ -39,6 +39,7 @@ func (this *PreferenceDao) Create(preference *Preference) *Preference {
|
||||
preference.Uuid = string(timeUUID.String())
|
||||
preference.CreateTime = time.Now()
|
||||
preference.UpdateTime = time.Now()
|
||||
preference.Sort = time.Now().UnixNano() / 1e6
|
||||
db := CONTEXT.DB.Create(preference)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
|
@ -87,7 +87,9 @@ func (this *Router) GlobalPanicHandler(writer http.ResponseWriter, request *http
|
||||
}
|
||||
|
||||
//错误情况记录。
|
||||
go this.footprintService.Trace(writer, request, time.Now().Sub(startTime), false)
|
||||
go SafeMethod(func() {
|
||||
this.footprintService.Trace(writer, request, time.Now().Sub(startTime), false)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,14 +125,15 @@ func (this *Router) ServeHTTP(writer http.ResponseWriter, request *http.Request)
|
||||
}
|
||||
|
||||
if !canHandle {
|
||||
panic(fmt.Sprintf("没有找到能够处理%s的方法\n", path))
|
||||
panic(CustomWebResult(CODE_WRAPPER_NOT_FOUND, fmt.Sprintf("没有找到能够处理%s的方法", path)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//正常的访问记录会落到这里。
|
||||
go this.footprintService.Trace(writer, request, time.Now().Sub(startTime), true)
|
||||
|
||||
go SafeMethod(func() {
|
||||
this.footprintService.Trace(writer, request, time.Now().Sub(startTime), true)
|
||||
})
|
||||
} else {
|
||||
//当作静态资源处理。默认从当前文件下面的static文件夹中取东西。
|
||||
dir := GetHtmlPath()
|
||||
|
@ -45,6 +45,9 @@ func (this *SessionDao) Create(session *Session) *Session {
|
||||
|
||||
timeUUID, _ := uuid.NewV4()
|
||||
session.Uuid = string(timeUUID.String())
|
||||
session.CreateTime = time.Now()
|
||||
session.UpdateTime = time.Now()
|
||||
session.Sort = time.Now().UnixNano() / 1e6
|
||||
db := CONTEXT.DB.Create(session)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
|
@ -32,7 +32,7 @@ func (this *UploadTokenDao) Create(uploadToken *UploadToken) *UploadToken {
|
||||
|
||||
uploadToken.CreateTime = time.Now()
|
||||
uploadToken.UpdateTime = time.Now()
|
||||
|
||||
uploadToken.Sort = time.Now().UnixNano() / 1e6
|
||||
db := CONTEXT.DB.Create(uploadToken)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
|
@ -248,15 +248,17 @@ func (this *UserController) Logout(writer http.ResponseWriter, request *http.Req
|
||||
//获取用户列表 管理员的权限。
|
||||
func (this *UserController) Page(writer http.ResponseWriter, request *http.Request) *WebResult {
|
||||
|
||||
//如果是根目录,那么就传入root.
|
||||
pageStr := request.FormValue("page")
|
||||
pageSizeStr := request.FormValue("pageSize")
|
||||
orderCreateTime := request.FormValue("orderCreateTime")
|
||||
orderUpdateTime := request.FormValue("orderUpdateTime")
|
||||
orderSort := request.FormValue("orderSort")
|
||||
|
||||
username := request.FormValue("username")
|
||||
email := request.FormValue("email")
|
||||
phone := request.FormValue("phone")
|
||||
status := request.FormValue("status")
|
||||
orderLastTime := request.FormValue("orderLastTime")
|
||||
orderCreateTime := request.FormValue("orderCreateTime")
|
||||
|
||||
var page int
|
||||
if pageStr != "" {
|
||||
@ -272,14 +274,22 @@ func (this *UserController) Page(writer http.ResponseWriter, request *http.Reque
|
||||
}
|
||||
|
||||
sortArray := []OrderPair{
|
||||
{
|
||||
key: "last_time",
|
||||
value: orderLastTime,
|
||||
},
|
||||
{
|
||||
key: "create_time",
|
||||
value: orderCreateTime,
|
||||
},
|
||||
{
|
||||
key: "update_time",
|
||||
value: orderUpdateTime,
|
||||
},
|
||||
{
|
||||
key: "sort",
|
||||
value: orderSort,
|
||||
},
|
||||
{
|
||||
key: "last_time",
|
||||
value: orderLastTime,
|
||||
},
|
||||
}
|
||||
|
||||
pager := this.userDao.Page(page, pageSize, username, email, phone, status, sortArray)
|
||||
|
@ -196,7 +196,7 @@ func (table *CacheTable) checkExpire() {
|
||||
table.cleanupInterval = smallestDuration
|
||||
if smallestDuration > 0 {
|
||||
table.cleanupTimer = time.AfterFunc(smallestDuration, func() {
|
||||
go table.checkExpire()
|
||||
go SafeMethod(table.checkExpire)
|
||||
})
|
||||
}
|
||||
table.Unlock()
|
||||
|
16
rest/util_framework.go
Normal file
16
rest/util_framework.go
Normal file
@ -0,0 +1,16 @@
|
||||
package rest
|
||||
|
||||
|
||||
//带有panic恢复的方法
|
||||
func PanicHandler() {
|
||||
if err := recover(); err != nil {
|
||||
LOGGER.Error("异步任务错误: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
//带有panic恢复的方法
|
||||
func SafeMethod(f func()) {
|
||||
defer PanicHandler()
|
||||
//执行函数
|
||||
f()
|
||||
}
|
Reference in New Issue
Block a user