监控redis和系统磁盘
先用springboot去整合reids
pom.xml
<!-- 导入reids场景启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
application.yml中:
spring:
# redis 单机配置
redis:
database: 0
host: 192.168.43.159
lettuce:
pool:
max-active: 8 #最大连接数据库连接数,设 0 为没有限制
max-idle: 8 #最大等待连接中的数量,设 0 为没有限制
max-wait: -1ms #最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。
min-idle: 0 #最小等待连接中的数量,设 0 为没有限制
shutdown-timeout: 100ms
password: 'root'
port: 6379
# reids 集群的配置请使用这个
# redis:
# cluster:
# nodes: ip:端口, ip:端口, ip:端口
# lettuce:
# pool:
# max-active: 300 #最大连接数据库连接数,设 0 为没有限制
# max-idle: 8 #最大等待连接中的数量,设 0 为没有限制
# max-wait: -1ms #最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。
# min-idle: 100 #最小等待连接中的数量,设 0 为没有限制
# shutdown-timeout: 60000ms
RedisServiceImpl
package com.cpc.monitor.service.impl;
import com.cpc.monitor.domain.RedisInfo;
import com.cpc.monitor.exception.RedisConnectException;
import com.cpc.monitor.service.RedisService;
import com.cpc.monitor.util.oConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* Redis 监控信息获取
*
* @Author MrBird
*/
@Service("redisService")
public class RedisServiceImpl implements RedisService {
@Autowired
private RedisConnectionFactory redisConnectionFactory;
/**
* Redis详细信息
*/
@Override
public List<RedisInfo> getRedisInfo() throws RedisConnectException {
Properties info = redisConnectionFactory.getConnection().info();
List<RedisInfo> infoList = new ArrayList<>();
RedisInfo redisInfo = null;
for (Map.Entry<Object, Object> entry : info.entrySet()) {
redisInfo = new RedisInfo();
redisInfo.setKey(oConvertUtils.getString(entry.getKey()));
redisInfo.setValue(oConvertUtils.getString(entry.getValue()));
infoList.add(redisInfo);
}
return infoList;
}
@Override
public Map<String, Object> getKeysSize() throws RedisConnectException {
Long dbSize = redisConnectionFactory.getConnection().dbSize();
Map<String, Object> map = new HashMap<>();
map.put("create_time", System.currentTimeMillis());
map.put("dbSize", dbSize);
return map;
}
@Override
public Map<String, Object> getMemoryInfo() throws RedisConnectException {
Map<String, Object> map