服务访问日志增加关键词搜索

This commit is contained in:
刘祥超
2021-06-04 10:15:31 +08:00
parent 0f5f175f08
commit 98f8fb3bec
7 changed files with 58 additions and 13 deletions

View File

@@ -21,6 +21,7 @@ func (this *HistoryAction) Init() {
func (this *HistoryAction) RunGet(params struct { func (this *HistoryAction) RunGet(params struct {
ServerId int64 ServerId int64
Day string Day string
Keyword string
RequestId string RequestId string
HasError int HasError int
@@ -31,6 +32,7 @@ func (this *HistoryAction) RunGet(params struct {
this.Data["path"] = this.Request.URL.Path this.Data["path"] = this.Request.URL.Path
this.Data["day"] = params.Day this.Data["day"] = params.Day
this.Data["keyword"] = params.Keyword
this.Data["accessLogs"] = []interface{}{} this.Data["accessLogs"] = []interface{}{}
this.Data["hasError"] = params.HasError this.Data["hasError"] = params.HasError
@@ -48,6 +50,7 @@ func (this *HistoryAction) RunGet(params struct {
ServerId: params.ServerId, ServerId: params.ServerId,
HasError: params.HasError > 0, HasError: params.HasError > 0,
Day: day, Day: day,
Keyword: params.Keyword,
Size: size, Size: size,
}) })
if err != nil { if err != nil {
@@ -80,6 +83,7 @@ func (this *HistoryAction) RunGet(params struct {
ServerId: params.ServerId, ServerId: params.ServerId,
HasError: params.HasError > 0, HasError: params.HasError > 0,
Day: day, Day: day,
Keyword: params.Keyword,
Size: size, Size: size,
Reverse: true, Reverse: true,
}) })

View File

@@ -20,9 +20,12 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct { func (this *IndexAction) RunGet(params struct {
ServerId int64 ServerId int64
RequestId string RequestId string
Keyword string
}) { }) {
this.Data["serverId"] = params.ServerId this.Data["serverId"] = params.ServerId
this.Data["requestId"] = params.RequestId this.Data["requestId"] = params.RequestId
this.Data["keyword"] = params.Keyword
this.Data["path"] = this.Request.URL.Path
// 记录最近使用 // 记录最近使用
_, err := this.RPC().LatestItemRPC().IncreaseLatestItem(this.AdminContext(), &pb.IncreaseLatestItemRequest{ _, err := this.RPC().LatestItemRPC().IncreaseLatestItem(this.AdminContext(), &pb.IncreaseLatestItemRequest{
@@ -40,6 +43,7 @@ func (this *IndexAction) RunGet(params struct {
func (this *IndexAction) RunPost(params struct { func (this *IndexAction) RunPost(params struct {
ServerId int64 ServerId int64
RequestId string RequestId string
Keyword string
Must *actions.Must Must *actions.Must
}) { }) {
@@ -49,6 +53,7 @@ func (this *IndexAction) RunPost(params struct {
RequestId: params.RequestId, RequestId: params.RequestId,
Size: 20, Size: 20,
Day: timeutil.Format("Ymd"), Day: timeutil.Format("Ymd"),
Keyword: params.Keyword,
Reverse: isReverse, Reverse: isReverse,
}) })
if err != nil { if err != nil {

View File

@@ -20,17 +20,20 @@ func (this *TodayAction) RunGet(params struct {
RequestId string RequestId string
ServerId int64 ServerId int64
HasError int HasError int
Keyword string
}) { }) {
size := int64(10) size := int64(10)
this.Data["path"] = this.Request.URL.Path this.Data["path"] = this.Request.URL.Path
this.Data["hasError"] = params.HasError this.Data["hasError"] = params.HasError
this.Data["keyword"] = params.Keyword
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{ resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
RequestId: params.RequestId, RequestId: params.RequestId,
ServerId: params.ServerId, ServerId: params.ServerId,
HasError: params.HasError > 0, HasError: params.HasError > 0,
Day: timeutil.Format("Ymd"), Day: timeutil.Format("Ymd"),
Keyword: params.Keyword,
Size: size, Size: size,
}) })
if err != nil { if err != nil {

View File

@@ -1,5 +1,5 @@
Vue.component("http-access-log-box", { Vue.component("http-access-log-box", {
props: ["v-access-log"], props: ["v-access-log", "v-keyword"],
data: function () { data: function () {
let accessLog = this.vAccessLog let accessLog = this.vAccessLog
if (accessLog.header != null && accessLog.header.Upgrade != null && accessLog.header.Upgrade.values != null && accessLog.header.Upgrade.values.$contains("websocket")) { if (accessLog.header != null && accessLog.header.Upgrade != null && accessLog.header.Upgrade.values != null && accessLog.header.Upgrade.values.$contains("websocket")) {
@@ -48,7 +48,7 @@ Vue.component("http-access-log-box", {
} }
}, },
template: `<div :style="{'color': (accessLog.status >= 400) ? '#dc143c' : ''}" ref="box"> template: `<div :style="{'color': (accessLog.status >= 400) ? '#dc143c' : ''}" ref="box">
<span v-if="accessLog.region != null && accessLog.region.length > 0" class="grey">[{{accessLog.region}}]</span> {{accessLog.remoteAddr}} [{{accessLog.timeLocal}}] <em>&quot;{{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}}&quot; </em> {{accessLog.status}} <code-label v-if="accessLog.attrs != null && accessLog.attrs['cache.status'] == 'HIT'">cache hit</code-label> <code-label v-if="accessLog.attrs != null && accessLog.attrs['waf.action'] != null && accessLog.attrs['waf.action'].length > 0">waf {{accessLog.attrs['waf.action']}}</code-label> - 耗时:{{formatCost(accessLog.requestTime)}} ms <span v-if="accessLog.region != null && accessLog.region.length > 0" class="grey">[{{accessLog.region}}]</span> <keyword :v-word="vKeyword">{{accessLog.remoteAddr}}</keyword> [{{accessLog.timeLocal}}] <em>&quot;<keyword :v-word="vKeyword">{{accessLog.requestMethod}}</keyword> {{accessLog.scheme}}://<keyword :v-word="vKeyword">{{accessLog.host}}</keyword><keyword :v-word="vKeyword">{{accessLog.requestURI}}</keyword> <a :href="accessLog.scheme + '://' + accessLog.host + accessLog.requestURI" target="_blank" title="新窗口打开" class="disabled"><i class="external icon tiny"></i> </a> {{accessLog.proto}}&quot; </em> <keyword :v-word="vKeyword">{{accessLog.status}}</keyword> <code-label v-if="accessLog.attrs != null && accessLog.attrs['cache.status'] == 'HIT'">cache hit</code-label> <code-label v-if="accessLog.attrs != null && accessLog.attrs['waf.action'] != null && accessLog.attrs['waf.action'].length > 0">waf {{accessLog.attrs['waf.action']}}</code-label> - 耗时:{{formatCost(accessLog.requestTime)}} ms
&nbsp; <a href="" @click.prevent="showLog" title="查看详情"><i class="icon expand"></i></a> &nbsp; <a href="" @click.prevent="showLog" title="查看详情"><i class="icon expand"></i></a>
</div>` </div>`
}) })

View File

@@ -13,12 +13,15 @@
<div class="right-box"> <div class="right-box">
<first-menu> <first-menu>
<menu-item :href="path + '?serverId=' + serverId + '&day=' + day" :active="hasError == 0">所有日志</menu-item> <menu-item :href="path + '?serverId=' + serverId + '&day=' + day + '&keyword=' + keyword" :active="hasError == 0">所有日志</menu-item>
<menu-item :href="path + '?serverId=' + serverId + '&day=' + day + '&hasError=1'" :active="hasError > 0">错误日志</menu-item> <menu-item :href="path + '?serverId=' + serverId + '&day=' + day + '&hasError=1' + '&keyword=' + keyword" :active="hasError > 0">错误日志</menu-item>
<div class="item right"> <div class="item right">
<form method="get" class="ui form small" :action="path" autocomplete="off"> <form method="get" class="ui form small" :action="path" autocomplete="off">
<input type="hidden" name="serverId" :value="serverId"/> <input type="hidden" name="serverId" :value="serverId"/>
<div class="ui fields inline"> <div class="ui fields inline">
<div class="ui field">
<input type="text" name="keyword" v-model="keyword" placeholder="IP、域名、路径等..."/>
</div>
<div class="ui field"> <div class="ui field">
<input type="text" name="day" maxlength="10" placeholder="选择日期" style="width:7.8em" id="day-input" v-model="day"/> <input type="text" name="day" maxlength="10" placeholder="选择日期" style="width:7.8em" id="day-input" v-model="day"/>
</div> </div>
@@ -35,15 +38,15 @@
<table class="ui table selectable" v-if="accessLogs.length > 0"> <table class="ui table selectable" v-if="accessLogs.length > 0">
<!-- 这里之所以需要添加 :key是因为要不然不会刷新显示 --> <!-- 这里之所以需要添加 :key是因为要不然不会刷新显示 -->
<tr v-for="accessLog in accessLogs" :key="accessLog.requestId"> <tr v-for="accessLog in accessLogs" :key="accessLog.requestId">
<td><http-access-log-box :v-access-log="accessLog"></http-access-log-box></td> <td><http-access-log-box :v-access-log="accessLog" :v-keyword="keyword"></http-access-log-box></td>
</tr> </tr>
</table> </table>
<div v-if="accessLogs.length > 0"> <div v-if="accessLogs.length > 0">
<a :href="path + '?serverId=' + serverId + '&requestId=' + lastRequestId + '&day=' + day + '&hasError=' + hasError" v-if="hasPrev">上一页</a> <a :href="path + '?serverId=' + serverId + '&requestId=' + lastRequestId + '&day=' + day + '&hasError=' + hasError + '&keyword=' + keyword" v-if="hasPrev">上一页</a>
<span v-else class="disabled">上一页</span> <span v-else class="disabled">上一页</span>
<span class="disabled">&nbsp; | &nbsp;</span> <span class="disabled">&nbsp; | &nbsp;</span>
<a :href="path + '?serverId=' + serverId + '&requestId=' + nextRequestId + '&day=' + day + '&hasError=' + hasError" v-if="hasMore">下一页</a> <a :href="path + '?serverId=' + serverId + '&requestId=' + nextRequestId + '&day=' + day + '&hasError=' + hasError + '&keyword=' + keyword" v-if="hasMore">下一页</a>
<span v-else class="disabled">下一页</span> <span v-else class="disabled">下一页</span>
</div> </div>
</div> </div>

View File

@@ -2,12 +2,28 @@
{$template "/left_menu"} {$template "/left_menu"}
<div class="right-box"> <div class="right-box">
<first-menu>
<div class="item right">
<form method="get" class="ui form small" :action="path" autocomplete="off">
<input type="hidden" name="serverId" :value="serverId"/>
<div class="ui fields inline">
<div class="ui field">
<input type="text" name="keyword" v-model="keyword" placeholder="IP、域名、路径等..."/>
</div>
<div class="ui field">
<button class="ui button small" type="submit">查找</button>
</div>
</div>
</form>
</div>
</first-menu>
<p class="comment" v-if="isLoaded && accessLogs.length == 0">今天暂时还没有访问日志。</p> <p class="comment" v-if="isLoaded && accessLogs.length == 0">今天暂时还没有访问日志。</p>
<table class="ui table selectable" v-if="accessLogs.length > 0"> <table class="ui table selectable" v-if="accessLogs.length > 0">
<!-- 这里之所以需要添加 :key是因为要不然不会刷新显示 --> <!-- 这里之所以需要添加 :key是因为要不然不会刷新显示 -->
<tr v-for="accessLog in accessLogs" :key="accessLog.requestId"> <tr v-for="accessLog in accessLogs" :key="accessLog.requestId">
<td><http-access-log-box :v-access-log="accessLog"></http-access-log-box></td> <td><http-access-log-box :v-access-log="accessLog" :v-keyword="keyword"></http-access-log-box></td>
</tr> </tr>
</table> </table>
</div> </div>

View File

@@ -3,8 +3,22 @@
{$template "/left_menu"} {$template "/left_menu"}
<div class="right-box"> <div class="right-box">
<first-menu> <first-menu>
<menu-item :href="path + '?serverId=' + serverId" :active="hasError == 0">所有日志</menu-item> <menu-item :href="path + '?serverId=' + serverId + '&keyword=' + keyword" :active="hasError == 0">所有日志</menu-item>
<menu-item :href="path + '?serverId=' + serverId + '&hasError=1'" :active="hasError > 0">错误日志</menu-item> <menu-item :href="path + '?serverId=' + serverId + '&hasError=1' + '&keyword=' + keyword" :active="hasError > 0">错误日志</menu-item>
<div class="item right">
<form method="get" class="ui form small" :action="path" autocomplete="off">
<input type="hidden" name="serverId" :value="serverId"/>
<div class="ui fields inline">
<div class="ui field">
<input type="text" name="keyword" v-model="keyword" placeholder="IP、域名、路径等..."/>
</div>
<div class="ui field">
<button class="ui button small" type="submit">查找</button>
</div>
</div>
</form>
</div>
</first-menu> </first-menu>
<p class="comment" v-if="accessLogs.length == 0">今天暂时还没有访问日志。</p> <p class="comment" v-if="accessLogs.length == 0">今天暂时还没有访问日志。</p>
@@ -12,15 +26,15 @@
<table class="ui table selectable" v-if="accessLogs.length > 0"> <table class="ui table selectable" v-if="accessLogs.length > 0">
<!-- 这里之所以需要添加 :key是因为要不然不会刷新显示 --> <!-- 这里之所以需要添加 :key是因为要不然不会刷新显示 -->
<tr v-for="accessLog in accessLogs" :key="accessLog.requestId"> <tr v-for="accessLog in accessLogs" :key="accessLog.requestId">
<td><http-access-log-box :v-access-log="accessLog"></http-access-log-box></td> <td><http-access-log-box :v-access-log="accessLog" :v-keyword="keyword"></http-access-log-box></td>
</tr> </tr>
</table> </table>
<div v-if="accessLogs.length > 0"> <div v-if="accessLogs.length > 0">
<a :href="path + '?serverId=' + serverId + '&requestId=' + lastRequestId + '&hasError=' + hasError" v-if="hasPrev">上一页</a> <a :href="path + '?serverId=' + serverId + '&requestId=' + lastRequestId + '&hasError=' + hasError + '&keyword=' + keyword" v-if="hasPrev">上一页</a>
<span v-else class="disabled">上一页</span> <span v-else class="disabled">上一页</span>
<span class="disabled">&nbsp; | &nbsp;</span> <span class="disabled">&nbsp; | &nbsp;</span>
<a :href="path + '?serverId=' + serverId + '&requestId=' + nextRequestId + '&hasError=' + hasError" v-if="hasMore">下一页</a> <a :href="path + '?serverId=' + serverId + '&requestId=' + nextRequestId + '&hasError=' + hasError + '&keyword=' + keyword" v-if="hasMore">下一页</a>
<span v-else class="disabled">下一页</span> <span v-else class="disabled">下一页</span>
</div> </div>
</div> </div>