Authored by qinchao

mysq监控

... ... @@ -101,6 +101,12 @@ public class HttpUriContants {
****/
public static final String GET_REDIS_INFO = "/redisMonitor/getRedisInfo";
/***
* 监控对象
****/
public static String MOBJECT_QUERY_MYSQL_MOBJECT = "/mobject/queryMysqlMobject";
/**
* user
*/
... ...
package com.ui.ctrl;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
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 org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/mysqlMonitor")
public class MysqlMonitorCtrl {
@Autowired
HttpRestClient httpRestClient;
@RequestMapping("/toMysqlMonitor")
public ModelAndView toMysqlMonitor() {
return new ModelAndView("mysqlmonitor/mysqlMonitor");
}
/**
* 显示mysql配置信息
*/
@RequestMapping("/queryMysqlMobject")
@ResponseBody
public BaseResponse<?> queryMysqlMobject() {
return httpRestClient.defaultGet(HttpUriContants.MOBJECT_QUERY_MYSQL_MOBJECT,BaseResponse.class);
}
}
... ...
... ... @@ -68,10 +68,18 @@
headTR = $("<tr>").appendTo(thead);
//设置table的头
$(opt.columns).each(function(index, item) {
th = $("<th>").css({
"text-align" : item.align ? item.align : "center",
width : item.width ? item.width : "auto"
}).appendTo(headTR);
if(item.alignColumn){
th = $("<th>").css({
"text-align" : item.alignColumn ? item.alignColumn : "center",
width : item.width ? item.width : "auto"
}).appendTo(headTR);
}else{
th = $("<th>").css({
"text-align" : item.align ? item.align : "center",
width : item.width ? item.width : "auto"
}).appendTo(headTR);
}
if (item.checkbox === true) {
$("<input type=\"checkbox\" id=\"bootstrap-table-checkAll\" />").click(function() {
//点击全选
... ...
<%--
CreateUser: craig.qin
CreateDate: 2018/1/31
--%>
<%@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 + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=basePath%>css/bootstrap.min.css"/>
<link rel="stylesheet" href="<%=basePath%>css/unicorn.main.css"/>
<link rel="stylesheet" href="<%=basePath%>css/unicorn.grey.css"/>
<link rel="stylesheet" href="<%=basePath%>css/jquery-ui.css"/>
<link rel="stylesheet"
href="<%=basePath%>css/bootstrap-responsive.min.css"/>
<link rel="stylesheet" href="<%=basePath%>css/uniform.css"/>
<link rel="stylesheet" href="<%=basePath%>css/select2.css"/>
<link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css"/>
<script src="<%=basePath%>js/excanvas.min.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath%>js/jquery-1.12.0.min.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath%>js/jquery-ui.custom.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath%>/js/bootstrap.min.js"></script>
<script src="<%=basePath%>/js/unicorn.js"></script>
<script
src="<%=basePath%>js/bootstrap-plugin/datetimepicker/moment-with-locales.js"
charset="UTF-8" type="text/javascript"></script>
<script
src="<%=basePath%>js/bootstrap-plugin/datetimepicker/bootstrap-datetimepicker.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/global.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap-plugin/bootstrap.pagination.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap-plugin/bootstrap.table.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap-plugin/bootstrap.dialog.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap-plugin/bootstrap.form.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap-plugin/bootstrap.panel.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap-plugin/bootstrap.alerts.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap-plugin/bootstrap.accordion.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap-plugin/bootstrap.breadcrumb.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap-plugin/bootstrap.validate.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap-plugin/bootstrap.form.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/layer/layer.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap-plugin/bootstrap.select.js"
charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/jstree/jstree.min.js"></script>
<script src="<%=basePath%>js/jquery.toaster.js"></script>
<script>
var contextPath = '<%=basePath%>';
</script>
<title>YOHO!运维</title>
</head>
<body>
<!-- 头部 -->
<div id="head"></div>
<!-- 右侧具体内容 -->
<div id="content">
<div id="breadcrumb">
<a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i>首页</a> <a href="#" class="current">Mysql监控管理</a>
</div>
<div class="container-fluid">
<div class="widget-box">
<div class="widget-title" style="height: 35px;">
<div>
</div>
</div>
<div class="widget-content">
<div id="mysqlTable" style="overflow-y: auto; overflow-x: hidden; max-height: 800px"></div>
</div>
</div>
</div>
</div>
<script src="<%=basePath%>script/common/genarate_left_panel.js"></script>
<script>
$("#li_monitor").addClass("active open");
$("#li_mysql").addClass("active");
</script>
<script type="text/javascript">
$(function () {
var columns = getColumns();
//加载表格
$("#mysqlTable").table({
columnAutoWidth: false,
url: contextPath + "/mysqlMonitor/queryMysqlMobject",
striped : true,
dataType: "json",
pagination: false,
loadFilter : function(data) {
return defaultLoadFilter(data);
},
onLoadSuccess : function(data) {
// var data = $('#table').bootstrapTable('getData', true);
//合并单元格
//mergeCells(data, "name", 0, $('#mysqlTable'));
alert(1);
MergeCell('mysqlTable',0,0);
},
/* queryParams:{
"eventName":"测试一下而已"
},*/
columns : columns
});
});
///合并表格相同行的内容
///tableId:表格ID(最好是tbody,避免把表尾给合并了)
///startRow:起始行,没有标题就从0开始
///endRow:终止行,此参数是递归时检查的范围,一开始时会自动赋值为最后一行
///col:当前处理的列
function MergeCell(tableId, startRow, col,endRow) {
var tb_jq = $("#mysqlTable div table tbody");
var tb=tb_jq[0]; //DOM对象
console.log(tb);
if (col >= tb.rows[0].cells.length) {
return;
}
//当检查第0列时检查所有行
if (col == 0 || endRow == 0) {
endRow = tb.rows.length - 1;
}
for (var i = startRow; i < endRow; i++) {
//程序是自左向右合并
if (tb.rows[startRow].cells[col].innerHTML == tb.rows[i + 1].cells[col].innerHTML) {
//如果相同则删除下一行的第0列单元格
tb.rows[i + 1].cells[col].style.display='none';
//更新rowSpan属性
tb.rows[startRow].cells[col].rowSpan = (tb.rows[startRow].cells[col].rowSpan | 0) + 1;
//当循环到终止行前一行并且起始行和终止行不相同时递归(因为上面的代码已经检查了i+1行,所以此处只到endRow-1)
if (i == endRow - 1 && startRow != endRow) {
MergeCell(tableId, startRow, endRow, col + 1);
}
} else {
//起始行,终止行不变,检查下一列
MergeCell(tableId, startRow, i, col + 1);
//增加起始行
startRow = i + 1;
}
}
}
function getColumns(){
var columns = [
{
title : "库名",
field : "name",
width : "10%",
styler : function(value, rowData, rowIndex){
return {
"vertical-align" : "middle"
};
}
},
{
title : "aws主机",
field : "awsMObjectInfo",
width : "40%",
align:"left",
alignColumn:"center",
formatter : function(value, rowData, rowIndex) {
return fmtHost(rowData.awsMObjectInfo);
}
},{
title : "qcloud主机",
field : "qcloudMObjectInfo",
width : "40%",
align:"left",
alignColumn:"center",
formatter : function(value, rowData, rowIndex) {
return fmtHost(rowData.qcloudMObjectInfo);
}
}/*,
{
title : "操作",
width : "100px",
formatter : function(value, rowData, rowIndex) {
return "";
},
styler : function(value, rowData, rowIndex){
return {
"vertical-align" : "middle"
};
}
}*/ ];
return columns;
}
function fmtHost(instances) {
if(instances == null || instances.length == 0){
return;
}
var masterIps="";
var slaveIps="";
for(var index = 0;index < instances.length;index++){
//属性 主机标签 --tags
var tags = instances[index].moTags;
var masterFlag=false;
var masterBadage='<span class="badge" style="background-color: #fff;font-weight:normal;">&nbsp;&nbsp;&nbsp;</span>';
var tagsBadage="";
var ipBackgroudColor="#5bc0de";
if(tags != null && tags!= ""){//展示标签信息
tagsBadage= "<span class=\"badge\" style=\"background-color: #5bc0de;font-weight:normal;font-size: 13px\";>标签:&nbsp;" + tags +"</span>";
if(tags.toUpperCase().indexOf("MASTER")>=0){
masterFlag=true;
masterBadage='<span class="badge">M</span>';
ipBackgroudColor="#777";
}
}
var healthCss=' style="background-color: '+ipBackgroudColor+';font-weight:normal;" ';
var runningStatusMessage = '&nbsp;&nbsp;<a href="#" title="master"><span class="badge" style="background-color: '+ipBackgroudColor+';font-weight:normal;"><i class="fa fa-check-circle" aria-hidden="true"></i></span></a>';
/*if("Healthy"!=instances[index].runningStatus){
healthCss=' style="background-color: #DD514D;font-weight:normal;" ';
runningStatusMessage='&nbsp;&nbsp;<a href="#" title="异常"><span class="badge" style="background-color: #DD514D;font-weight:normal;"><i class="fa fa-exclamation-circle" aria-hidden="true"></i></span></a>';
}*/
var hostip='<span class="label" style="font-weight:normal;">';
hostip+= ('<span class="badge" '+healthCss+'>'+instances[index].moHostIp);
//在个别机器的chrome版本上instances[index].ip取不到值,很奇怪,因此添加一个if判断,跳过
if(instances[index]!=null&&instances[index].moHostIp!=null&& instances[index].moHostIp != undefined&&instances[index].moHostIp!=""){
for(var i=0;i<=(15-instances[index].moHostIp.length);i++){
hostip+="&nbsp;&nbsp;"
}
}
hostip += runningStatusMessage;
hostip += '</span>';
hostip += '</span>';
hostip = hostip +tagsBadage;
var onehost='<h4>'+masterBadage+hostip+'</h4>';
if(masterFlag){
masterIps += onehost;
}else{
slaveIps += onehost;
}
}
return masterIps+slaveIps;
}
</script>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -11,7 +11,7 @@ innerHTML += "<div id='sidebar'><ul>";
innerHTML += "<li id='li_dashboard'><a id='li_dashboard_a' href=''><i class='icon icon-th'></i> <span>Dashboard</span></a></li>";
/*监控*/
innerHTML += "<li class='submenu' id='li_monitor'><a id='li_monitor_a' href='#'><i class='icon icon-th-list'></i> <span>监控</span><span class='label'>11</span></a><ul>";
innerHTML += "<li class='submenu' id='li_monitor'><a id='li_monitor_a' href='#'><i class='icon icon-th-list'></i> <span>监控</span><span class='label'>12</span></a><ul>";
innerHTML += "<li id='li_javaMonitor'><a id='li_javaMonitor_a' href=''><i class='icon icon-th'></i> <span>JAVA服务监控</span></a></li>";
innerHTML += "<li id='li_javaApiMonitor'><a id='li_javaApiMonitor_a' href=''><i class='icon icon-th'></i> <span>JAVA API监控</span></a></li>";
innerHTML += "<li id='li_javaApi'><a id='li_javaApi_a' href=''><i class='icon icon-th'></i> <span>JAVA服务信息</span></a></li>";
... ... @@ -23,6 +23,7 @@ innerHTML += "<li id='li_newRedisMonitor'><a id='li_memcachedMonitor_a' href=''>
innerHTML += "<li id='li_dns_monitor'><a id='li_dns_monitor_a' href=''><i class='icon icon-th'></i> <span>DNS反劫持监控</span></a></li>";
innerHTML += "<li id='li_monit'><a id='li_monit_a' href=''><i class='icon icon-th'></i> <span>Monit监控</span></a></li>";
innerHTML += "<li id='li_sqlOpLogs'><a id='li_sqlOpLogs_a' href=''><i class='icon icon-th'></i> <span>SQL操作日志</span></a></li>";
innerHTML += "<li id='li_mysql'><a id='li_mysql_a' href=''><i class='icon icon-th'></i> <span>Mysql监控</span></a></li>";
innerHTML += "</ul></li>";
/*运维(大数据)*/
... ... @@ -204,6 +205,7 @@ document.getElementById("li_docker_monitor_service_a").setAttribute("href", path
//document.getElementById("li_lbswitch_a").setAttribute("href", path + "/lbSwitch/toLbSwitch");
document.getElementById("li_monit_a").setAttribute("href",path+"/monit/toMonit");
document.getElementById("li_sqlOpLogs_a").setAttribute("href",path+"/sqlOperate/sqlLogs");
document.getElementById("li_mysql_a").setAttribute("href",path+"/mysqlMonitor/toMysqlMonitor");
/*document.getElementById("li_ABTestConfig_a").setAttribute("href",path+"/abtestConfig/toABTestConfig");
document.getElementById("li_ABTestTotal_a").setAttribute("href",path+"/abtestTotal/toABTestTotal");*/
document.getElementById("li_nodeMonitor_a").setAttribute("href",path+"/nodeMonitor/toNodeMonitor");
... ...