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

添加redis信息查看

上级 fa3c84da
package com.skyeye.authority.service;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
public interface SysRedisMonitorService {
public void queryRedisInfoList(InputObject inputObject, OutputObject outputObject) throws Exception;
public void queryRedisLogsList(InputObject inputObject, OutputObject outputObject) throws Exception;
}
package com.skyeye.authority.service.impl;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.skyeye.authority.service.SysRedisMonitorService;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.jedis.JedisClient;
import com.skyeye.jedis.JedisClientClusterService;
@Service
public class SysRedisMonitorServiceImpl implements SysRedisMonitorService{
@Autowired
public JedisClient jedisClient;
@Autowired
public JedisClientClusterService jedisClientClusterService;
/**
*
* @Title: queryRedisInfoList
* @Description: 获取redis服务器信息
* @param @param inputObject
* @param @param outputObject
* @param @throws Exception 参数
* @return void 返回类型
* @throws
*/
@SuppressWarnings("unchecked")
@Override
public void queryRedisInfoList(InputObject inputObject, OutputObject outputObject) throws Exception {
//获取redis服务器信息
String info = jedisClient.getRedisInfo();
List<Map<String, Object>> beans = JSONArray.fromObject(info);
outputObject.setBeans(beans);
}
/**
*
* @Title: queryRedisLogsList
* @Description: 获取redis日志信息
* @param @param inputObject
* @param @param outputObject
* @param @throws Exception 参数
* @return void 返回类型
* @throws
*/
@Override
public void queryRedisLogsList(InputObject inputObject, OutputObject outputObject) throws Exception {
List<Map<String, Object>> beans = jedisClientClusterService.getClusterNodes();
outputObject.setBeans(beans);
}
}
package com.skyeye.jedis;
import java.util.List;
import redis.clients.util.Slowlog;
public interface JedisClient {
......@@ -120,4 +124,59 @@ public interface JedisClient {
*/
public Long del(String key);
/**
*
* @Title: getRedisInfo
* @Description: 获取redis 服务器信息
* @param @return
* @param @throws Exception 参数
* @return String 返回类型
* @throws
*/
public String getRedisInfo();
/**
*
* @Title: getLogs
* @Description: 获取日志列表
* @param @param entries
* @param @return
* @param @throws Exception 参数
* @return List<Slowlog> 返回类型
* @throws
*/
public List<Slowlog> getLogs(long entries);
/**
*
* @Title: getLogsLen
* @Description: 获取日志条数
* @param @return
* @param @throws Exception 参数
* @return Long 返回类型
* @throws
*/
public Long getLogsLen();
/**
*
* @Title: logEmpty
* @Description: 清空日志
* @param @return
* @param @throws Exception 参数
* @return String 返回类型
* @throws
*/
public String logEmpty();
/**
*
* @Title: dbSize
* @Description: 获取占用内存大小
* @param @return
* @param @throws Exception 参数
* @return Long 返回类型
* @throws
*/
public Long dbSize();
}
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;
}
package com.skyeye.jedis.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import com.skyeye.jedis.JedisClient;
import com.skyeye.jedis.JedisClientClusterService;
import redis.clients.jedis.Client;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
import redis.clients.util.Slowlog;
public class JedisClientCluster implements JedisClient {
/**
*
* @ClassName: JedisClientCluster
* @Description: redis集群
* @author 卫志强
* @date 2018年11月17日
*
*/
public class JedisClientCluster implements JedisClient, JedisClientClusterService {
@Autowired
private JedisCluster jedisCluster;
@Value("${redis.ip1}")
private String redisIp1;
@Value("${redis.ip2}")
private String redisIp2;
@Value("${redis.ip3}")
private String redisIp3;
@Value("${redis.ip4}")
private String redisIp4;
@Value("${redis.ip5}")
private String redisIp5;
@Value("${redis.ip6}")
private String redisIp6;
@Override
public String set(String key, String value) {
......@@ -58,5 +101,121 @@ public class JedisClientCluster implements JedisClient {
public Long del(String key) {
return jedisCluster.del(key);
}
@Override
public String getRedisInfo() {
Jedis jedis = null;
try {
Map<String, JedisPool> jedisPools = jedisCluster.getClusterNodes();
List<Map<String, Object>> ridMationList = new ArrayList<>();
Iterator<Map.Entry<String, JedisPool>> entries = jedisPools.entrySet().iterator();
while (entries.hasNext()) {
Entry<String, JedisPool> entry = entries.next();
if(entry.getKey().indexOf(redisIp1) != -1 || entry.getKey().indexOf(redisIp2) != -1
|| entry.getKey().indexOf(redisIp3) != -1 || entry.getKey().indexOf(redisIp4) != -1
|| entry.getKey().indexOf(redisIp5) != -1 || entry.getKey().indexOf(redisIp6) != -1){
jedis = entry.getValue().getResource();
Client client = jedis.getClient();
client.info();
String info = client.getBulkReply();
List<Map<String, Object>> ridList = new ArrayList<>();
Map<String, Object> redisMation = new HashMap<>();
String[] strs = info.split("\n");
Map<String, Object> bean = null;
if (strs != null && strs.length > 0) {
for (int i = 0; i < strs.length; i++) {
String[] str = strs[i].split(":");
if (str != null && str.length > 1) {
bean = new HashMap<>();
bean.put("key", str[0]);
bean.put("value", str[1].replace("\n", "").replace("\r", ""));
ridList.add(bean);
}
}
redisMation.put("ip", entry.getKey());
redisMation.put("mation", ridList);
ridMationList.add(redisMation);
}
}
}
return JSONArray.fromObject(ridMationList).toString();
} finally {
// 返还到连接池
jedis.close();
}
}
@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();
}
}
@Override
public Long getLogsLen() {
Jedis jedis = null;
try {
// jedis = jedisPool.getResource();
// long logLen = jedis.slowlogLen();
return new Long(10);
} finally {
// 返还到连接池
jedis.close();
}
}
@Override
public String logEmpty() {
Jedis jedis = null;
try {
// jedis = jedisPool.getResource();
// return jedis.slowlogReset();
return "";
} finally {
// 返还到连接池
jedis.close();
}
}
@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();
}
}
@Override
public List<Map<String, Object>> getClusterNodes() throws Exception {
Map<String, JedisPool> jedisPools = jedisCluster.getClusterNodes();
List<Map<String, Object>> ridPoolList = new ArrayList<>();
Iterator<Map.Entry<String, JedisPool>> entries = jedisPools.entrySet().iterator();
while (entries.hasNext()) {
Entry<String, JedisPool> entry = entries.next();
if(entry.getKey().indexOf(redisIp1) != -1 || entry.getKey().indexOf(redisIp2) != -1
|| entry.getKey().indexOf(redisIp3) != -1 || entry.getKey().indexOf(redisIp4) != -1
|| entry.getKey().indexOf(redisIp5) != -1 || entry.getKey().indexOf(redisIp6) != -1){
Map<String, Object> redisPoolMation = new HashMap<>();
redisPoolMation.put("ip", entry.getKey());
ridPoolList.add(redisPoolMation);
}
}
return ridPoolList;
}
}
package com.skyeye.jedis.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.skyeye.jedis.JedisClient;
import redis.clients.jedis.Client;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.util.SafeEncoder;
import redis.clients.util.Slowlog;
/**
*
* @ClassName: JedisClientPool
* @Description: redis集群
* @author 卫志强
* @date 2018年11月17日
*
*/
public class JedisClientPool implements JedisClient {
@Autowired
......@@ -90,5 +104,73 @@ public class JedisClientPool implements JedisClient {
jedis.close();
return result;
}
@Override
public String getRedisInfo() {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
Client client = jedis.getClient();
client.info();
String info = client.getBulkReply();
return info;
} finally {
// 返还到连接池
jedis.close();
}
}
@Override
public List<Slowlog> getLogs(long entries) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
List<Slowlog> logList = jedis.slowlogGet(entries);
return logList;
} finally {
// 返还到连接池
jedis.close();
}
}
@Override
public Long getLogsLen() {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
long logLen = jedis.slowlogLen();
return logLen;
} finally {
// 返还到连接池
jedis.close();
}
}
@Override
public String logEmpty() {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.slowlogReset();
} finally {
// 返还到连接池
jedis.close();
}
}
@Override
public Long dbSize() {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
//配置redis服务信息
Client client = jedis.getClient();
client.dbSize();
return client.getIntegerReply();
} finally {
// 返还到连接池
jedis.close();
}
}
}
package com.skyeye.authority.controller;
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.skyeye.authority.service.SysRedisMonitorService;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
@Controller
public class SysRedisMonitorController {
@Autowired
private SysRedisMonitorService sysRedisMonitorService;
/**
*
* @Title: queryRedisInfoList
* @Description: 获取redis服务器信息
* @param @param inputObject
* @param @param outputObject
* @param @throws Exception 参数
* @return void 返回类型
* @throws
*/
@RequestMapping("/post/SysRedisMonitorController/queryRedisInfoList")
@ResponseBody
public void queryRedisInfoList(InputObject inputObject, OutputObject outputObject) throws Exception{
sysRedisMonitorService.queryRedisInfoList(inputObject, outputObject);
}
/**
*
* @Title: queryRedisLogsList
* @Description: 获取redis日志信息
* @param @param inputObject
* @param @param outputObject
* @param @throws Exception 参数
* @return void 返回类型
* @throws
*/
@RequestMapping("/post/SysRedisMonitorController/queryRedisLogsList")
@ResponseBody
public void queryRedisLogsList(InputObject inputObject, OutputObject outputObject) throws Exception{
sysRedisMonitorService.queryRedisLogsList(inputObject, outputObject);
}
}
......@@ -157,6 +157,11 @@
<property id="limit" name="limit" ref="required,num" var="分页参数,每页多少条数据" />
<property id="page" name="page" ref="required,num" var="分页参数,第几页"/>
</url>
<url id="redis001" path="/post/SysRedisMonitorController/queryRedisInfoList" val="获取redis服务器信息" allUse="0">
</url>
<url id="redis002" path="/post/SysRedisMonitorController/queryRedisLogsList" val="获取redis日志信息" allUse="0">
</url>
<!-- 系统角色用户管理结束 -->
<!-- 系统数据库管理开始 -->
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册