Authored by fanzelei

zk配置

... ... @@ -25,6 +25,7 @@ public class HttpUriContants {
public static String TYPE_UPDATE = "/type/update";
public static String TYPE_QUERY_NODE = "/type/queryNode";
public static String TYPE_QUERY_JAVAAPI = "/type/queryJavaApi";
public static String TYPE_GET_ZKTREE = "/type/queryZk";
/***
* 主机信息
... ... @@ -57,6 +58,7 @@ public class HttpUriContants {
* ZK监控信息查询
****/
public static final String GET_ZK_INFO = "/zkMonitor/getZkMonitorRecords";
public static final String GET_ZK_TREE = "/zkMonitor/getZkMonitorTree";
/***
* redis监控信息查询
... ...
package com.ui.model.req;
import lombok.Data;
@Data
public class ZkTreeReq extends PageRequest{
private String ip;
private String name;
private String root;
}
... ...
... ... @@ -103,5 +103,19 @@ public class TypeCtrl {
BaseResponse response=httpClient.defaultGet(HttpUriContants.TYPE_QUERY_JAVAAPI, BaseResponse.class);
return response;
}
@RequestMapping("/zkTree")
@ResponseBody
public String getZkTree() {
String strType = "";
log.debug("get zkTree");
strType = httpClient.defaultGet(HttpUriContants.TYPE_GET_ZKTREE, String.class);
log.info("zkTree: {}", strType);
return strType;
}
}
... ...
package com.ui.ctrl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.req.ZkTreeReq;
/**
*
* @author yoho
*
*/
@Controller
@RequestMapping("zkTree")
public class ZkMonitorTree {
Logger log = LoggerFactory.getLogger(ZkMonitorTree.class);
@Autowired
private HttpRestClient httpClient;
@RequestMapping("/getRoot")
@ResponseBody
public BaseResponse getRoot(ZkTreeReq req){
log.info("getRoot with req is {}",req);
BaseResponse response=httpClient.defaultPost(HttpUriContants.GET_ZK_TREE, req, BaseResponse.class);
return response;
}
}
... ...
... ... @@ -98,8 +98,8 @@
</li>
<li class="" id="zkInfo"><a href="?page_type=zkInfo"><i class="icon icon-th"></i><span>ZK监控</span></a>
</li>
<!-- <li class="" id="zkMonitor"><a href="?page_type=zkMonitor"><i class="icon icon-th"></i><span>ZK配置管理</span></a>
</li> -->
<li class="" id="zkMonitor"><a href="?page_type=zkMonitor"><i class="icon icon-th"></i><span>ZK配置管理</span></a>
</li>
<li class="" id="rabbitview"><a href="?page_type=rabbitview"><i class="icon icon-th"></i><span>Rabbitmq监控</span></a>
</li>
<li class="" id="redisInfo"><a href="?page_type=redisInfo"><i class="icon icon-th"></i><span>Redis监控</span></a>
... ... @@ -109,31 +109,7 @@
<li class="" id="ProjectRelease"><a href="?page_type=projectRelease"><i
class="icon icon-th"></i><span>项目发布</span></a>
</li>
<li class="submenu">
<a href="#"><i class="icon icon-th-list"></i> <span>其他</span></a>
<ul>
<li class="">
<a href="#" id="rabbitmqMenu"><i class="icon icon-th-list"></i> <span>rabbitmq dashboard</span></a>
<ul style="display:none" id="rabbitmqUl">
<li><a href="http://rabbit-aws.yohops.com/" target="_blank">aws交易</a></li>
<li><a href="http://rabbit-aws-common.yohops.com/" target="_blank">aws通用</a></li>
<li><a href="http://rabbit-qq.yohops.com/" target="_blank">qq交易</a></li>
<li><a href="http://rabbit-qq-common.yohops.com/" target="_blank">qq通用</a></li>
</ul>
</li>
<li class="">
<a href="#" id="monitorMenu"><i class="icon icon-th-list"></i> <span>微服务监控</span></a>
<ul style="display:none" id="monitorUl">
<li><a href="http://aws-monitor.yohops.com/" target="_blank">aws</a></li>
<li><a href="http://aws-monitor.yohops.com/" target="_blank">Qcloud</a></li>
</ul>
</li>
<li><a href="http://g.yohops.com" target="_blank">grafana dashboard</a></li>
<li><a href="http://zk.yohops.com" target="_blank">zookeeper dashboard</a></li>
<li><a href="http://dev.yohops.com" target="_blank">开发运维信息查询</a></li>
<li><a href="http://kibana.yoho.cn/" target="_blank">kibana</a></li>
</ul>
</li>
<li class="" id="others"><a href="?page_type=others"><i class="icon icon-home"></i> <span>其他</span></a></li>
</ul>
</div>
<!-- 右侧具体内容 -->
... ... @@ -156,7 +132,8 @@
"projectRelease": '/jsp/project/projectRelease.jsp',
"rabbitInfo": '/jsp/mobject/rabbitmq.jsp',
"zkMonitor":'/jsp/zkMonitor/zkMonitorList.jsp',
"dashBoard":'/jsp/dashBoard/dashBoard.jsp'
"dashBoard":'/jsp/dashBoard/dashBoard.jsp',
"others":'/jsp/dashBoard/dashBoard.jsp'
};
var page_type = "<%=page_type %>";
var page_url = "<%=page_url %>";
... ...
... ... @@ -74,7 +74,7 @@
class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a> <a href="http://aws-monitor.yohops.com/" target="_blank">
</a> <a href="http://qq-monitor.yohops.com" target="_blank">
<div class="panel-footer">
<span class="pull-left">Qcloud</span> <span class="pull-right"><i
class="fa fa-arrow-circle-right"></i></span>
... ...
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<form class="form-horizontal" id="javaInfoForm" name="javaInfoForm">
<div class="form-group">
<label class="col-sm-2 control-label"> <span style="color:red">*</span>服务名:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="apiName" name="apiName" placeholder="输入服务名" maxlength="30"
size="40"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"> <span style="color:red">*</span>url:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="apiUrl" name="apiUrl" placeholder="输入url"
size="40"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"> <span style="color:red">*</span>类别:</label>
<div class="col-sm-2">
<select id="serviceType" name="serviceType" class="form-control">
</select>
</div>
<label class="col-sm-2 control-label"> <span style="color:red">*</span>请求:</label>
<div class="col-sm-2">
<select id="apiReqMethod" name="apiReqMethod" class="form-control">
<option value="0">GET</option>
<option value="1">POST</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">是否启用:</label>
<div class="col-sm-2">
<input type="checkbox" id="apiToggle" name="apiToggle">
</div>
<label class="col-sm-2 control-label"> <span style="color:red">*</span>告警阈值:</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="apiWarnTrigger" name="apiWarnTrigger" placeholder="输入告警阈值"
maxlength="30" size="40"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">请求参数:</label>
<div class="col-sm-8">
<textarea id="apiData" name="apiData" class="form-control" rows="3"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-8" id="messageAlert"></div>
</div>
</form>
... ...
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<div id="breadcrumb">
<a href="#" title="Go to Home" class="tip-bottom"><i
class="icon-home"></i> Home</a> <a href="#" class="current">监控对象</a>
</div>
<div class="container-fluid">
<div class="widget-box">
<div class="widget-title">
<h5>ZK配置</h5>
</div>
<!-- 树 -->
<div style="float: left;width: 300px;color: #D3D3D3;height: 600px;">
<div class="widget-title" style="height: 50px;">
<h5>节点展示</h5>
</div>
<div class="tree_container" style="height: 540px;color: black;overflow:auto;">
<div id="jstree" class="jstree jstree-default" role="tree" aria-multiselectable="true"
tabindex="0"></div>
</div>
</div>
<!-- 列表 -->
<div class="widget-content nopadding" style="border-left: 1px solid #E5E5E5;width: 800px;float: left;">
<div class="widget-title" style="height: 50px;">
<h5>根路径</h5>
</div>
<div class="widget-content nopadding">
<div class="tree_container" style="height: 540px;color: black;overflow:auto;">
<div id="rootTable"></div>
</div>
</div>
</div>
<div class="widget-content nopadding" style="margin-left: 1100px;border-left: 1px solid #E5E5E5;">
<div class="widget-title" style="height: 50px;">
<h5>节点详情</h5>
</div>
<div class="widget-content nopadding">
<div class="tree_container" style="height: 540px;color: black;overflow:auto;">
<div id="detailTable"></div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="<%=basePath %>/script/yoho.type.zktree.js"></script>
<script>
function toDetail(rowData){
$("#detailTable").show();
$(function () {
$("#detailTable").table({
url: contextPath + "/mobject/query",
striped: true,
panelClass: "panel-success",
pagination: true,
pageSize: 10,
loadFilter: function (data) {
return defaultLoadFilter(data);
},
columns: [{
title: "名称",
field: "moName"
}, {
title: "值",
field: "zkValue"
}, {
title: "操作",
formatter: function (value, rowData, rowIndex) {
var div = $("<div>");
//修改
var editBtn = $("<button data-target='#updateModal' data-toggle='modal'>").addClass("btn btn-xs btn-success").html("修改").appendTo(div);
editBtn.click(function () {
updateMObject(rowData);
});
return div;
}
}],
});
});
}
function updateMObject(rowData){
}
</script>
\ No newline at end of file
... ...
/**
* Created by frw on 2016/6/17.
*/
var treeData = [];
var nodeId2id = function (nodeid) {
if (nodeid == "#") {
return 0;
} else {
return nodeid.split("_")[1];
}
};
var getPath = function (nodeid) {
var paths = [];
var num = 0;
var currentId = nodeid;
while (currentId != "#") {
var node = $("#jstree").jstree().get_node(currentId);
paths.push(node.text);
num++;
currentId = node.parent;
}
var strPath = "";
for (var i = 0; i < num; i++) {
strPath += paths.pop() + "/";
}
return strPath;
}
var openTree = function (node_id, level) {
// console.log("open tree" + node_id);
try {
var node = $("#jstree").jstree().get_node(node_id);
$("#jstree").jstree("open_node", node);
var children = node.children;
} catch (e) {
console.warn(e);
return;
}
// console.log("open children" +children);
if (level <= 1)
return;
level--;
$.each(children, function (n, data) {
openTree(data, level);
});
}
var addType = function (node) {
var rel = 0;
var pid;
var name;
var isleaf;
$('#modal_type_update').hide();
$('#modal_type_del').hide();
$('#modal_type_add').show();
$('#myModalLabel').html("添加类型");
$('#cb_new_type_isleaf').prop("checked", true);// 默认为子节点
$('#tx_new_type_name').val("");
$('#tx_type_id').val(nodeId2id(node.id));
$('#tx_type_action').val("add");
$('#tx_new_type_isleaf').val(1);
$('#tx_new_type_parent').val(getPath(node.id));
$('#myModal').modal({keyboard: true});
return rel;
};
var doAddType = function () {
var pid = $('#tx_type_id').val();
var name = $('#tx_new_type_name').val();
if (name == null || $('#tx_new_type_name').val() == "") {
$.toaster('输入类型名', '提示', 'warning');
return;
}
var isleaf = $('#cb_new_type_isleaf').prop("checked") == true ? 1 : 0;
$.get("type/add", {"pid": pid, "name": name, "isleaf": isleaf},
function (data, state) {
var repjson = JSON.parse(data);
if (state == "success" && repjson.code == 200) {
$.toaster('添加成功', '提示', 'info');
console.log(repjson.data);
var newNode = repjson.data;
$('#jstree').jstree().create_node("#node_" + newNode.typeParentId,
{
'id': "node_" + newNode.typeId,
'text': newNode.typeName,
'parent': "#node_" + newNode.typeParentId,
'data': newNode.typeIsLeaf
}, 'last');
$('#jstree').jstree().get_node("node_" + newNode.typeId).data = newNode.typeIsLeaf;
} else
$.toaster('添加失败' + repjson.code + " " + repjson.message, '提示', 'warning');
}
).fail(function () {
$.toaster('添加失败:', '提示', 'warning');
});
$('#myModal').dialog('hide');
}
/**
* 获取所有选择节点
* @param isleaf true:仅获取叶子节点;false:所有节点
* @returns {Array}
*/
var getSelectType = function (isleaf) {
var seltypes = [];
$.each($("#jstree").jstree('get_selected'), function (idx, nodeid) {
var node = $('#jstree').jstree().get_node(nodeid);
if (isleaf == true && node.data != 1)
return;
seltypes.push(nodeId2id(nodeid));
});
return seltypes;
}
/**
* 检查节点是否子节点
* @param nodeid
* @returns {boolean}
*/
var checkIsLeaf = function (nodeid) {
var node = $('#jstree').jstree().get_node(nodeid);
var isLeaf = node.data == 1 ? true : false;
return isLeaf;
}
$("#btn4type").click(function () {
console.log("frw");
if ($("#tx_type_action").val() == "add") {
doAddType();
}
});
/**
* 根据选中的节点获取信息
*/
function searchType(ip){
$("#detailTable").hide();
$.ajax({
url: contextPath + "/zkTree/getRoot",
type: "post",
dataType: "json",
data: {
ip: ip
},
success: function (data) {
$(function () {
$("#rootTable").table({
url: contextPath + "/zkTree/getRoot",
striped: true,
panelClass: "panel-success",
pagination: true,
pageSize: 10,
loadFilter: function (data) {
return defaultLoadFilter(data);
},
columns: [{
title: "名称",
field: "name",
formatter: function (value, rowData, rowIndex) {
var div = $("<div>");
var input = $("<input type=\"button\">").addClass("form-control").attr({
id :"name",
name : "name",
style : "border: none;",
value : value
}).appendTo(div);
input.click(function () {
toDetail(rowData);
});
return div;
}
}, {
title: "路径",
field: "root"
}, {
title: "操作",
formatter: function (value, rowData, rowIndex) {
var div = $("<div>");
//修改
var editBtn = $("<button data-target='#updateModal' data-toggle='modal'>").addClass("btn btn-xs btn-success").html("修改").appendTo(div);
editBtn.click(function () {
updateMObject(rowData);
});
return div;
}
}],
});
});
},
error: function (e) {
}
});
}
var refreshTypeTree = function () {
console.log("refresh tree");
treeData = []; //重置
$.get("type/zkTree", function (data, state) {
console.log(state)
var jsonData = JSON.parse(data);
$.each(jsonData.data, function (n, val) {
var treeNode = {};
treeNode.id = "node_" + val.typeId;
treeNode.parent = (val.typeParentId == 0 ? "#" : "node_" + val.typeParentId);
treeNode.text = val.typeName;
treeNode.data = val.typeIsLeaf;
treeData.push(treeNode)
});
$('#jstree').jstree(true).settings.core.data = treeData;
$('#jstree').jstree().refresh(true, true);
setTimeout("openTree('#', 3)", 300); //展开三层
});
}
$('#jstree').jstree({
"plugins": ["themes", "contextmenu", "ui", "types", "crrm", "core", "status"],
'core': {
"themes": {
name: 'proton',
dots: false,
icons: false
},
'data': treeData,
'check_callback': true
}
}).bind("changed.jstree",
function (e, data) {
console.log(data);
console.log("Checked: " + data.node.text);
searchType(data.node.text);
});
refreshTypeTree();
... ...