服务访问日志增加今天和历史的访问日志查看

This commit is contained in:
GoEdgeLab
2020-10-31 17:44:53 +08:00
parent a8dd678b82
commit 509dc9771e
6 changed files with 14 additions and 9 deletions

View File

@@ -110,7 +110,7 @@ func (this *HTTPAccessLogDAO) CreateHTTPAccessLogsWithDAO(daoWrapper *HTTPAccess
}
// 读取往前的 单页访问日志
func (this *HTTPAccessLogDAO) ListAccessLogs(lastRequestId string, size int64, day string, serverId int64, reverse bool) (result []*HTTPAccessLog, nextLastRequestId string, hasMore bool, err error) {
func (this *HTTPAccessLogDAO) ListAccessLogs(lastRequestId string, size int64, day string, serverId int64, reverse bool, hasError bool) (result []*HTTPAccessLog, nextLastRequestId string, hasMore bool, err error) {
if len(day) != 8 {
return
}
@@ -120,18 +120,18 @@ func (this *HTTPAccessLogDAO) ListAccessLogs(lastRequestId string, size int64, d
size = 1000
}
result, nextLastRequestId, err = this.listAccessLogs(lastRequestId, size, day, serverId, reverse)
result, nextLastRequestId, err = this.listAccessLogs(lastRequestId, size, day, serverId, reverse, hasError)
if err != nil || int64(len(result)) < size {
return
}
moreResult, _, _ := this.listAccessLogs(nextLastRequestId, 1, day, serverId, reverse)
moreResult, _, _ := this.listAccessLogs(nextLastRequestId, 1, day, serverId, reverse, hasError)
hasMore = len(moreResult) > 0
return
}
// 读取往前的单页访问日志
func (this *HTTPAccessLogDAO) listAccessLogs(lastRequestId string, size int64, day string, serverId int64, reverse bool) (result []*HTTPAccessLog, nextLastRequestId string, err error) {
func (this *HTTPAccessLogDAO) listAccessLogs(lastRequestId string, size int64, day string, serverId int64, reverse bool, hasError bool) (result []*HTTPAccessLog, nextLastRequestId string, err error) {
if size <= 0 {
return nil, lastRequestId, nil
}
@@ -177,6 +177,9 @@ func (this *HTTPAccessLogDAO) listAccessLogs(lastRequestId string, size int64, d
if serverId > 0 {
query.Attr("serverId", serverId)
}
if hasError {
query.Where("status>400")
}
// offset
if len(lastRequestId) > 0 {

View File

@@ -491,7 +491,7 @@ func (this *NodeDAO) ComposeNodeConfig(nodeId int64) (*nodeconfigs.NodeConfig, e
// 全局设置
// TODO 根据用户的不同读取不同的全局设置
settingJSON, err := SharedSysSettingDAO.ReadSetting(SettingCodeGlobalConfig)
settingJSON, err := SharedSysSettingDAO.ReadSetting(SettingCodeServerGlobalConfig)
if err != nil {
return nil, err
}

View File

@@ -13,7 +13,9 @@ type SysSettingDAO dbs.DAO
type SettingCode = string
const (
SettingCodeGlobalConfig SettingCode = "globalConfig"
SettingCodeServerGlobalConfig SettingCode = "serverGlobalConfig" // 服务相关全局设置
SettingCodeNodeMonitor SettingCode = "nodeMonitor" // 监控节点状态
SettingCodeClusterHealthCheck SettingCode = "clusterHealthCheck" // 集群健康检查
)
func NewSysSettingDAO() *SysSettingDAO {

View File

@@ -39,7 +39,7 @@ func (this *HTTPAccessLogService) ListHTTPAccessLogs(ctx context.Context, req *p
return nil, err
}
accessLogs, requestId, hasMore, err := models.SharedHTTPAccessLogDAO.ListAccessLogs(req.RequestId, req.Size, req.Day, req.ServerId, req.Reverse)
accessLogs, requestId, hasMore, err := models.SharedHTTPAccessLogDAO.ListAccessLogs(req.RequestId, req.Size, req.Day, req.ServerId, req.Reverse, req.HasError)
if err != nil {
return nil, err
}

View File

@@ -87,7 +87,7 @@ func (this *HealthCheckClusterTask) Stop() {
// 单个循环任务
func (this *HealthCheckClusterTask) loop(seconds int64) error {
// 检查上次运行时间,防止重复运行
settingKey := "cluster_health_check_%d" + numberutils.FormatInt64(this.clusterId)
settingKey := models.SettingCodeClusterHealthCheck + numberutils.FormatInt64(this.clusterId)
timestamp := time.Now().Unix()
c, err := models.SharedSysSettingDAO.CompareInt64Setting(settingKey, timestamp-seconds)
if err != nil {

View File

@@ -40,7 +40,7 @@ func (this *NodeMonitorTask) Run() {
func (this *NodeMonitorTask) loop() error {
// 检查上次运行时间,防止重复运行
settingKey := "node_monitor"
settingKey := models.SettingCodeNodeMonitor
timestamp := time.Now().Unix()
c, err := models.SharedSysSettingDAO.CompareInt64Setting(settingKey, timestamp-int64(this.intervalSeconds))
if err != nil {