提交 8a421a6f 编写于 作者: Skyeye云's avatar Skyeye云

redis日志信息查看完成

上级 fc4bf920
......@@ -580,6 +580,20 @@ public class ToolUtil {
}
return flag;
}
/**
*
* @Title: getDateStr
* @Description: 将日期转化为正常的年月日时分秒
* @param @param timeStmp
* @param @return 参数
* @return String 返回类型
* @throws
*/
public static String getDateStr(long timeStmp) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateFormat.format(new Date(timeStmp));
}
public static void main(String[] args) throws Exception {
......
......@@ -57,7 +57,11 @@ public class SysRedisMonitorServiceImpl implements SysRedisMonitorService{
@Override
public void queryRedisLogsList(InputObject inputObject, OutputObject outputObject) throws Exception {
List<Map<String, Object>> beans = jedisClientClusterService.getClusterNodes();
for(Map<String, Object> bean : beans){
bean.put("log", jedisClientClusterService.getLogs(bean.get("ip").toString()));
}
outputObject.setBeans(beans);
outputObject.settotal(beans.size());
}
}
......@@ -3,10 +3,42 @@ package com.skyeye.jedis;
import java.util.List;
import java.util.Map;
import redis.clients.jedis.JedisPool;
public interface JedisClientClusterService {
public List<Map<String, Object>> getClusterNodes() throws Exception;
/**
*
* @Title: getLogs
* @Description: 获取日志列表
* @param @param entries
* @param @return
* @param @throws Exception 参数
* @return List<Map<String, Object>> 返回类型
* @throws
*/
public List<Map<String, Object>> getLogs(String ip);
/**
*
* @Title: logEmpty
* @Description: 清空日志
* @param @return
* @param @throws Exception 参数
* @return String 返回类型
* @throws
*/
public String logEmpty(String ip);
/**
*
* @Title: dbSize
* @Description: 获取占用内存大小
* @param @return
* @param @throws Exception 参数
* @return Long 返回类型
* @throws
*/
public Long dbSize(String ip);
}
......@@ -3,6 +3,7 @@ package com.skyeye.jedis.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
......@@ -12,6 +13,8 @@ import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import com.alibaba.fastjson.JSON;
import com.skyeye.common.util.ToolUtil;
import com.skyeye.jedis.JedisClient;
import com.skyeye.jedis.JedisClientClusterService;
......@@ -146,57 +149,22 @@ public class JedisClientCluster implements JedisClient, JedisClientClusterServic
@Override
public List<Slowlog> getLogs(long entries) {
Jedis jedis = null;
try {
// jedis = jedisPool.getResource();
// List<Slowlog> logList = jedis.slowlogGet(entries);
return null;
} finally {
// 返还到连接池
jedis.close();
}
return null;
}
@Override
public Long getLogsLen() {
Jedis jedis = null;
try {
// jedis = jedisPool.getResource();
// long logLen = jedis.slowlogLen();
return new Long(10);
} finally {
// 返还到连接池
jedis.close();
}
return new Long(1);
}
@Override
public String logEmpty() {
Jedis jedis = null;
try {
// jedis = jedisPool.getResource();
// return jedis.slowlogReset();
return "";
} finally {
// 返还到连接池
jedis.close();
}
return "";
}
@Override
public Long dbSize() {
Jedis jedis = null;
try {
// jedis = jedisPool.getResource();
// //配置redis服务信息
// Client client = jedis.getClient();
// client.dbSize();
// return client.getIntegerReply();
return new Long(10);
} finally {
// 返还到连接池
jedis.close();
}
return new Long(1);
}
@Override
......@@ -217,4 +185,57 @@ public class JedisClientCluster implements JedisClient, JedisClientClusterServic
return ridPoolList;
}
@Override
public List<Map<String, Object>> getLogs(String ip) {
Jedis jedis = null;
try {
Map<String, JedisPool> jedisPools = jedisCluster.getClusterNodes();
Iterator<Map.Entry<String, JedisPool>> entries = jedisPools.entrySet().iterator();
while (entries.hasNext()) {
Entry<String, JedisPool> entry = entries.next();
if(entry.getKey().indexOf(ip) != -1){
jedis = entry.getValue().getResource();
long logLen = jedis.slowlogLen();
List<Slowlog> logList = jedis.slowlogGet(logLen);
jedis.close();
List<Map<String, Object>> opList = null;
Map<String, Object> op = null;
boolean flag = false;
if (logList != null && !logList.isEmpty()) {
opList = new LinkedList<>();
for (Slowlog sl : logList) {
String args = JSON.toJSONString(sl.getArgs());
if (args.equals("[\"PING\"]") || args.equals("[\"SLOWLOG\",\"get\"]") || args.equals("[\"DBSIZE\"]") || args.equals("[\"INFO\"]")) {
continue;
}
op = new HashMap<>();
flag = true;
op.put("id", sl.getId());
op.put("executeTime", ToolUtil.getDateStr(sl.getTimeStamp() * 1000));
op.put("usedTime", sl.getExecutionTime()/1000.0 + "ms");
op.put("args", args);
opList.add(op);
}
}
if (flag)
return opList;
else
return null;
}
}
} finally {
}
return null;
}
@Override
public String logEmpty(String ip) {
return null;
}
@Override
public Long dbSize(String ip) {
return null;
}
}
......@@ -123,7 +123,7 @@ public class SessionFilter implements Filter {
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(servletRequest.getSession().getServletContext());
JedisClientCluster jedisClient = (JedisClientCluster)ac.getBean("jedisClientCluster");
if(ToolUtil.isBlank(request.getParameter("userToken"))){
servletResponse.sendRedirect(Constants.LOGIN_PAGE);
servletResponse.setHeader("SESSIONSTATUS", "TIMEOUT");
return;
}
if(!jedisClient.exists("userMation:" + request.getParameter("userToken").toString())){
......
......@@ -9,6 +9,9 @@ layui.config({
form = layui.form,
table = layui.table;
var redisInfo = false,//redis服务器配置信息是否加载
redisLogsInfo = false;//redis服务器日志信息是否加载
initRedieInfoMation();
//redis服务器配置信息
......@@ -21,6 +24,7 @@ layui.config({
template: getFileContent('tpl/sysredis/redisTemplate.tpl'),
ajaxSendLoadBefore: function(hdb){},
ajaxSendAfter:function(json){
redisInfo = true;
$("#bar tbody").scroll(function(){
$("#bar tbody").scrollTop($(this).scrollTop());
});
......@@ -28,6 +32,31 @@ layui.config({
});
}
//redis服务器日志信息
function initRedieLogsMation(){
showGrid({
id: "line",
url: reqBasePath + "redis002",
params: {},
pagination: false,
template: getFileContent('tpl/sysredis/redisLogsTemplate.tpl'),
ajaxSendLoadBefore: function(hdb){},
ajaxSendAfter:function(json){
redisLogsInfo = true;
}
});
}
//监听Winui的左右Tab切换
winui.tab.on('tabchange(winuitab)', function (data) {
if(data.index == '0'){
if(!redisInfo)
initRedieInfoMation();
}else if(data.index == '1'){
if(!redisLogsInfo)
initRedieLogsMation();
}
});
exports('redismonitorlist', {});
});
......@@ -26,3 +26,4 @@ card(); 随机不重复的6-8位
replaceUnderLineAndUpperCase(); 将表名转为Java经常使用的名字,如code_model转CodeModel
toLowerCaseFirstOne(); 字符串首字母转小写
writeTxtFile(); 写入内容到文件
getDateStr(); 将日期转化为正常的年月日时分秒
\ No newline at end of file
{{#each rows}}
<div class="layui-col-xs6 padding-l-r-10">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
<legend>{{ip}}</legend>
</fieldset>
<ul class="layui-timeline" style="height: 400px; overflow-y: scroll;">
{{#each log}}
<li class="layui-timeline-item">
<i class="layui-icon layui-timeline-axis"></i>
<div class="layui-timeline-content layui-text">
<h3 class="layui-timeline-title">{{executeTime}}</h3>
<p>操作:{{args}},时长:{{usedTime}}</p>
</div>
</li>
{{/each}}
</ul>
</div>
{{/each}}
\ No newline at end of file
......@@ -14,7 +14,7 @@
<div class="winui-scroll-y" style="height:auto;position:absolute;top:50px;bottom:0;">
<ul class="winui-tab-nav">
<li class="winui-this"><i class="fa fa-bar-chart fa-fw"></i>redis服务器信息</li>
<li><i class="fa fa-line-chart fa-fw"></i>Line</li>
<li><i class="fa fa-line-chart fa-fw"></i>redis日志信息</li>
<li><i class="fa fa-area-chart fa-fw"></i>Area</li>
<li><i class="fa fa-pie-chart fa-fw"></i>Pie</li>
</ul>
......@@ -29,7 +29,9 @@
</div>
</div>
<div class="winui-tab-item">
<div id="line" style="width:100%;height:100%;">2</div>
<div id="line" style="width:100%;height:100%;">
</div>
</div>
<div class="winui-tab-item">
<div id="area" style="width:100%;height:100%;">3</div>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册