|
|
package com.monitor.influxdb.mapper.impl;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Random;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.influxdb.dto.Point;
|
|
|
import org.influxdb.dto.QueryResult;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import com.monitor.common.contants.InfluxDBContants;
|
|
|
import com.monitor.common.util.QueryResultUtil;
|
|
|
import com.monitor.influxdb.InfluxDBModel;
|
|
|
import com.monitor.influxdb.InfluxDBQuery;
|
|
|
import com.monitor.influxdb.InluxDBSingle;
|
|
|
import com.monitor.influxdb.mapper.IRedisMapper;
|
|
|
import com.monitor.influxdb.model.RedisInfo;
|
|
|
import com.monitor.model.domain.PageBean;
|
|
|
|
|
|
@Component
|
|
|
public class RedisMapper extends InfluxDBQuery implements IRedisMapper {
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
InluxDBSingle inluxDBSingle;
|
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
|
@Override
|
|
|
public void insert(RedisInfo redis) {
|
|
|
|
|
|
Point point = Point.measurement(InfluxDBContants.REDIS_ALARM)
|
|
|
.addField("hostIp", redis.getHostIp())
|
|
|
.addField("role", redis.getRole())
|
|
|
.addField("connected_clients", redis.getConnected_clients())
|
|
|
.addField("is_slave", redis.getIs_slave())
|
|
|
.addField("used_memory_peak_human", redis.getUsed_memory_peak_human())
|
|
|
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS)
|
|
|
.build();
|
|
|
inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB()
|
|
|
.write(InfluxDBContants.MIDDLEWARE_ALARM, "default", point);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int selectCountByCodition(PageBean page) {
|
|
|
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
buffer.append("SELECT COUNT(hostIp) FROM " + InfluxDBContants.REDIS_ALARM);
|
|
|
int flag=0;
|
|
|
String hostIp = (String) page.getParams().get("hostIp");
|
|
|
if(StringUtils.isNotEmpty(hostIp)){
|
|
|
flag=1;
|
|
|
buffer.append(" where hostIp='"+hostIp+"'");
|
|
|
}
|
|
|
String recordTime=(String)page.getParams().get("recordTime");
|
|
|
if(StringUtils.isNotBlank(recordTime)){
|
|
|
if(flag==1){
|
|
|
buffer.append(" and time>'"+recordTime+"'");
|
|
|
}else{
|
|
|
buffer.append(" where time>'"+recordTime+"'");
|
|
|
}
|
|
|
}
|
|
|
InfluxDBModel influxDBModel= inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM);
|
|
|
QueryResult result= query(influxDBModel.getName(), buffer.toString(), InfluxDBContants.MIDDLEWARE_ALARM);
|
|
|
return QueryResultUtil.getCount(result);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<?> selectRedisInfosByCodition(PageBean page) {
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
buffer.append("SELECT hostIp,role,connected_clients,used_memory,used_memory_peak_human FROM " + InfluxDBContants.REDIS_ALARM);
|
|
|
int flag = 0;
|
|
|
String hostIp = (String) page.getParams().get("hostIp");
|
|
|
if(StringUtils.isNotEmpty(hostIp)){
|
|
|
buffer.append(" where hostIp='"+hostIp+"'");
|
|
|
}
|
|
|
String recordTime=(String)page.getParams().get("recordTime");
|
|
|
if(StringUtils.isNotBlank(recordTime)){
|
|
|
if(flag==1){
|
|
|
buffer.append(" and time>'"+recordTime+"'");
|
|
|
}else{
|
|
|
buffer.append(" where time>'"+recordTime+"'");
|
|
|
}
|
|
|
}
|
|
|
buffer.append(" ORDER BY time DESC LIMIT " + page.getPageSize() + " OFFSET " + page.getStartIndex());
|
|
|
InfluxDBModel influxDBModel= inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM);
|
|
|
QueryResult result= query(influxDBModel.getName(), buffer.toString(), InfluxDBContants.MIDDLEWARE_ALARM);
|
|
|
return QueryResultUtil.getValues(result);
|
|
|
}
|
|
|
|
|
|
} |