mirror of https://github.com/shunfei/cronsun
web: 增加结点存活判断
parent
efc714923c
commit
5991088eda
|
@ -6,6 +6,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
client "github.com/coreos/etcd/clientv3"
|
client "github.com/coreos/etcd/clientv3"
|
||||||
|
mgo "gopkg.in/mgo.v2"
|
||||||
"gopkg.in/mgo.v2/bson"
|
"gopkg.in/mgo.v2/bson"
|
||||||
|
|
||||||
"sunteng/commons/log"
|
"sunteng/commons/log"
|
||||||
|
@ -19,10 +20,10 @@ const (
|
||||||
// 执行 cron cmd 的进程
|
// 执行 cron cmd 的进程
|
||||||
// 注册到 /cronsun/proc/<id>
|
// 注册到 /cronsun/proc/<id>
|
||||||
type Node struct {
|
type Node struct {
|
||||||
ID string `bson:"_id" json:"-"` // ip
|
ID string `bson:"_id" json:"id"` // ip
|
||||||
PID string `bson:"pid" json:"pid"` // 进程 pid
|
PID string `bson:"pid" json:"pid"` // 进程 pid
|
||||||
|
|
||||||
Alived bool `bson:"alived" json:"-"` // 是否可用
|
Alived bool `bson:"alived" json:"alived"` // 是否可用
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) String() string {
|
func (n *Node) String() string {
|
||||||
|
@ -69,16 +70,10 @@ func (n *Node) Exist() (pid int, err error) {
|
||||||
return -1, nil
|
return -1, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetActivityNodeList() (nodes []string, err error) {
|
func GetNodes() (nodes []*Node, err error) {
|
||||||
resp, err := DefalutClient.Get(conf.Config.Proc, client.WithPrefix(), client.WithKeysOnly(), client.WithSort(client.SortByKey, client.SortAscend))
|
err = mgoDB.WithC(Coll_Node, func(c *mgo.Collection) error {
|
||||||
if err != nil {
|
return c.Find(nil).All(&nodes)
|
||||||
return
|
})
|
||||||
}
|
|
||||||
|
|
||||||
procKeyLen := len(conf.Config.Proc)
|
|
||||||
for _, n := range resp.Kvs {
|
|
||||||
nodes = append(nodes, string(n.Key[procKeyLen:]))
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,11 +97,11 @@ func (n *Node) DeleteGroup(w http.ResponseWriter, r *http.Request) {
|
||||||
outJSONWithCode(w, http.StatusNoContent, nil)
|
outJSONWithCode(w, http.StatusNoContent, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) GetActivityNodeList(w http.ResponseWriter, r *http.Request) {
|
func (n *Node) GetNodes(w http.ResponseWriter, r *http.Request) {
|
||||||
ids, err := models.GetActivityNodeList()
|
nodes, err := models.GetNodes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
outJSONError(w, http.StatusInternalServerError, err.Error())
|
outJSONError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
outJSONWithCode(w, http.StatusOK, ids)
|
outJSONWithCode(w, http.StatusOK, nodes)
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,20 +43,20 @@ func InitRouters() (s *http.Server, err error) {
|
||||||
h = BaseHandler{Handle: jobLogHandler.GetDetail}
|
h = BaseHandler{Handle: jobLogHandler.GetDetail}
|
||||||
subrouter.Handle("/log/{id}", h).Methods("GET")
|
subrouter.Handle("/log/{id}", h).Methods("GET")
|
||||||
|
|
||||||
h = BaseHandler{Handle: nodeHandler.GetActivityNodeList}
|
h = BaseHandler{Handle: nodeHandler.GetNodes}
|
||||||
subrouter.Handle("/node/activitys", h).Methods("GET")
|
subrouter.Handle("/nodes", h).Methods("GET")
|
||||||
// get node group list
|
// get node group list
|
||||||
h = BaseHandler{Handle: nodeHandler.GetGroups}
|
h = BaseHandler{Handle: nodeHandler.GetGroups}
|
||||||
subrouter.Handle("/node/groups", h).Methods("GET")
|
subrouter.Handle("/nodes/groups", h).Methods("GET")
|
||||||
// get a node group by group id
|
// get a node group by group id
|
||||||
h = BaseHandler{Handle: nodeHandler.GetGroupByGroupId}
|
h = BaseHandler{Handle: nodeHandler.GetGroupByGroupId}
|
||||||
subrouter.Handle("/node/group/{id}", h).Methods("GET")
|
subrouter.Handle("/nodes/group/{id}", h).Methods("GET")
|
||||||
// create/update a node group
|
// create/update a node group
|
||||||
h = BaseHandler{Handle: nodeHandler.UpdateGroup}
|
h = BaseHandler{Handle: nodeHandler.UpdateGroup}
|
||||||
subrouter.Handle("/node/group", h).Methods("PUT")
|
subrouter.Handle("/nodes/group", h).Methods("PUT")
|
||||||
// delete a node group
|
// delete a node group
|
||||||
h = BaseHandler{Handle: nodeHandler.DeleteGroup}
|
h = BaseHandler{Handle: nodeHandler.DeleteGroup}
|
||||||
subrouter.Handle("/node/group", h).Methods("DELETE")
|
subrouter.Handle("/nodes/group", h).Methods("DELETE")
|
||||||
|
|
||||||
uidir := conf.Config.Web.UIDir
|
uidir := conf.Config.Web.UIDir
|
||||||
if len(uidir) == 0 {
|
if len(uidir) == 0 {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<router-link class="item" to="/" v-bind:class="{active: this.$route.path == '/'}"><i class="dashboard icon"></i> 仪表盘</router-link>
|
<router-link class="item" to="/" v-bind:class="{active: this.$route.path == '/'}"><i class="dashboard icon"></i> 仪表盘</router-link>
|
||||||
<router-link class="item" to="/log" v-bind:class="{active: this.$route.path.indexOf('/log') === 0}"><i class="file text icon"></i> 日志</router-link>
|
<router-link class="item" to="/log" v-bind:class="{active: this.$route.path.indexOf('/log') === 0}"><i class="file text icon"></i> 日志</router-link>
|
||||||
<router-link class="item" to="/job" v-bind:class="{active: this.$route.path.indexOf('/job') === 0}"><i class="calendar icon"></i> 任务</router-link>
|
<router-link class="item" to="/job" v-bind:class="{active: this.$route.path.indexOf('/job') === 0}"><i class="calendar icon"></i> 任务</router-link>
|
||||||
<router-link class="item" to="/node" v-bind:class="{active: this.$route.path.indexOf('/node') === 0}"><i class="server icon"></i> 节点</router-link>
|
<router-link class="item" to="/nodes" v-bind:class="{active: this.$route.path.indexOf('/nodes') === 0}"><i class="server icon"></i> 节点</router-link>
|
||||||
</div>
|
</div>
|
||||||
<div style="height: 55px;"></div>
|
<div style="height: 55px;"></div>
|
||||||
<div class="ui container">
|
<div class="ui container">
|
||||||
|
|
|
@ -35,8 +35,8 @@ export default {
|
||||||
|
|
||||||
mounted: function(){
|
mounted: function(){
|
||||||
var vm = this;
|
var vm = this;
|
||||||
this.$rest.GET('node/activitys').onsucceed(200, (resp)=>{vm.activityNodes = resp}).do();
|
this.$rest.GET('nodes').onsucceed(200, (resp)=>{vm.activityNodes = resp}).do();
|
||||||
this.$rest.GET('node/groups').onsucceed(200, (resp)=>{
|
this.$rest.GET('nodes/groups').onsucceed(200, (resp)=>{
|
||||||
var groups = [];
|
var groups = [];
|
||||||
for (var i in resp) {
|
for (var i in resp) {
|
||||||
groups.push({value: resp[i].id, name: resp[i].name});
|
groups.push({value: resp[i].id, name: resp[i].name});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<h3 class="ui horizontal divider header">当前活动节点: {{count}}</h3>
|
<h3 class="ui horizontal divider header">当前节点: {{count}}</h3>
|
||||||
<div class="ui label" v-for="node in nodes"><i class="cube icon"></i> {{node}}</div>
|
<div v-for="node in nodes" v-bind:class="{blue:node.alived}" class="ui label"><i class="cube icon"></i> {{node.id}}</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ export default {
|
||||||
|
|
||||||
mounted: function(){
|
mounted: function(){
|
||||||
var vm = this;
|
var vm = this;
|
||||||
this.$rest.GET('node/activitys').onsucceed(200, (resp)=>{
|
this.$rest.GET('nodes').onsucceed(200, (resp)=>{
|
||||||
vm.nodes = resp;
|
vm.nodes = resp;
|
||||||
vm.count = resp.length;
|
vm.count = resp.length;
|
||||||
}).do();
|
}).do();
|
||||||
|
|
|
@ -35,7 +35,7 @@ var routes = [
|
||||||
{path: '/job', component: Job},
|
{path: '/job', component: Job},
|
||||||
{path: '/job/create', component: JobEdit},
|
{path: '/job/create', component: JobEdit},
|
||||||
{path: '/job/edit/:group/:id', component: JobEdit},
|
{path: '/job/edit/:group/:id', component: JobEdit},
|
||||||
{path: '/node', component: Node}
|
{path: '/nodes', component: Node}
|
||||||
];
|
];
|
||||||
|
|
||||||
var router = new VueRouter({
|
var router = new VueRouter({
|
||||||
|
|
Loading…
Reference in New Issue