mirror of https://github.com/shunfei/cronsun
返回节点是否连接到 etcd 的检测
parent
395b814e28
commit
ab33e3ca27
|
@ -23,7 +23,8 @@ type Node struct {
|
|||
ID string `bson:"_id" json:"id"` // ip
|
||||
PID string `bson:"pid" json:"pid"` // 进程 pid
|
||||
|
||||
Alived bool `bson:"alived" json:"alived"` // 是否可用
|
||||
Alived bool `bson:"alived" json:"alived"` // 是否可用
|
||||
Connected bool `bson:"-" json:"connected"` // 当 Alived 为 true 时有效,表示心跳是否正常
|
||||
}
|
||||
|
||||
func (n *Node) String() string {
|
||||
|
|
17
web/node.go
17
web/node.go
|
@ -103,5 +103,22 @@ func (n *Node) GetNodes(w http.ResponseWriter, r *http.Request) {
|
|||
outJSONError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
gresp, err := models.DefalutClient.Get(conf.Config.Proc, v3.WithPrefix(), v3.WithKeysOnly())
|
||||
if err == nil {
|
||||
connecedMap := make(map[string]bool, gresp.Count)
|
||||
for i := range gresp.Kvs {
|
||||
k := string(gresp.Kvs[i].Key)
|
||||
index := strings.LastIndexByte(k, '/')
|
||||
connecedMap[k[index+1:]] = true
|
||||
}
|
||||
|
||||
for i := range nodes {
|
||||
nodes[i].Connected = connecedMap[nodes[i].ID]
|
||||
}
|
||||
} else {
|
||||
log.Errorf("failed to fetch key[%s] from etcd: %s", conf.Config.Proc, err.Error())
|
||||
}
|
||||
|
||||
outJSONWithCode(w, http.StatusOK, nodes)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
<template>
|
||||
<div>
|
||||
<h3 class="ui horizontal divider header">当前节点: {{count}}</h3>
|
||||
<div v-for="node in nodes" v-bind:class="{blue:node.alived}" class="ui label"><i class="cube icon"></i> {{node.id}}</div>
|
||||
<div class="ui label" title="手动下线/维护中的"><i class="cube icon"></i> 已下线节点</div>
|
||||
<div class="ui label" title="正常运行的节点"><i class="green cube icon"></i> 正常节点</div>
|
||||
<div class="ui label" title="节点因自身或网络等原因未检测到"><i class="red cube icon"></i> 故障节点</div>
|
||||
<h3 class="ui horizontal divider header"> </h3>
|
||||
<div v-for="node in nodes" class="ui label"><i v-bind:class="{green: node.alived && node.connected, red: node.alived && !node.connected}" class="cube icon"></i> {{node.id}}</div
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
Loading…
Reference in New Issue