- add checker (heap usage rate, GC count, JVM cpu usage rate)
- add datacollector( agent stat)
This commit is contained in:
Minwoo Jung
2014-10-13 18:55:19 +09:00
parent 819a872009
commit f98732d24f
34 changed files with 685 additions and 60 deletions
@@ -30,8 +30,7 @@ public class AlarmMailTemplate {
body.append(LINE_FEED);
body.append(String.format("Rule : %s", rule.getCheckerName()));
body.append(LINE_FEED);
body.append(String.format("%s value is %s during the past 5 mins.(Threshold : %s%s)", rule.getCheckerName(), checker.getDetectedValue(), rule.getThreshold(), checker.getUnit()));
body.append(LINE_FEED);
body.append(checker.getEmailMessage());
body.append(String.format(LINK_FORMAT, pinpointUrl, pinpointUrl));
return body.toString();
@@ -21,8 +21,6 @@ import com.nhn.pinpoint.web.dao.ApplicationIndexDao;
import com.nhn.pinpoint.web.vo.Application;
public class AlarmReader implements ItemReader<AlarmCheckFilter>, StepExecutionListener {
private final static long SLOT_INTERVAL = 300000;
@Autowired
private DataCollectorFactory dataCollectorFactory;
@@ -79,7 +77,7 @@ public class AlarmReader implements ItemReader<AlarmCheckFilter>, StepExecutionL
DataCollector collector = collectorMap.get(checkerCategory);
if(collector == null) {
collector = dataCollectorFactory.createDataCollector(checkerCategory, application, timeSlotEndTime, SLOT_INTERVAL);
collector = dataCollectorFactory.createDataCollector(checkerCategory, application, timeSlotEndTime);
collectorMap.put(collector.getDataCollectorCategory(), collector);
}
@@ -84,16 +84,18 @@ public class AlarmWriter implements ItemWriter<AlarmCheckFilter> {
CloseableHttpClient client = HttpClients.createDefault();
try {
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("serviceId", SMS_SERVICE_ID));
nvps.add(new BasicNameValuePair("sendMdn", QUOTATATION + SENDER_NUMBER + QUOTATATION));
nvps.add(new BasicNameValuePair("receiveMdnList",convertToReceiverFormat(receivers)));
nvps.add(new BasicNameValuePair("content", QUOTATATION + makeSmsMessage(checker) + QUOTATATION));
HttpGet get = new HttpGet(smsServerUrl + "?" + URLEncodedUtils.format(nvps, "UTF-8"));
logger.debug("SMSServer url : {}", get.getURI());
HttpResponse response = client.execute(get);
logger.debug("SMSServer call result ={}", EntityUtils.toString(response.getEntity()));
for(String message : checker.getSmsMessage()) {
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("serviceId", SMS_SERVICE_ID));
nvps.add(new BasicNameValuePair("sendMdn", QUOTATATION + SENDER_NUMBER + QUOTATATION));
nvps.add(new BasicNameValuePair("receiveMdnList",convertToReceiverFormat(receivers)));
nvps.add(new BasicNameValuePair("content", QUOTATATION + message + QUOTATATION));
HttpGet get = new HttpGet(smsServerUrl + "?" + URLEncodedUtils.format(nvps, "UTF-8"));
logger.debug("SMSServer url : {}", get.getURI());
HttpResponse response = client.execute(get);
logger.debug("SMSServer call result ={}", EntityUtils.toString(response.getEntity()));
}
} catch (Exception e) {
logger.warn(e.getMessage(), e);
} finally {
@@ -105,12 +107,6 @@ public class AlarmWriter implements ItemWriter<AlarmCheckFilter> {
}
}
private String makeSmsMessage(AlarmCheckFilter checker) {
Rule rule = checker.getRule();
return String.format("[PINPOINT Alarm - %s] %s is %s (Threshold : %s%s)", rule.getApplicationId(), rule.getCheckerName(), checker.getDetectedValue(), rule.getThreshold(), checker.getUnit());
}
private String convertToReceiverFormat(List<String> receivers) {
List<String> result = new ArrayList<String>();
@@ -4,11 +4,15 @@ import java.util.LinkedList;
import java.util.List;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.alarm.collector.AgentStatDataCollector;
import com.nhn.pinpoint.web.alarm.collector.DataCollector;
import com.nhn.pinpoint.web.alarm.collector.ResponseTimeDataCollector;
import com.nhn.pinpoint.web.alarm.filter.AlarmCheckFilter;
import com.nhn.pinpoint.web.alarm.filter.ErrorCountChecker;
import com.nhn.pinpoint.web.alarm.filter.ErrorRateChecker;
import com.nhn.pinpoint.web.alarm.filter.GcCountChecker;
import com.nhn.pinpoint.web.alarm.filter.HeapUsageRateChecker;
import com.nhn.pinpoint.web.alarm.filter.JvmCpuUsageRateChecker;
import com.nhn.pinpoint.web.alarm.filter.ResponseCountChecker;
import com.nhn.pinpoint.web.alarm.filter.SlowCountFilter;
import com.nhn.pinpoint.web.alarm.filter.SlowRatesFilter;
@@ -49,8 +53,28 @@ public enum CheckerCategory {
public AlarmCheckFilter createChecker(DataCollector dataCollector, Rule rule) {
return new ResponseCountChecker((ResponseTimeDataCollector)dataCollector, rule);
}
}
;
},
HEAP_USAGE_RATE("HEAP_USAGE_RATE", DataCollectorCategory.AGENT_STAT) {
@Override
public AlarmCheckFilter createChecker(DataCollector dataCollector, Rule rule) {
return new HeapUsageRateChecker((AgentStatDataCollector)dataCollector, rule);
}
},
GC_COUNT("GC_COUNT", DataCollectorCategory.AGENT_STAT) {
@Override
public AlarmCheckFilter createChecker(DataCollector dataCollector, Rule rule) {
return new GcCountChecker((AgentStatDataCollector)dataCollector, rule);
}
},
JVM_CPU_USAGE_RATE("JVM_CPU_USAGE_RATE", DataCollectorCategory.AGENT_STAT) {
@Override
public AlarmCheckFilter createChecker(DataCollector dataCollector, Rule rule) {
return new JvmCpuUsageRateChecker((AgentStatDataCollector)dataCollector, rule);
}
};
public static CheckerCategory getValue(String value) {
for (CheckerCategory category : CheckerCategory.values()) {
@@ -3,28 +3,44 @@ package com.nhn.pinpoint.web.alarm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.nhn.pinpoint.web.alarm.collector.AgentStatDataCollector;
import com.nhn.pinpoint.web.alarm.collector.DataCollector;
import com.nhn.pinpoint.web.alarm.collector.ResponseTimeDataCollector;
import com.nhn.pinpoint.web.dao.hbase.HbaseAgentStatDao;
import com.nhn.pinpoint.web.dao.hbase.HbaseApplicationIndexDao;
import com.nhn.pinpoint.web.dao.hbase.HbaseMapResponseTimeDao;
import com.nhn.pinpoint.web.vo.Application;
@Component
public class DataCollectorFactory {
public final static long SLOT_INTERVAL_FIVE_MIN = 300000;
public final static long SLOT_INTERVAL_THREE_MIN = 180000;
@Autowired
private HbaseMapResponseTimeDao hbaseMapResponseTimeDao;
public DataCollector createDataCollector(CheckerCategory checker, Application application, long timeSlotEndTime, long slotInterval) {
@Autowired
private HbaseAgentStatDao hbaseAgentStatDao;
@Autowired
private HbaseApplicationIndexDao hbaseApplicationIndexDao;
public DataCollector createDataCollector(CheckerCategory checker, Application application, long timeSlotEndTime) {
switch (checker.getDataCollectorCategory()) {
case RESPONSE_TIME:
return new ResponseTimeDataCollector(application, hbaseMapResponseTimeDao, timeSlotEndTime, slotInterval);
return new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, hbaseMapResponseTimeDao, timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN);
case AGENT_STAT:
return new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, hbaseAgentStatDao, hbaseApplicationIndexDao, timeSlotEndTime, SLOT_INTERVAL_THREE_MIN);
}
throw new RuntimeException("not create DataCollector : " + checker.getName());
throw new IllegalArgumentException("not create DataCollector : " + checker.getName());
}
public enum DataCollectorCategory {
RESPONSE_TIME;
RESPONSE_TIME,
AGENT_STAT;
}
}
@@ -118,7 +118,8 @@ public enum SubCategory {
AlarmFilter createAlarmFilter(Application application, AlarmRuleResource rule) throws Exception {
List<MainCategory> parentSupportCategoryList = getParentSupportCategoryList();
if (parentSupportCategoryList.size() == 1) {
return createAlarmFilter(application, parentSupportCategoryList.get(0), rule);
// return createAlarmFilter(application, parentSupportCategoryList.get(0), rule);
return null;
} else {
throw new Exception("Ambiguous ParentCategory Exception");
}
@@ -0,0 +1,99 @@
package com.nhn.pinpoint.web.alarm.collector;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.dao.AgentStatDao;
import com.nhn.pinpoint.web.dao.ApplicationIndexDao;
import com.nhn.pinpoint.web.vo.AgentStat;
import com.nhn.pinpoint.web.vo.Application;
import com.nhn.pinpoint.web.vo.Range;
public class AgentStatDataCollector extends DataCollector {
private final Application application;
private final AgentStatDao agentStatDao;
private final ApplicationIndexDao applicationIndexDao;
private final long timeSlotEndTime;
private final long slotInterval;
private final AtomicBoolean init =new AtomicBoolean(false);// 동시에 checker들이 동작 되면 동시성 고려가 필요함
private final Map<String, Long> agentHeapUsageRate = new HashMap<String, Long>();
private final Map<String, Long> agentGcCount = new HashMap<String, Long>();
private final Map<String, Long> agentJvmCpuUsageRate = new HashMap<String, Long>();
public AgentStatDataCollector(DataCollectorCategory category, Application application, AgentStatDao agentStatDao, ApplicationIndexDao applicationIndexDao, long timeSlotEndTime, long slotInterval) {
super(category);
this.application = application;
this.agentStatDao = agentStatDao;
this.applicationIndexDao = applicationIndexDao;
this.timeSlotEndTime = timeSlotEndTime;
this.slotInterval = slotInterval;
}
@Override
public void collect() {
if (init.get()) {
return;
}
Range range = Range.createUncheckedRange(timeSlotEndTime - slotInterval, timeSlotEndTime);
List<String> agentIds = applicationIndexDao.selectAgentIds(application.getName());
for(String agentId : agentIds) {
List<AgentStat> scanAgentStatList = agentStatDao.scanAgentStatList(agentId, range);
int listSize = scanAgentStatList.size();
long totalHeapSize = 0;
long usedHeapSize = 0;
long jvmCpuUsaged = 0;
for (AgentStat agentStat : scanAgentStatList) {
totalHeapSize += agentStat.getMemoryGc().getJvmMemoryHeapMax();
usedHeapSize += agentStat.getMemoryGc().getJvmMemoryHeapUsed();
jvmCpuUsaged += agentStat.getCpuLoad().getJvmCpuLoad();
}
long percent = 0;
percent = calculatePercent(usedHeapSize, totalHeapSize);
agentHeapUsageRate.put(agentId, percent);
percent = calculatePercent(jvmCpuUsaged, 100*scanAgentStatList.size());
agentJvmCpuUsageRate.put(agentId, percent);
if(listSize > 0) {
long accruedFirstGCcount = scanAgentStatList.get(0).getMemoryGc().getJvmGcOldCount();
long accruedLastGCcount= scanAgentStatList.get(listSize - 1).getMemoryGc().getJvmGcOldCount();
agentGcCount.put(agentId, accruedLastGCcount - accruedFirstGCcount);
}
}
init.set(true);
}
private long calculatePercent(long used, long total) {
if (total == 0 || used == 0) {
return 0;
} else {
return Math.round((used * 100) / total);
}
}
public Map<String, Long> getHeapUsageRate() {
return agentHeapUsageRate;
}
public Map<String, Long> getGCCount() {
return agentGcCount;
}
public Map<String, Long> getJvmCpuUsageRate() {
return agentJvmCpuUsageRate;
}
}
@@ -25,8 +25,8 @@ public class ResponseTimeDataCollector extends DataCollector {
private int slowRate = 0;
private int errorRate = 0;
public ResponseTimeDataCollector(Application application, MapResponseDao responseDAO, long timeSlotEndTime, long slotInterval) {
super(DataCollectorCategory.RESPONSE_TIME);
public ResponseTimeDataCollector(DataCollectorCategory category, Application application, MapResponseDao responseDAO, long timeSlotEndTime, long slotInterval) {
super(category);
this.application = application;
this.responseDao = responseDAO;
this.timeSlotEndTime = timeSlotEndTime;
@@ -0,0 +1,64 @@
package com.nhn.pinpoint.web.alarm.filter;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.nhn.pinpoint.web.alarm.collector.DataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
public abstract class AgentChecker extends AlarmCheckFilter {
protected Map<String, Long> detectedAgents = new HashMap<String, Long>();
protected AgentChecker(Rule rule, String unit, DataCollector dataCollector) {
super(rule, unit, dataCollector);
}
@Override
public void check() {
logger.debug("{} check.", this.getClass().getSimpleName());
dataCollector.collect();
Map<String, Long> agents = getAgentValues();
for(Entry<String, Long> agent : agents.entrySet()) {
if (decideResult(agent.getValue())) {
detected = true;
detectedAgents.put(agent.getKey(), agent.getValue());
}
}
}
@Override
protected long getDetectedValue() {
throw new UnsupportedOperationException(this.getClass() + "is not support getDetectedValue function. you should use getAgentValues");
}
public List<String> getSmsMessage() {
List<String> messages = new LinkedList<String>();
for (Entry<String, Long> detected : detectedAgents.entrySet()) {
messages.add(String.format("[PINPOINT Alarm - %s] %s is %s (Threshold : %s%s)", detected.getKey(), rule.getCheckerName(), detected.getValue(), rule.getThreshold(), unit));
}
return messages;
};
@Override
public String getEmailMessage() {
StringBuilder message = new StringBuilder();
for (Entry<String, Long> detected : detectedAgents.entrySet()) {
message.append(String.format(" Value of agent(%s) is %s during the past 5 mins.(Threshold : %s%s)", detected.getKey(), detected.getValue(), rule.getThreshold(), unit));
message.append("<br>");
}
return message.toString();
};
protected abstract Map<String, Long> getAgentValues();
}
@@ -1,5 +1,8 @@
package com.nhn.pinpoint.web.alarm.filter;
import java.util.LinkedList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -10,9 +13,9 @@ import com.nhn.pinpoint.web.alarm.vo.Rule;
*
* @author koo.taejin
*/
public abstract class AlarmCheckFilter implements AlarmFilter {
public abstract class AlarmCheckFilter {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
protected final DataCollector dataCollector;
protected final Rule rule;
protected boolean detected = false;
@@ -68,7 +71,17 @@ public abstract class AlarmCheckFilter implements AlarmFilter {
}
}
abstract public long getDetectedValue();
public List<String> getSmsMessage() {
List<String> messages = new LinkedList<String>();
messages.add(String.format("[PINPOINT Alarm - %s] %s is %s (Threshold : %s%s)", rule.getApplicationId(), rule.getCheckerName(), getDetectedValue(), rule.getThreshold(), unit));
return messages;
};
public String getEmailMessage() {
return String.format("%s value is %s during the past 5 mins.(Threshold : %s%s)<br>", rule.getCheckerName(), getDetectedValue(), rule.getThreshold(), unit);
};
protected abstract long getDetectedValue();
}
@@ -10,7 +10,7 @@ public class ErrorCountChecker extends AlarmCheckFilter {
}
@Override
public long getDetectedValue() {
protected long getDetectedValue() {
return ((ResponseTimeDataCollector)dataCollector).getErrorCount();
}
}
@@ -10,7 +10,7 @@ public class ErrorRateChecker extends AlarmCheckFilter {
}
@Override
public long getDetectedValue() {
protected long getDetectedValue() {
return ((ResponseTimeDataCollector)dataCollector).getErrorRate();
}
}
@@ -93,7 +93,7 @@ public class FailureCountFilter extends AlarmCheckCountFilter {
}
@Override
public long getDetectedValue() {
protected long getDetectedValue() {
return 0;
}
@@ -94,7 +94,7 @@ public class FailureRatesFilter extends AlarmCheckRatesFilter {
}
@Override
public long getDetectedValue() {
protected long getDetectedValue() {
// TODO Auto-generated method stub
return 0;
}
@@ -0,0 +1,18 @@
package com.nhn.pinpoint.web.alarm.filter;
import java.util.Map;
import com.nhn.pinpoint.web.alarm.collector.AgentStatDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
public class GcCountChecker extends AgentChecker {
public GcCountChecker(AgentStatDataCollector dataCollector, Rule rule) {
super(rule, "", dataCollector);
}
@Override
protected Map<String, Long> getAgentValues() {
return ((AgentStatDataCollector)dataCollector).getGCCount();
}
}
@@ -0,0 +1,19 @@
package com.nhn.pinpoint.web.alarm.filter;
import java.util.Map;
import com.nhn.pinpoint.web.alarm.collector.AgentStatDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
public class HeapUsageRateChecker extends AgentChecker {
public HeapUsageRateChecker(AgentStatDataCollector dataCollector, Rule rule) {
super(rule, "%", dataCollector);
}
@Override
protected Map<String, Long> getAgentValues() {
return ((AgentStatDataCollector)dataCollector).getHeapUsageRate();
}
}
@@ -0,0 +1,19 @@
package com.nhn.pinpoint.web.alarm.filter;
import java.util.Map;
import com.nhn.pinpoint.web.alarm.collector.AgentStatDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
public class JvmCpuUsageRateChecker extends AgentChecker {
public JvmCpuUsageRateChecker(AgentStatDataCollector dataCollector, Rule rule) {
super(rule, "%", dataCollector);
}
@Override
protected Map<String, Long> getAgentValues() {
return ((AgentStatDataCollector)dataCollector).getJvmCpuUsageRate();
}
}
@@ -10,7 +10,7 @@ public class ResponseCountChecker extends AlarmCheckFilter {
}
@Override
public long getDetectedValue() {
protected long getDetectedValue() {
return ((ResponseTimeDataCollector)dataCollector).getTotalCount();
}
}
@@ -10,7 +10,7 @@ public class SlowCountFilter extends AlarmCheckFilter {
}
@Override
public long getDetectedValue() {
protected long getDetectedValue() {
return ((ResponseTimeDataCollector)dataCollector).getSlowCount();
}
}
@@ -13,8 +13,8 @@ public class SlowRatesFilter extends AlarmCheckFilter {
super(rule, "%", dataCollector);
}
@Override
public long getDetectedValue() {
@Override
protected long getDetectedValue() {
return ((ResponseTimeDataCollector)dataCollector).getSlowRate();
}
}
@@ -150,7 +150,7 @@ public class DefaultAlarmScheduler implements AlarmScheduler {
}
List<AlarmRuleResource> alarmRuleList = ruleGroup.getAlarmRuleList();
List<AlarmCheckFilter> alarmCheckFilterList = createAlarmCheckFilter(application, alarmRuleList);
alarmJob.addFilter(alarmCheckFilterList);
// alarmJob.addFilter(alarmCheckFilterList);
if (CollectionUtils.isEmpty(alarmCheckFilterList)) {
logger.warn("Application={}, Rule={} can't find valid rule resource.", applicationName, alarmName);
return null;
@@ -8,7 +8,6 @@
xmlns:hdp="http://www.springframework.org/schema/hadoop"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
@@ -19,7 +19,7 @@ public class DataCollectorFactoryTest {
@Test
public void createDataCollector() {
DataCollector collector = factory.createDataCollector(CheckerCategory.SLOW_COUNT, null, 0, 0);
DataCollector collector = factory.createDataCollector(CheckerCategory.SLOW_COUNT, null, 0);
assertNotNull(collector);
}
@@ -14,6 +14,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.alarm.collector.ResponseTimeDataCollector;
import com.nhn.pinpoint.web.alarm.filter.AlarmCheckFilter;
import com.nhn.pinpoint.web.alarm.vo.Rule;
@@ -27,7 +28,7 @@ import com.nhn.pinpoint.web.vo.ResponseTime;
@ContextConfiguration("classpath:applicationContext-test.xml")
public class ProcessorTest {
private static final String SERVICE_NAME = "minwoo_tomcat";
private static final String SERVICE_NAME = "local_tomcat";
@Autowired
AlarmProcessor processor;
@@ -68,7 +69,7 @@ public class ProcessorTest {
@Test
public void processTest() {
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(application, mockMapResponseDAO, 3000000, System.currentTimeMillis());
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, 3000000, System.currentTimeMillis());
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.SLOW_COUNT.getName(), 74, "testGroup", false, false);
AlarmCheckFilter filter = CheckerCategory.SLOW_COUNT.createChecker(collector, rule);
@@ -14,6 +14,7 @@ import org.springframework.batch.core.StepExecution;
import org.springframework.batch.item.ExecutionContext;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.alarm.collector.DataCollector;
import com.nhn.pinpoint.web.alarm.collector.ResponseTimeDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
@@ -124,8 +125,8 @@ public class ReaderTest {
dataCollectorFactory = new DataCollectorFactory() {
@Override
public DataCollector createDataCollector(CheckerCategory checker, Application application, long timeSlotEndTime, long slotInterval) {
return new ResponseTimeDataCollector(null, null, 0, 0);
public DataCollector createDataCollector(CheckerCategory checker, Application application, long timeSlotEndTime) {
return new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, null, null, 0, 0);
}
};
}
@@ -32,7 +32,7 @@ public class WriterTest {
}
@Override
public long getDetectedValue() {
protected long getDetectedValue() {
return 10000;
}
};
@@ -53,7 +53,7 @@ public class WriterTest {
}
@Override
public long getDetectedValue() {
protected long getDetectedValue() {
return 10000;
}
};
@@ -11,6 +11,7 @@ import org.junit.Test;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.web.alarm.CheckerCategory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.alarm.collector.ResponseTimeDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
import com.nhn.pinpoint.web.applicationmap.histogram.TimeHistogram;
@@ -62,7 +63,7 @@ public class ErrorCountCheckerTest {
@Test
public void checkTest1() {
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.ERROR_COUNT.getName(), 74, "testGroup", false, false);
ErrorCountChecker filter = new ErrorCountChecker(collector, rule);
@@ -76,7 +77,7 @@ public class ErrorCountCheckerTest {
@Test
public void checkTest2() {
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.ERROR_COUNT.getName(), 76, "testGroup", false, false);
ErrorCountChecker filter = new ErrorCountChecker(collector, rule);
@@ -10,6 +10,7 @@ import org.junit.Test;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.web.alarm.CheckerCategory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.alarm.collector.ResponseTimeDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
import com.nhn.pinpoint.web.applicationmap.histogram.TimeHistogram;
@@ -61,7 +62,7 @@ public class ErrorRateCheckerTest {
@Test
public void checkTest1() {
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.ERROR_RATE.getName(), 60, "testGroup", false, false);
ErrorRateChecker filter = new ErrorRateChecker(collector, rule);
@@ -75,7 +76,7 @@ public class ErrorRateCheckerTest {
@Test
public void checkTest2() {
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.ERROR_RATE.getName(), 61, "testGroup", false, false);
ErrorRateChecker filter = new ErrorRateChecker(collector, rule);
@@ -0,0 +1,106 @@
package com.nhn.pinpoint.web.alarm.filter;
import static org.junit.Assert.*;
import java.util.LinkedList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.common.bo.AgentStatMemoryGcBo;
import com.nhn.pinpoint.common.bo.AgentStatMemoryGcBo.Builder;
import com.nhn.pinpoint.web.alarm.CheckerCategory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.alarm.collector.AgentStatDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
import com.nhn.pinpoint.web.dao.AgentStatDao;
import com.nhn.pinpoint.web.dao.ApplicationIndexDao;
import com.nhn.pinpoint.web.vo.AgentStat;
import com.nhn.pinpoint.web.vo.Application;
import com.nhn.pinpoint.web.vo.Range;
public class GcCountCheckerTest {
private static final String SERVICE_NAME = "local_service";
private static ApplicationIndexDao applicationIndexDao;
private static AgentStatDao agentStatDao;
@BeforeClass
public static void before() {
agentStatDao = new AgentStatDao() {
@Override
public List<AgentStat> scanAgentStatList(String agentId, Range range) {
List<AgentStat> AgentStatList = new LinkedList<AgentStat>();
for (int i = 1; i < 37; i++) {
Builder builder = new Builder("AGETNT_NAME", 0L, 1L);
builder.jvmGcOldCount(i);
AgentStatMemoryGcBo memoryBo = builder.build();
AgentStat stat = new AgentStat();
stat.setMemoryGc(memoryBo);
AgentStatList.add(stat);
}
return AgentStatList;
}
};
applicationIndexDao = new ApplicationIndexDao() {
@Override
public List<Application> selectAllApplicationNames() {
throw new UnsupportedOperationException();
}
@Override
public List<String> selectAgentIds(String applicationName) {
if (SERVICE_NAME.equals(applicationName)) {
List<String> agentIds = new LinkedList<String>();
agentIds.add("local_tomcat");
return agentIds;
}
throw new IllegalArgumentException();
}
@Override
public void deleteApplicationName(String applicationName) {
throw new UnsupportedOperationException();
}
};
}
@Test
public void checkTest1() {
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.GC_COUNT.getName(), 35, "testGroup", false, false);
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN);
AgentChecker checker = new GcCountChecker(collector, rule);
checker.check();
assertTrue(checker.isDetected());
}
@Test
public void checkTest2() {
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.GC_COUNT.getName(), 36, "testGroup", false, false);
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN);
AgentChecker checker = new GcCountChecker(collector, rule);
checker.check();
assertFalse(checker.isDetected());
}
}
@@ -0,0 +1,130 @@
package com.nhn.pinpoint.web.alarm.filter;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.LinkedList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.common.bo.AgentStatMemoryGcBo;
import com.nhn.pinpoint.common.bo.AgentStatMemoryGcBo.Builder;
import com.nhn.pinpoint.web.alarm.CheckerCategory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.alarm.collector.AgentStatDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
import com.nhn.pinpoint.web.dao.AgentStatDao;
import com.nhn.pinpoint.web.dao.ApplicationIndexDao;
import com.nhn.pinpoint.web.vo.AgentStat;
import com.nhn.pinpoint.web.vo.Application;
import com.nhn.pinpoint.web.vo.Range;
//@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration("classpath:applicationContext-test.xml")
public class HeapUsageRateCheckerTest {
private static final String SERVICE_NAME = "local_service";
private static ApplicationIndexDao applicationIndexDao;
private static AgentStatDao agentStatDao;
@BeforeClass
public static void before() {
agentStatDao = new AgentStatDao() {
@Override
public List<AgentStat> scanAgentStatList(String agentId, Range range) {
List<AgentStat> AgentStatList = new LinkedList<AgentStat>();
for (int i = 0; i < 36; i++) {
Builder builder = new Builder("AGETNT_NAME", 0L, 1L);
builder.jvmMemoryHeapUsed(70L);
builder.jvmMemoryHeapMax(100L);
AgentStatMemoryGcBo memoryBo = builder.build();
AgentStat stat = new AgentStat();
stat.setMemoryGc(memoryBo);
AgentStatList.add(stat);
}
return AgentStatList;
}
};
applicationIndexDao = new ApplicationIndexDao() {
@Override
public List<Application> selectAllApplicationNames() {
throw new UnsupportedOperationException();
}
@Override
public List<String> selectAgentIds(String applicationName) {
if (SERVICE_NAME.equals(applicationName)) {
List<String> agentIds = new LinkedList<String>();
agentIds.add("local_tomcat");
return agentIds;
}
throw new IllegalArgumentException();
}
@Override
public void deleteApplicationName(String applicationName) {
throw new UnsupportedOperationException();
}
};
}
@Test
public void checkTest1() {
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.HEAP_USAGE_RATE.getName(), 70, "testGroup", false, false);
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN);
AgentChecker checker = new HeapUsageRateChecker(collector, rule);
checker.check();
assertTrue(checker.isDetected());
}
@Test
public void checkTest2() {
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.HEAP_USAGE_RATE.getName(), 71, "testGroup", false, false);
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN);
AgentChecker checker = new HeapUsageRateChecker(collector, rule);
checker.check();
assertFalse(checker.isDetected());
}
// @Autowired
// private HbaseAgentStatDao hbaseAgentStatDao ;
// @Autowired
// private HbaseApplicationIndexDao applicationIndexDao;
// @Test
// public void checkTest1() {
// Rule rule = new Rule(SERVICE_NAME, CheckerCategory.HEAP_USAGE_RATE.getName(), 60, "testGroup", false, false);
// Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
// AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, hbaseAgentStatDao, applicationIndexDao, System.currentTimeMillis(), (long)300000);
// AgentChecker checker = new HeapUsageRateChecker(collector, rule);
//
// checker.check();
// assertTrue(checker.isDetected());
// }
}
@@ -0,0 +1,109 @@
package com.nhn.pinpoint.web.alarm.filter;
import static org.junit.Assert.*;
import java.util.LinkedList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.common.bo.AgentStatCpuLoadBo;
import com.nhn.pinpoint.common.bo.AgentStatMemoryGcBo;
import com.nhn.pinpoint.web.alarm.CheckerCategory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.alarm.collector.AgentStatDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
import com.nhn.pinpoint.web.dao.AgentStatDao;
import com.nhn.pinpoint.web.dao.ApplicationIndexDao;
import com.nhn.pinpoint.web.vo.AgentStat;
import com.nhn.pinpoint.web.vo.Application;
import com.nhn.pinpoint.web.vo.Range;
public class JvmCpuUsageRateCheckerTest {
private static final String SERVICE_NAME = "local_service";
private static ApplicationIndexDao applicationIndexDao;
private static AgentStatDao agentStatDao;
@BeforeClass
public static void before() {
agentStatDao = new AgentStatDao() {
@Override
public List<AgentStat> scanAgentStatList(String agentId, Range range) {
List<AgentStat> AgentStatList = new LinkedList<AgentStat>();
for (int i = 0; i < 36; i++) {
AgentStatCpuLoadBo.Builder cpuLoadBoBuilder = new AgentStatCpuLoadBo.Builder("AGETNT_NAME", 0L, 1L);
cpuLoadBoBuilder.jvmCpuLoad(60);
AgentStatCpuLoadBo cpuLoadBo = cpuLoadBoBuilder.build();
AgentStatMemoryGcBo.Builder memoryGcBobuilder = new AgentStatMemoryGcBo.Builder("AGETNT_NAME", 0L, 1L);
AgentStatMemoryGcBo memoryGcBo = memoryGcBobuilder.build();
AgentStat stat = new AgentStat();
stat.setCpuLoad(cpuLoadBo);
stat.setMemoryGc(memoryGcBo);
AgentStatList.add(stat);
}
return AgentStatList;
}
};
applicationIndexDao = new ApplicationIndexDao() {
@Override
public List<Application> selectAllApplicationNames() {
throw new UnsupportedOperationException();
}
@Override
public List<String> selectAgentIds(String applicationName) {
if (SERVICE_NAME.equals(applicationName)) {
List<String> agentIds = new LinkedList<String>();
agentIds.add("local_tomcat");
return agentIds;
}
throw new IllegalArgumentException();
}
@Override
public void deleteApplicationName(String applicationName) {
throw new UnsupportedOperationException();
}
};
}
@Test
public void checkTest1() {
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.JVM_CPU_USAGE_RATE.getName(), 60, "testGroup", false, false);
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN);
AgentChecker checker = new JvmCpuUsageRateChecker(collector, rule);
checker.check();
assertTrue(checker.isDetected());
}
@Test
public void checkTest2() {
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.JVM_CPU_USAGE_RATE.getName(), 61, "testGroup", false, false);
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN);
AgentChecker checker = new JvmCpuUsageRateChecker(collector, rule);
checker.check();
assertFalse(checker.isDetected());
}
}
@@ -10,6 +10,8 @@ import org.junit.Test;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.web.alarm.CheckerCategory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.alarm.collector.ResponseTimeDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
import com.nhn.pinpoint.web.applicationmap.histogram.TimeHistogram;
@@ -62,7 +64,7 @@ public class ResponseCountCheckerTest {
@Test
public void checkTest1() {
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN);
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.RESPONSE_COUNT.getName(), 125, "testGroup", false, false);
ResponseCountChecker filter = new ResponseCountChecker(collector, rule);
@@ -76,11 +78,18 @@ public class ResponseCountCheckerTest {
@Test
public void checkTest2() {
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.RESPONSE_COUNT.getName(), 126, "testGroup", false, false);
ResponseCountChecker filter = new ResponseCountChecker(collector, rule);
filter.check();
assertFalse(filter.isDetected());
}
@Test
public void test() {
double val = -1;
int i = (int) val;
System.out.println(val);
}
}
@@ -11,6 +11,7 @@ import org.junit.Test;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.web.alarm.CheckerCategory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.alarm.collector.DataCollector;
import com.nhn.pinpoint.web.alarm.collector.ResponseTimeDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
@@ -63,7 +64,7 @@ public class SlowCountFilterTest {
@Test
public void checkTest1() {
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.SLOW_COUNT.getName(), 74, "testGroup", false, false);
SlowCountFilter filter = new SlowCountFilter(collector, rule);
@@ -77,7 +78,7 @@ public class SlowCountFilterTest {
@Test
public void checkTest2() {
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.SLOW_COUNT.getName(), 76, "testGroup", false, false);
SlowCountFilter filter = new SlowCountFilter(collector, rule);
@@ -11,6 +11,7 @@ import org.junit.Test;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.web.alarm.CheckerCategory;
import com.nhn.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory;
import com.nhn.pinpoint.web.alarm.collector.ResponseTimeDataCollector;
import com.nhn.pinpoint.web.alarm.vo.Rule;
import com.nhn.pinpoint.web.applicationmap.histogram.TimeHistogram;
@@ -62,7 +63,7 @@ public class SlowRatesFilterTest {
@Test
public void checkTest1() {
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.SLOW_RATE.getName(), 60, "testGroup", false, false);
SlowRatesFilter filter = new SlowRatesFilter(collector, rule);
@@ -76,7 +77,7 @@ public class SlowRatesFilterTest {
@Test
public void checkTest2() {
Application application = new Application(SERVICE_NAME, ServiceType.TOMCAT);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000);
Rule rule = new Rule(SERVICE_NAME, CheckerCategory.SLOW_RATE.getName(), 61, "testGroup", false, false);
SlowRatesFilter filter = new SlowRatesFilter(collector, rule);