可以修复单页或者全部服务日志

This commit is contained in:
GoEdgeLab
2022-03-23 17:31:53 +08:00
parent 3d45db8f3e
commit ee24baf7d6
11 changed files with 144 additions and 138 deletions

View File

@@ -1,19 +1,28 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package servers
package logs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/types"
"strings"
)
type FixLogAction struct {
type FixAction struct {
actionutils.ParentAction
}
func (this *FixLogAction) RunPost(params struct {
func (this *FixAction) RunPost(params struct {
LogIds []int64
}) {
var logIdStrings = []string{}
for _, logId := range params.LogIds {
logIdStrings = append(logIdStrings, types.String(logId))
}
defer this.CreateLogInfo("设置日志 %s 为已修复", strings.Join(logIdStrings, ", "))
_, err := this.RPC().NodeLogRPC().FixNodeLogs(this.AdminContext(), &pb.FixNodeLogsRequest{NodeLogIds: params.LogIds})
if err != nil {
this.ErrorPage(err)

View File

@@ -0,0 +1,25 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package logs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type FixAllAction struct {
actionutils.ParentAction
}
func (this *FixAllAction) RunPost(params struct {
}) {
defer this.CreateLogInfo("设置所有日志为已修复")
_, err := this.RPC().NodeLogRPC().FixAllNodeLogs(this.AdminContext(), &pb.FixAllNodeLogsRequest{})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -3,8 +3,10 @@ package logs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils/nodelogutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
@@ -14,8 +16,11 @@ type IndexAction struct {
}
func (this *IndexAction) Init() {
if this.ParamString("type") == "unread" {
var paramType = this.ParamString("type")
if paramType == "unread" {
this.FirstMenu("unread")
} else if paramType == "needFix" {
this.FirstMenu("needFix")
} else {
this.FirstMenu("index")
}
@@ -26,7 +31,7 @@ func (this *IndexAction) RunGet(params struct {
DayTo string
Keyword string
Level string
Type string
Type string // unread, needFix
Tag string
ClusterId int64
NodeId int64
@@ -40,6 +45,13 @@ func (this *IndexAction) RunGet(params struct {
this.Data["clusterId"] = params.ClusterId
this.Data["nodeId"] = params.NodeId
var fixedState configutils.BoolState = 0
var allServers = false
if params.Type == "needFix" {
fixedState = configutils.BoolStateNo
allServers = true
}
// 常见标签
this.Data["tags"] = nodelogutils.FindNodeCommonTags()
@@ -54,6 +66,18 @@ func (this *IndexAction) RunGet(params struct {
}
this.Data["countUnreadLogs"] = countUnreadResp.Count
// 需要修复数量
countNeedFixResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
Role: nodeconfigs.NodeRoleNode,
AllServers: true,
FixedState: int32(configutils.BoolStateNo),
})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["countNeedFixLogs"] = countNeedFixResp.Count
// 日志数量
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
NodeClusterId: params.ClusterId,
@@ -65,13 +89,15 @@ func (this *IndexAction) RunGet(params struct {
Level: params.Level,
IsUnread: params.Type == "unread",
Tag: params.Tag,
FixedState: int32(fixedState),
AllServers: allServers,
})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
var count = countResp.Count
var page = this.NewPage(count)
this.Data["page"] = page.AsHTML()
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
@@ -84,6 +110,8 @@ func (this *IndexAction) RunGet(params struct {
Level: params.Level,
IsUnread: params.Type == "unread",
Tag: params.Tag,
FixedState: int32(fixedState),
AllServers: allServers,
Offset: page.Offset,
Size: page.Size,
})
@@ -92,14 +120,14 @@ func (this *IndexAction) RunGet(params struct {
return
}
logs := []maps.Map{}
var logs = []maps.Map{}
for _, log := range logsResp.NodeLogs {
// 节点信息
nodeResp, err := this.RPC().NodeRPC().FindEnabledNode(this.AdminContext(), &pb.FindEnabledNodeRequest{NodeId: log.NodeId})
if err != nil {
continue
}
node := nodeResp.Node
var node = nodeResp.Node
if node == nil || node.NodeCluster == nil {
continue
}
@@ -118,6 +146,11 @@ func (this *IndexAction) RunGet(params struct {
}
}
var isFixed = true
if !log.IsFixed && log.ServerId > 0 && lists.ContainsString([]string{"success", "warning", "error"}, log.Level) {
isFixed = false
}
logs = append(logs, maps.Map{
"id": log.Id,
"tag": log.Tag,
@@ -127,6 +160,7 @@ func (this *IndexAction) RunGet(params struct {
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
"count": log.Count,
"isRead": log.IsRead,
"isFixed": isFixed,
"node": maps.Map{
"id": node.Id,
"cluster": maps.Map{

View File

@@ -16,6 +16,8 @@ func init() {
Get("", new(IndexAction)).
Post("/readLogs", new(ReadLogsAction)).
Post("/readAllLogs", new(ReadAllLogsAction)).
Post("/fix", new(FixAction)).
Post("/fixAll", new(FixAllAction)).
EndAll()
})
}

View File

@@ -5,7 +5,6 @@ import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/maps"
@@ -260,72 +259,16 @@ func (this *IndexAction) RunGet(params struct {
// 是否有用户管理权限
this.Data["canVisitUser"] = configloaders.AllowModule(this.AdminId(), configloaders.AdminModuleCodeUser)
// 显示服务相关的日志
errorLogsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
NodeId: 0,
Role: nodeconfigs.NodeRoleNode,
Offset: 0,
Size: 20,
Level: "error,success,warning",
FixedState: int32(configutils.BoolStateNo),
// 显示服务需要修复的日志数量
countNeedFixLogsResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
AllServers: true,
FixedState: int32(configutils.BoolStateNo),
})
if err != nil {
this.ErrorPage(err)
return
}
errorLogMaps := []maps.Map{}
for _, errorLog := range errorLogsResp.NodeLogs {
serverResp, err := this.RPC().ServerRPC().FindEnabledUserServerBasic(this.AdminContext(), &pb.FindEnabledUserServerBasicRequest{ServerId: errorLog.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
// 服务
var server = serverResp.Server
if server == nil {
// 设置为已修复
_, err = this.RPC().NodeLogRPC().FixNodeLogs(this.AdminContext(), &pb.FixNodeLogsRequest{NodeLogIds: []int64{errorLog.Id}})
if err != nil {
this.ErrorPage(err)
return
}
continue
}
// 节点
nodeResp, err := this.RPC().NodeRPC().FindEnabledNode(this.AdminContext(), &pb.FindEnabledNodeRequest{NodeId: errorLog.NodeId})
if err != nil {
this.ErrorPage(err)
return
}
var node = nodeResp.Node
if node == nil || node.NodeCluster == nil {
// 设置为已修复
_, err = this.RPC().NodeLogRPC().FixNodeLogs(this.AdminContext(), &pb.FixNodeLogsRequest{NodeLogIds: []int64{errorLog.Id}})
if err != nil {
this.ErrorPage(err)
return
}
continue
}
errorLogMaps = append(errorLogMaps, maps.Map{
"id": errorLog.Id,
"description": errorLog.Description,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", errorLog.CreatedAt),
"serverId": errorLog.ServerId,
"level": errorLog.Level,
"serverName": server.Name,
"nodeId": node.Id,
"nodeName": node.Name,
"clusterId": node.NodeCluster.Id,
})
}
this.Data["errorLogs"] = errorLogMaps
this.Data["countNeedFixLogs"] = countNeedFixLogsResp.Count
this.Show()
}

View File

@@ -17,7 +17,6 @@ func init() {
Get("", new(IndexAction)).
GetPost("/create", new(CreateAction)).
GetPost("/update", new(UpdateAction)).
Post("/fixLog", new(FixLogAction)).
Post("/nearby", new(NearbyAction)).
//

View File

@@ -1,4 +1,5 @@
<first-menu>
<menu-item href="/clusters/logs" code="index">所有</menu-item>
<menu-item href="/clusters/logs?type=unread" code="unread">未读<span :class="{red: countUnreadLogs > 0}">({{countUnreadLogs}})</span></menu-item>
<menu-item href="/clusters/logs?type=needFix" code="needFix">需修复<span :class="{red: countNeedFixLogs > 0}">({{countNeedFixLogs}})</span></menu-item>
</first-menu>

View File

@@ -46,6 +46,7 @@
</div>
</form>
<!-- 未读操作 -->
<div v-if="type == 'unread'">
<div class="ui divider" style="margin-bottom: 0"></div>
<second-menu v-if="logs.length > 0">
@@ -54,7 +55,17 @@
</second-menu>
</div>
<p class="comment" v-if="logs.length == 0">暂时还没有日志。</p>
<!-- 未修复操作 -->
<div v-if="type == 'needFix'">
<div class="ui divider" style="margin-bottom: 0"></div>
<second-menu v-if="logs.length > 0">
<a href="" class="item" @click.prevent="fixPageLogs()">[本页已修复]</a>
<a href="" class="item" @click.prevent="fixAllLogs()">[全部已修复]</a>
</second-menu>
<p class="ui message" v-if="logs.length > 0">已合并重复内容,当前显示数据和总数量可能不一致。</p>
</div>
<p class="comment" v-if="logs.length == 0">暂时还没有<span v-if="type == 'unread'">未读</span><span v-if="type == 'needFix'">需修复</span>日志。</p>
<table class="ui table selectable celled" v-if="logs.length > 0">
<thead>
@@ -62,7 +73,7 @@
<th>集群</th>
<th>节点</th>
<th>信息</th>
<th class="one op">操作</th>
<th style="width: 5em">操作</th>
</tr>
</thead>
<tr v-for="log in logs">
@@ -72,7 +83,8 @@
<node-log-row :v-log="log" :v-keyword="keyword"></node-log-row>
</td>
<td>
<a href="" @click.prevent="updateRead(log.id)" v-if="!log.isRead"></a>
<a href="" v-if="!log.isFixed" @click.prevent="fixLog(log.id)">修复</a>
<a href="" @click.prevent="updateRead(log.id)" v-if="log.isFixed && !log.isRead">已读</a>
</td>
</tr>
</table>

View File

@@ -18,8 +18,43 @@ Tea.context(function () {
let logIds = this.logs.map(function (v) {
return v.id
})
teaweb.confirm("确定要设置本页日志为已读吗?", function () {
this.$post(".readLogs")
this.$post(".readLogs")
.params({
logIds: logIds
})
.success(function () {
teaweb.reload()
})
}
this.updateAllRead = function () {
this.$post(".readAllLogs")
.params({})
.success(function () {
teaweb.reload()
})
}
this.changeCluster = function (clusterId) {
this.clusterId = clusterId
}
this.fixLog = function (logId) {
this.$post(".fixLogs")
.params({
logIds: [logId]
})
.success(function () {
teaweb.reload()
})
}
this.fixPageLogs = function () {
let logIds = this.logs.map(function (v) {
return v.id
})
teaweb.confirm("确定已修复并消除当前页的问题?", function () {
this.$post(".fix")
.params({
logIds: logIds
})
@@ -29,17 +64,12 @@ Tea.context(function () {
})
}
this.updateAllRead = function () {
teaweb.confirm("确定要设置所有日志为已读吗", function () {
this.$post(".readAllLogs")
.params({})
this.fixAllLogs = function () {
teaweb.confirm("确定已修复并消除所有的问题", function () {
this.$post(".fixAll")
.success(function () {
teaweb.reload()
})
})
}
this.changeCluster = function (clusterId) {
this.clusterId = clusterId
}
})

View File

@@ -2,24 +2,12 @@
{$template "menu"}
<!-- 错误日志 -->
<div v-if="errorLogs.length > 0">
<div v-if="countNeedFixLogs > 0">
<div class="margin"></div>
<div class="ui menu tabular attached">
<span class="ui item active"><span class="red">需要修复的错误 &nbsp; <a href="" title="本页已修复" @click.prevent="fixPageLogs"><i class="icon remove small"></i> </a></span></span>
</div>
<div class="ui segment attached node-logs-box">
<div class="ui icon message small" v-for="log in errorLogs" :class="{error: log.level == 'error', success: log.level == 'success'}">
<i class="icon warning circle"></i>
<div class="content">
[{{log.createdTime}}]
<a :href="'/clusters/cluster/node?clusterId=' + log.clusterId + '&nodeId=' + log.nodeId">[节点:{{log.nodeName}}]</a>
<a :href="'/servers/server/settings?serverId=' + log.serverId"><span v-if="log.serverName.length > 0">[服务:{{log.serverName}}]</span><span v-else>[服务]</span></a>
<span v-if="log.level == 'error'">[错误]</span>
<span v-if="log.level == 'success'">[成功]</span>
{{log.description}}
</div>
<a href="" title="关闭" @click.prevent="fixLog(log.id)"><i class="ui icon remove small"></i></a>
</div>
<div class="ui icon message small error">
<i class="icon warning circle"></i>
<div class="content"><a href="/clusters/logs?type=needFix">有{{countNeedFixLogs}}个网站服务相关的错误需要修复。</a></div>
</div>
</div>

View File

@@ -46,41 +46,4 @@ Tea.context(function () {
this.showLatest = function () {
this.latestVisible = !this.latestVisible
}
/**
* 错误日志相关
*/
this.fixLog = function (logId) {
let that = this
teaweb.confirm("确定要关闭此错误提示吗?", function () {
that.$post(".fixLog")
.params({
logIds: logId
})
.success(function () {
teaweb.reload()
})
})
}
this.fixPageLogs = function () {
let logIds = this.errorLogs.map(function (v) {
return v.id
})
if (logIds.length == 0) {
teaweb.reload()
return
}
let that = this
teaweb.confirm("确定要关闭此页错误提示吗?", function () {
that.$post(".fixLog")
.params({
logIds: logIds
})
.success(function () {
teaweb.reload()
})
})
}
})