mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-12 19:30:26 +08:00
服务访问日志增加今天和历史的访问日志查看
This commit is contained in:
@@ -142,13 +142,14 @@ func (this *NodeAction) RunGet(params struct {
|
|||||||
"isOn": node.IsOn,
|
"isOn": node.IsOn,
|
||||||
|
|
||||||
"status": maps.Map{
|
"status": maps.Map{
|
||||||
"isActive": status.IsActive,
|
"isActive": status.IsActive,
|
||||||
"updatedAt": status.UpdatedAt,
|
"updatedAt": status.UpdatedAt,
|
||||||
"hostname": status.Hostname,
|
"hostname": status.Hostname,
|
||||||
"cpuUsage": status.CPUUsage,
|
"cpuUsage": status.CPUUsage,
|
||||||
"cpuUsageText": fmt.Sprintf("%.2f%%", status.CPUUsage*100),
|
"cpuUsageText": fmt.Sprintf("%.2f%%", status.CPUUsage*100),
|
||||||
"memUsage": status.MemoryUsage,
|
"memUsage": status.MemoryUsage,
|
||||||
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
|
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
|
||||||
|
"connectionCount": status.ConnectionCount,
|
||||||
},
|
},
|
||||||
|
|
||||||
"group": groupMap,
|
"group": groupMap,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SettingCodeGlobalConfig = "globalConfig"
|
SettingCodeServerGlobalConfig = "serverGlobalConfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
@@ -22,7 +22,7 @@ func (this *IndexAction) Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct{}) {
|
func (this *IndexAction) RunGet(params struct{}) {
|
||||||
valueJSONResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: SettingCodeGlobalConfig})
|
valueJSONResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: SettingCodeServerGlobalConfig})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
@@ -57,7 +57,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
|
|
||||||
// 修改配置
|
// 修改配置
|
||||||
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||||
Code: SettingCodeGlobalConfig,
|
Code: SettingCodeServerGlobalConfig,
|
||||||
ValueJSON: params.GlobalConfigJSON,
|
ValueJSON: params.GlobalConfigJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
87
internal/web/actions/default/servers/server/log/history.go
Normal file
87
internal/web/actions/default/servers/server/log/history.go
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HistoryAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *HistoryAction) Init() {
|
||||||
|
this.Nav("", "log", "")
|
||||||
|
this.SecondMenu("history")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *HistoryAction) RunGet(params struct {
|
||||||
|
ServerId int64
|
||||||
|
Day string
|
||||||
|
|
||||||
|
RequestId string
|
||||||
|
HasError int
|
||||||
|
}) {
|
||||||
|
if len(params.Day) == 0 {
|
||||||
|
params.Day = timeutil.Format("Y-m-d")
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["path"] = this.Request.URL.Path
|
||||||
|
this.Data["day"] = params.Day
|
||||||
|
this.Data["accessLogs"] = []interface{}{}
|
||||||
|
this.Data["hasError"] = params.HasError
|
||||||
|
|
||||||
|
day := params.Day
|
||||||
|
if len(day) > 0 && regexp.MustCompile(`\d{4}-\d{2}-\d{2}`).MatchString(day) {
|
||||||
|
day = strings.ReplaceAll(day, "-", "")
|
||||||
|
size := int64(10)
|
||||||
|
|
||||||
|
this.Data["hasError"] = params.HasError
|
||||||
|
|
||||||
|
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||||||
|
RequestId: params.RequestId,
|
||||||
|
ServerId: params.ServerId,
|
||||||
|
HasError: params.HasError > 0,
|
||||||
|
Day: day,
|
||||||
|
Size: size,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(resp.AccessLogs) == 0 {
|
||||||
|
this.Data["accessLogs"] = []interface{}{}
|
||||||
|
} else {
|
||||||
|
this.Data["accessLogs"] = resp.AccessLogs
|
||||||
|
}
|
||||||
|
this.Data["hasMore"] = resp.HasMore
|
||||||
|
this.Data["nextRequestId"] = resp.RequestId
|
||||||
|
|
||||||
|
// 上一个requestId
|
||||||
|
this.Data["hasPrev"] = false
|
||||||
|
this.Data["lastRequestId"] = ""
|
||||||
|
if len(params.RequestId) > 0 {
|
||||||
|
this.Data["hasPrev"] = true
|
||||||
|
prevResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||||||
|
RequestId: params.RequestId,
|
||||||
|
ServerId: params.ServerId,
|
||||||
|
HasError: params.HasError > 0,
|
||||||
|
Day: day,
|
||||||
|
Size: size,
|
||||||
|
Reverse: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if int64(len(prevResp.AccessLogs)) == size {
|
||||||
|
this.Data["lastRequestId"] = prevResp.RequestId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -13,6 +13,8 @@ func init() {
|
|||||||
Helper(serverutils.NewServerHelper()).
|
Helper(serverutils.NewServerHelper()).
|
||||||
Prefix("/servers/server/log").
|
Prefix("/servers/server/log").
|
||||||
GetPost("", new(IndexAction)).
|
GetPost("", new(IndexAction)).
|
||||||
|
GetPost("/today", new(TodayAction)).
|
||||||
|
GetPost("/history", new(HistoryAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
71
internal/web/actions/default/servers/server/log/today.go
Normal file
71
internal/web/actions/default/servers/server/log/today.go
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TodayAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TodayAction) Init() {
|
||||||
|
this.Nav("", "log", "")
|
||||||
|
this.SecondMenu("today")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TodayAction) RunGet(params struct {
|
||||||
|
RequestId string
|
||||||
|
ServerId int64
|
||||||
|
HasError int
|
||||||
|
}) {
|
||||||
|
size := int64(10)
|
||||||
|
|
||||||
|
this.Data["path"] = this.Request.URL.Path
|
||||||
|
this.Data["hasError"] = params.HasError
|
||||||
|
|
||||||
|
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||||||
|
RequestId: params.RequestId,
|
||||||
|
ServerId: params.ServerId,
|
||||||
|
HasError: params.HasError > 0,
|
||||||
|
Day: timeutil.Format("Ymd"),
|
||||||
|
Size: size,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(resp.AccessLogs) == 0 {
|
||||||
|
this.Data["accessLogs"] = []interface{}{}
|
||||||
|
} else {
|
||||||
|
this.Data["accessLogs"] = resp.AccessLogs
|
||||||
|
}
|
||||||
|
this.Data["hasMore"] = resp.HasMore
|
||||||
|
this.Data["nextRequestId"] = resp.RequestId
|
||||||
|
|
||||||
|
// 上一个requestId
|
||||||
|
this.Data["hasPrev"] = false
|
||||||
|
this.Data["lastRequestId"] = ""
|
||||||
|
if len(params.RequestId) > 0 {
|
||||||
|
this.Data["hasPrev"] = true
|
||||||
|
prevResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||||||
|
RequestId: params.RequestId,
|
||||||
|
ServerId: params.ServerId,
|
||||||
|
HasError: params.HasError > 0,
|
||||||
|
Day: timeutil.Format("Ymd"),
|
||||||
|
Size: size,
|
||||||
|
Reverse: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if int64(len(prevResp.AccessLogs)) == size {
|
||||||
|
this.Data["lastRequestId"] = prevResp.RequestId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -125,6 +125,16 @@ func (this *ServerHelper) createLogMenu(secondMenuItem string, serverIdString st
|
|||||||
"url": "/servers/server/log?serverId=" + serverIdString,
|
"url": "/servers/server/log?serverId=" + serverIdString,
|
||||||
"isActive": secondMenuItem == "index",
|
"isActive": secondMenuItem == "index",
|
||||||
})
|
})
|
||||||
|
menuItems = append(menuItems, maps.Map{
|
||||||
|
"name": "今天",
|
||||||
|
"url": "/servers/server/log/today?serverId=" + serverIdString,
|
||||||
|
"isActive": secondMenuItem == "today",
|
||||||
|
})
|
||||||
|
menuItems = append(menuItems, maps.Map{
|
||||||
|
"name": "历史",
|
||||||
|
"url": "/servers/server/log/history?serverId=" + serverIdString,
|
||||||
|
"isActive": secondMenuItem == "history",
|
||||||
|
})
|
||||||
return menuItems
|
return menuItems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ Vue.component("http-access-log-box", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
template: `<div :style="{'color': (accessLog.status >= 400) ? '#dc143c' : ''}">
|
template: `<div :style="{'color': (accessLog.status >= 400) ? '#dc143c' : ''}">
|
||||||
{{accessLog.remoteAddr}} [{{accessLog.timeLocal}}] <em>"{{accessLog.requestMethod}} {{accessLog.requestScheme}}://{{accessLog.host}}{{accessLog.requestURI}} <a :href="accessLog.scheme + '://' + accessLog.host + accessLog.requestURI" target="_blank" title="新窗口打开" class="disabled"><i class="external icon tiny"></i> </a> {{accessLog.proto}}" </em> {{accessLog.status}} <span v-if="accessLog.attrs != null && accessLog.attrs['cache_cached'] == '1'">[cached]</span> <span v-if="accessLog.attrs != null && accessLog.attrs['waf_action'] != null && accessLog.attrs['waf_action'].length > 0">[waf {{accessLog.attrs['waf_action']}}]</span> - 耗时:{{formatCost(accessLog.requestTime)}} ms
|
{{accessLog.remoteAddr}} [{{accessLog.timeLocal}}] <em>"{{accessLog.requestMethod}} {{accessLog.scheme}}://{{accessLog.host}}{{accessLog.requestURI}} <a :href="accessLog.scheme + '://' + accessLog.host + accessLog.requestURI" target="_blank" title="新窗口打开" class="disabled"><i class="external icon tiny"></i> </a> {{accessLog.proto}}" </em> {{accessLog.status}} <span v-if="accessLog.attrs != null && accessLog.attrs['cache_cached'] == '1'">[cached]</span> <span v-if="accessLog.attrs != null && accessLog.attrs['waf_action'] != null && accessLog.attrs['waf_action'].length > 0">[waf {{accessLog.attrs['waf_action']}}]</span> - 耗时:{{formatCost(accessLog.requestTime)}} ms
|
||||||
</div>`
|
</div>`
|
||||||
})
|
})
|
||||||
@@ -104,15 +104,22 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-show="node.status.isActive">
|
<tbody v-show="node.status.isActive">
|
||||||
<td>CPU</td>
|
<tr>
|
||||||
<td>{{node.status.cpuUsageText}}</td>
|
<td>CPU</td>
|
||||||
</tr>
|
<td>{{node.status.cpuUsageText}}</td>
|
||||||
<tr v-show="node.status.isActive">
|
</tr>
|
||||||
<td>内存</td>
|
<tr>
|
||||||
<td>{{node.status.memUsageText}}</td>
|
<td>内存</td>
|
||||||
</tr>
|
<td>{{node.status.memUsageText}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>连接数</td>
|
||||||
|
<td>{{node.status.connectionCount}}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<p class="comment" v-if="node.status.isActive">每隔30秒钟更新一次运行状态。</p>
|
||||||
|
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
<h3>安装信息</h3>
|
<h3>安装信息</h3>
|
||||||
|
|||||||
49
web/views/@default/servers/server/log/history.html
Normal file
49
web/views/@default/servers/server/log/history.html
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
{$layout}
|
||||||
|
|
||||||
|
{$var "header"}
|
||||||
|
<!-- datepicker -->
|
||||||
|
<script type="text/javascript" src="/js/moment.min.js"></script>
|
||||||
|
<script type="text/javascript" src="/js/pikaday.js"></script>
|
||||||
|
<link rel="stylesheet" href="/js/pikaday.css"/>
|
||||||
|
<link rel="stylesheet" href="/js/pikaday.theme.css"/>
|
||||||
|
<link rel="stylesheet" href="/js/pikaday.triangle.css"/>
|
||||||
|
{$end}
|
||||||
|
|
||||||
|
{$template "/left_menu"}
|
||||||
|
|
||||||
|
<div class="right-box">
|
||||||
|
<first-menu>
|
||||||
|
<menu-item :href="path + '?serverId=' + serverId + '&day=' + day" :active="hasError == 0">所有日志</menu-item>
|
||||||
|
<menu-item :href="path + '?serverId=' + serverId + '&day=' + day + '&hasError=1'" :active="hasError > 0">错误日志</menu-item>
|
||||||
|
<div class="item right">
|
||||||
|
<form class="ui form" :action="path" autocomplete="off">
|
||||||
|
<input type="hidden" name="serverId" :value="serverId"/>
|
||||||
|
<div class="ui fields inline">
|
||||||
|
<div class="ui field">
|
||||||
|
<input type="text" name="day" maxlength="10" placeholder="选择日期" style="width:7.8em" id="day-input" v-model="day"/>
|
||||||
|
</div>
|
||||||
|
<div class="ui field">
|
||||||
|
<button class="ui button" type="submit">查找</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</first-menu>
|
||||||
|
|
||||||
|
<p class="comment" v-if="accessLogs.length == 0">暂时还没有访问日志。</p>
|
||||||
|
|
||||||
|
<table class="ui table selectable" v-if="accessLogs.length > 0">
|
||||||
|
<!-- 这里之所以需要添加 :key,是因为要不然不会刷新显示 -->
|
||||||
|
<tr v-for="accessLog in accessLogs" :key="accessLog.requestId">
|
||||||
|
<td><http-access-log-box :v-access-log="accessLog"></http-access-log-box></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div v-if="accessLogs.length > 0">
|
||||||
|
<a :href="path + '?serverId=' + serverId + '&requestId=' + lastRequestId + '&day=' + day + '&hasError=' + hasError" v-if="hasPrev">上一页</a>
|
||||||
|
<span v-else class="disabled">上一页</span>
|
||||||
|
<span class="disabled"> | </span>
|
||||||
|
<a :href="path + '?serverId=' + serverId + '&requestId=' + nextRequestId + '&day=' + day + '&hasError=' + hasError" v-if="hasMore">下一页</a>
|
||||||
|
<span v-else class="disabled">下一页</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
8
web/views/@default/servers/server/log/history.js
Normal file
8
web/views/@default/servers/server/log/history.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
Tea.context(function () {
|
||||||
|
this.$delay(function () {
|
||||||
|
let that = this
|
||||||
|
teaweb.datepicker("day-input", function (day) {
|
||||||
|
that.day = day
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1 +0,0 @@
|
|||||||
undefined
|
|
||||||
26
web/views/@default/servers/server/log/today.html
Normal file
26
web/views/@default/servers/server/log/today.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{$layout}
|
||||||
|
|
||||||
|
{$template "/left_menu"}
|
||||||
|
<div class="right-box">
|
||||||
|
<first-menu>
|
||||||
|
<menu-item :href="path + '?serverId=' + serverId" :active="hasError == 0">所有日志</menu-item>
|
||||||
|
<menu-item :href="path + '?serverId=' + serverId + '&hasError=1'" :active="hasError > 0">错误日志</menu-item>
|
||||||
|
</first-menu>
|
||||||
|
|
||||||
|
<p class="comment" v-if="accessLogs.length == 0">今天暂时还没有访问日志。</p>
|
||||||
|
|
||||||
|
<table class="ui table selectable" v-if="accessLogs.length > 0">
|
||||||
|
<!-- 这里之所以需要添加 :key,是因为要不然不会刷新显示 -->
|
||||||
|
<tr v-for="accessLog in accessLogs" :key="accessLog.requestId">
|
||||||
|
<td><http-access-log-box :v-access-log="accessLog"></http-access-log-box></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div v-if="accessLogs.length > 0">
|
||||||
|
<a :href="path + '?serverId=' + serverId + '&requestId=' + lastRequestId + '&hasError=' + hasError" v-if="hasPrev">上一页</a>
|
||||||
|
<span v-else class="disabled">上一页</span>
|
||||||
|
<span class="disabled"> | </span>
|
||||||
|
<a :href="path + '?serverId=' + serverId + '&requestId=' + nextRequestId + '&hasError=' + hasError" v-if="hasMore">下一页</a>
|
||||||
|
<span v-else class="disabled">下一页</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user