From dcdabc390a9cbc3e09fb9c3dc2491bb4e4f1a669 Mon Sep 17 00:00:00 2001 From: HyunGil Jeong Date: Wed, 17 Aug 2016 17:06:17 +0900 Subject: [PATCH] #1533 Add web support for agent stat storage version 2 --- .../web/alarm/DataCollectorFactory.java | 14 +- .../collector/AgentStatDataCollector.java | 42 +- .../web/controller/AgentInfoController.java | 132 +++++ .../web/controller/AgentStatController.java | 236 ++++----- .../web/controller/ApplicationController.java | 8 - .../controller/LegacyAgentStatController.java | 121 +++++ .../SampledAgentStatDao.java} | 61 +-- .../dao/hbase/stat/AgentStatDaoFactory.java | 236 +++++++++ .../hbase/stat/LegacyHbaseAgentStatDao.java | 131 +++++ .../stat/SampledAgentStatDaoFactory.java | 236 +++++++++ .../HbaseAgentStatDualReadDao.java | 99 ++++ .../HbaseSampledAgentStatDualReadDao.java | 88 ++++ .../web/dao/hbase/stat/v1/Aggregator.java | 278 ++++++++++ .../hbase/stat/v1/HbaseActiveTraceDao.java | 52 ++ .../v1/HbaseAgentStatDaoOperations.java} | 173 +++---- .../dao/hbase/stat/v1/HbaseCpuLoadDao.java | 52 ++ .../web/dao/hbase/stat/v1/HbaseJvmGcDao.java | 52 ++ .../hbase/stat/v1/HbaseJvmGcDetailedDao.java | 46 ++ .../stat/v1/HbaseSampledActiveTraceDao.java | 53 ++ .../hbase/stat/v1/HbaseSampledCpuLoadDao.java | 53 ++ .../hbase/stat/v1/HbaseSampledJvmGcDao.java | 53 ++ .../stat/v1/HbaseSampledJvmGcDetailedDao.java | 37 ++ .../stat/v1/HbaseSampledTransactionDao.java | 53 ++ .../hbase/stat/v1/HbaseTransactionDao.java | 52 ++ .../hbase/stat/v2/HbaseActiveTraceDaoV2.java | 53 ++ .../v2/HbaseAgentStatDaoOperationsV2.java | 140 +++++ .../dao/hbase/stat/v2/HbaseCpuLoadDaoV2.java | 53 ++ .../dao/hbase/stat/v2/HbaseJvmGcDaoV2.java | 53 ++ .../stat/v2/HbaseJvmGcDetailedDaoV2.java | 53 ++ .../stat/v2/HbaseSampledActiveTraceDaoV2.java | 54 ++ .../stat/v2/HbaseSampledCpuLoadDaoV2.java | 54 ++ .../hbase/stat/v2/HbaseSampledJvmGcDaoV2.java | 54 ++ .../v2/HbaseSampledJvmGcDetailedDaoV2.java | 54 ++ .../stat/v2/HbaseSampledTransactionDaoV2.java | 54 ++ .../hbase/stat/v2/HbaseTransactionDaoV2.java | 53 ++ .../stat/ActiveTraceDao.java} | 15 +- .../pinpoint/web/dao/stat/AgentStatDao.java | 32 ++ .../pinpoint/web/dao/stat/CpuLoadDao.java | 25 + .../pinpoint/web/dao/stat/JvmGcDao.java | 25 + .../web/dao/stat/JvmGcDetailedDao.java | 25 + .../LegacyAgentStatDao.java} | 12 +- .../web/dao/stat/SampledActiveTraceDao.java | 26 + .../web/dao/stat/SampledCpuLoadDao.java | 26 + .../web/dao/stat/SampledJvmGcDao.java | 26 + .../web/dao/stat/SampledJvmGcDetailedDao.java | 26 + .../web/dao/stat/SampledTransactionDao.java | 26 + .../pinpoint/web/dao/stat/TransactionDao.java | 25 + .../web/mapper/RangeTimestampFilter.java | 36 ++ .../pinpoint/web/mapper/TimestampFilter.java | 24 + .../web/mapper/stat/AgentStatMapper.java | 28 + .../web/mapper/stat/AgentStatMapperV1.java | 287 +++++++++++ .../web/mapper/stat/AgentStatMapperV2.java | 92 ++++ .../LegacyAgentStatMapper.java} | 12 +- .../SampledActiveTraceResultExtractor.java | 75 +++ .../stat/SampledAgentStatResultExtractor.java | 88 ++++ .../stat/SampledCpuLoadResultExtractor.java | 59 +++ .../SampledJvmGcDetailedResultExtractor.java | 82 +++ .../stat/SampledJvmGcResultExtractor.java | 71 +++ .../SampledTransactionResultExtractor.java | 80 +++ .../web/service/AdminServiceImpl.java | 11 +- .../service/stat/ActiveTraceChartService.java | 54 ++ .../web/service/stat/ActiveTraceService.java | 51 ++ .../stat/AgentStatChartService.java} | 57 +-- .../web/service/stat/AgentStatService.java | 29 ++ .../web/service/stat/CpuLoadChartService.java | 54 ++ .../web/service/stat/CpuLoadService.java | 51 ++ .../web/service/stat/JvmGcChartService.java | 54 ++ .../stat/JvmGcDetailedChartService.java | 54 ++ .../service/stat/JvmGcDetailedService.java | 51 ++ .../JvmGcService.java} | 43 +- ...acyAgentStatChartCompatibilityService.java | 95 ++++ .../stat/LegacyAgentStatChartService.java} | 58 +-- .../LegacyAgentStatChartServiceFactory.java | 73 +++ .../stat/LegacyAgentStatChartV1Service.java | 56 ++ .../stat/LegacyAgentStatChartV2Service.java | 77 +++ .../service/stat/TransactionChartService.java | 54 ++ .../web/service/stat/TransactionService.java | 51 ++ .../pinpoint/web/util/AgentStats.java | 169 ------ .../navercorp/pinpoint/web/vo/AgentStat.java | 2 +- .../pinpoint/web/vo/chart/Chart.java | 54 ++ .../vo/{linechart => chart}/DataPoint.java | 90 ++-- .../web/vo/chart/LegacyChartBuilder.java | 54 ++ .../LegacySampledChartBuilder.java} | 100 ++-- .../LegacySampledTimeSeriesChartBuilder.java | 82 +++ ...cySampledTitledTimeSeriesChartBuilder.java | 44 ++ .../pinpoint/web/vo/chart/Point.java | 82 +++ .../web/vo/chart/TimeSeriesChartBuilder.java | 55 ++ .../{linechart => chart}/TitledDataPoint.java | 5 +- .../pinpoint/web/vo/chart/TitledPoint.java | 59 +++ .../web/vo/chart/UncollectedPoint.java | 36 ++ .../pinpoint/web/vo/linechart/Chart.java | 114 ----- .../vo/linechart/SampledDataChartBuilder.java | 61 --- .../SampledTimeSeriesChartBuilder.java | 79 --- .../agentstat/AgentStatChartGroup.java | 188 ------- .../navercorp/pinpoint/web/vo/stat/JvmGc.java | 130 +++++ .../web/vo/stat/SampledActiveTrace.java | 94 ++++ .../vo/stat/SampledAgentStatDataPoint.java | 24 + .../pinpoint/web/vo/stat/SampledCpuLoad.java | 70 +++ .../pinpoint/web/vo/stat/SampledJvmGc.java | 118 +++++ .../web/vo/stat/SampledJvmGcDetailed.java | 144 ++++++ .../web/vo/stat/SampledTransaction.java | 108 ++++ .../vo/stat/chart/ActiveTraceChartGroup.java | 68 +++ .../chart/AgentStatChartGroup.java} | 17 +- .../web/vo/stat/chart/CpuLoadChartGroup.java | 60 +++ .../web/vo/stat/chart/DownSampler.java | 35 ++ .../chart}/DownSamplers.java | 8 +- .../web/vo/stat/chart/JvmGcChartGroup.java | 76 +++ .../stat/chart/JvmGcDetailedChartGroup.java | 85 ++++ .../stat/chart/LegacyAgentStatChartGroup.java | 306 +++++++++++ .../vo/stat/chart/TransactionChartGroup.java | 72 +++ web/src/main/resources-local/log4j.xml | 6 - web/src/main/resources-release/log4j.xml | 6 - .../resources/applicationContext-hbase.xml | 10 + .../main/resources/applicationContext-web.xml | 3 +- .../main/resources/pinpoint-web.properties | 6 +- .../common/services/agent-dao.service.js | 28 +- .../web/alarm/checker/GcCountCheckerTest.java | 46 +- .../checker/HeapUsageRateCheckerTest.java | 55 +- .../checker/JvmCpuUsageRateCheckerTest.java | 49 +- ...st.java => LegacyAgentStatMapperTest.java} | 479 +++++++++--------- .../mapper/stat/AgentStatMapperV2Test.java | 230 +++++++++ .../SampledAgentStatResultExtractorTest.java | 277 ++++++++++ .../SampledDataChartBuilderTest.java | 76 --- 123 files changed, 7663 insertions(+), 1526 deletions(-) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/controller/AgentInfoController.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/controller/LegacyAgentStatController.java rename web/src/main/java/com/navercorp/pinpoint/web/{vo/linechart/SampledTimeSeriesIntegerChartBuilder.java => dao/SampledAgentStatDao.java} (64%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/AgentStatDaoFactory.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/LegacyHbaseAgentStatDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/SampledAgentStatDaoFactory.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/compatibility/HbaseAgentStatDualReadDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/compatibility/HbaseSampledAgentStatDualReadDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/Aggregator.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseActiveTraceDao.java rename web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/{HbaseAgentStatDao.java => stat/v1/HbaseAgentStatDaoOperations.java} (59%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseCpuLoadDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseJvmGcDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseJvmGcDetailedDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledActiveTraceDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledCpuLoadDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledJvmGcDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledJvmGcDetailedDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledTransactionDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseTransactionDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseActiveTraceDaoV2.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseAgentStatDaoOperationsV2.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseCpuLoadDaoV2.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseJvmGcDaoV2.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseJvmGcDetailedDaoV2.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledActiveTraceDaoV2.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledCpuLoadDaoV2.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledJvmGcDaoV2.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledJvmGcDetailedDaoV2.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledTransactionDaoV2.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseTransactionDaoV2.java rename web/src/main/java/com/navercorp/pinpoint/web/{vo/linechart/SampledDataDoubleChartBuilder.java => dao/stat/ActiveTraceDao.java} (63%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/stat/AgentStatDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/stat/CpuLoadDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/stat/JvmGcDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/stat/JvmGcDetailedDao.java rename web/src/main/java/com/navercorp/pinpoint/web/dao/{AgentStatDao.java => stat/LegacyAgentStatDao.java} (76%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledActiveTraceDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledCpuLoadDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledJvmGcDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledJvmGcDetailedDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledTransactionDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/dao/stat/TransactionDao.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/mapper/RangeTimestampFilter.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/mapper/TimestampFilter.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapper.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV1.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2.java rename web/src/main/java/com/navercorp/pinpoint/web/mapper/{AgentStatMapper.java => stat/LegacyAgentStatMapper.java} (98%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledActiveTraceResultExtractor.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractor.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledCpuLoadResultExtractor.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledJvmGcDetailedResultExtractor.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledJvmGcResultExtractor.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledTransactionResultExtractor.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/ActiveTraceChartService.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/ActiveTraceService.java rename web/src/main/java/com/navercorp/pinpoint/web/{vo/linechart/SampledTimeSeriesLongChartBuilder.java => service/stat/AgentStatChartService.java} (62%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatService.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/CpuLoadChartService.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/CpuLoadService.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcChartService.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcDetailedChartService.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcDetailedService.java rename web/src/main/java/com/navercorp/pinpoint/web/service/{AgentStatServiceImpl.java => stat/JvmGcService.java} (55%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartCompatibilityService.java rename web/src/main/java/com/navercorp/pinpoint/web/{vo/linechart/SampledTimeSeriesDoubleChartBuilder.java => service/stat/LegacyAgentStatChartService.java} (62%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartServiceFactory.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartV1Service.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartV2Service.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/TransactionChartService.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/stat/TransactionService.java delete mode 100644 web/src/main/java/com/navercorp/pinpoint/web/util/AgentStats.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/chart/Chart.java rename web/src/main/java/com/navercorp/pinpoint/web/vo/{linechart => chart}/DataPoint.java (84%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacyChartBuilder.java rename web/src/main/java/com/navercorp/pinpoint/web/vo/{linechart/SampledChartBuilder.java => chart/LegacySampledChartBuilder.java} (72%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacySampledTimeSeriesChartBuilder.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacySampledTitledTimeSeriesChartBuilder.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/chart/Point.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/chart/TimeSeriesChartBuilder.java rename web/src/main/java/com/navercorp/pinpoint/web/vo/{linechart => chart}/TitledDataPoint.java (92%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/chart/TitledPoint.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/chart/UncollectedPoint.java delete mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/Chart.java delete mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataChartBuilder.java delete mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesChartBuilder.java delete mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/agentstat/AgentStatChartGroup.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/JvmGc.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledActiveTrace.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledAgentStatDataPoint.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledCpuLoad.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGc.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGcDetailed.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledTransaction.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/ActiveTraceChartGroup.java rename web/src/main/java/com/navercorp/pinpoint/web/vo/{linechart/SampledDataLongChartBuilder.java => stat/chart/AgentStatChartGroup.java} (63%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/CpuLoadChartGroup.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/DownSampler.java rename web/src/main/java/com/navercorp/pinpoint/web/vo/{linechart => stat/chart}/DownSamplers.java (96%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/JvmGcChartGroup.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/JvmGcDetailedChartGroup.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/LegacyAgentStatChartGroup.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/TransactionChartGroup.java rename web/src/test/java/com/navercorp/pinpoint/web/mapper/{AgentStatMapperTest.java => LegacyAgentStatMapperTest.java} (96%) create mode 100644 web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2Test.java create mode 100644 web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractorTest.java delete mode 100644 web/src/test/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataChartBuilderTest.java diff --git a/web/src/main/java/com/navercorp/pinpoint/web/alarm/DataCollectorFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/alarm/DataCollectorFactory.java index 1f23cc72c..bdb848a04 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/alarm/DataCollectorFactory.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/alarm/DataCollectorFactory.java @@ -16,14 +16,17 @@ package com.navercorp.pinpoint.web.alarm; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; +import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; import com.navercorp.pinpoint.web.alarm.collector.AgentStatDataCollector; import com.navercorp.pinpoint.web.alarm.collector.DataCollector; import com.navercorp.pinpoint.web.alarm.collector.MapStatisticsCallerDataCollector; import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; -import com.navercorp.pinpoint.web.dao.hbase.HbaseAgentStatDao; import com.navercorp.pinpoint.web.dao.hbase.HbaseApplicationIndexDao; import com.navercorp.pinpoint.web.dao.hbase.HbaseMapResponseTimeDao; import com.navercorp.pinpoint.web.dao.hbase.HbaseMapStatisticsCallerDao; @@ -43,7 +46,12 @@ public class DataCollectorFactory { private HbaseMapResponseTimeDao hbaseMapResponseTimeDao; @Autowired - private HbaseAgentStatDao hbaseAgentStatDao; + @Qualifier("jvmGcDaoFactory") + private AgentStatDao jvmGcDao; + + @Autowired + @Qualifier("cpuLoadDaoFactory") + private AgentStatDao cpuLoadDao; @Autowired private HbaseApplicationIndexDao hbaseApplicationIndexDao; @@ -56,7 +64,7 @@ public class DataCollectorFactory { case RESPONSE_TIME: 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_FIVE_MIN); + return new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, jvmGcDao, cpuLoadDao, hbaseApplicationIndexDao, timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN); case CALLER_STAT: return new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, mapStatisticsCallerDao, timeSlotEndTime, SLOT_INTERVAL_FIVE_MIN); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/alarm/collector/AgentStatDataCollector.java b/web/src/main/java/com/navercorp/pinpoint/web/alarm/collector/AgentStatDataCollector.java index 4f91c8c59..ecaae6a34 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/alarm/collector/AgentStatDataCollector.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/alarm/collector/AgentStatDataCollector.java @@ -21,10 +21,11 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; -import com.navercorp.pinpoint.web.dao.AgentStatDao; +import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; -import com.navercorp.pinpoint.web.vo.AgentStat; import com.navercorp.pinpoint.web.vo.Application; import com.navercorp.pinpoint.web.vo.Range; @@ -34,7 +35,8 @@ import com.navercorp.pinpoint.web.vo.Range; public class AgentStatDataCollector extends DataCollector { private final Application application; - private final AgentStatDao agentStatDao; + private final AgentStatDao jvmGcDao; + private final AgentStatDao cpuLoadDao; private final ApplicationIndexDao applicationIndexDao; private final long timeSlotEndTime; private final long slotInterval; @@ -44,10 +46,11 @@ public class AgentStatDataCollector extends DataCollector { private final Map agentGcCount = new HashMap<>(); private final Map agentJvmCpuUsageRate = new HashMap<>(); - public AgentStatDataCollector(DataCollectorCategory category, Application application, AgentStatDao agentStatDao, ApplicationIndexDao applicationIndexDao, long timeSlotEndTime, long slotInterval) { + public AgentStatDataCollector(DataCollectorCategory category, Application application, AgentStatDao jvmGcDao, AgentStatDao cpuLoadDao, ApplicationIndexDao applicationIndexDao, long timeSlotEndTime, long slotInterval) { super(category); this.application = application; - this.agentStatDao = agentStatDao; + this.jvmGcDao = jvmGcDao; + this.cpuLoadDao = cpuLoadDao; this.applicationIndexDao = applicationIndexDao; this.timeSlotEndTime = timeSlotEndTime; this.slotInterval = slotInterval; @@ -63,29 +66,32 @@ public class AgentStatDataCollector extends DataCollector { List agentIds = applicationIndexDao.selectAgentIds(application.getName()); for(String agentId : agentIds) { - List scanAgentStatList = agentStatDao.getAgentStatList(agentId, range); - int listSize = scanAgentStatList.size(); + List jvmGcBos = jvmGcDao.getAgentStatList(agentId, range); + List cpuLoadBos = cpuLoadDao.getAgentStatList(agentId, range); long totalHeapSize = 0; long usedHeapSize = 0; long jvmCpuUsaged = 0; - for (AgentStat agentStat : scanAgentStatList) { - totalHeapSize += agentStat.getHeapMax(); - usedHeapSize += agentStat.getHeapUsed(); - - jvmCpuUsaged += agentStat.getJvmCpuUsage() * 100; + for (JvmGcBo jvmGcBo : jvmGcBos) { + totalHeapSize += jvmGcBo.getHeapMax(); + usedHeapSize += jvmGcBo.getHeapUsed(); } - if(listSize > 0) { + for (CpuLoadBo cpuLoadBo : cpuLoadBos) { + jvmCpuUsaged += cpuLoadBo.getJvmCpuLoad() * 100; + } + + if (!jvmGcBos.isEmpty()) { long percent = calculatePercent(usedHeapSize, totalHeapSize); agentHeapUsageRate.put(agentId, percent); - percent = calculatePercent(jvmCpuUsaged, 100*scanAgentStatList.size()); + long accruedLastGcCount = jvmGcBos.get(0).getGcOldCount(); + long accruedFirstGcCount = jvmGcBos.get(jvmGcBos.size() - 1).getGcOldCount(); + agentGcCount.put(agentId, accruedLastGcCount - accruedFirstGcCount); + } + if (!cpuLoadBos.isEmpty()) { + long percent = calculatePercent(jvmCpuUsaged, 100 * cpuLoadBos.size()); agentJvmCpuUsageRate.put(agentId, percent); - - long accruedLastGCcount = scanAgentStatList.get(0).getGcOldCount(); - long accruedFirstGCcount= scanAgentStatList.get(listSize - 1).getGcOldCount(); - agentGcCount.put(agentId, accruedLastGCcount - accruedFirstGCcount); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentInfoController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentInfoController.java new file mode 100644 index 000000000..aa3cf3a28 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentInfoController.java @@ -0,0 +1,132 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.controller; + +import com.navercorp.pinpoint.web.service.AgentEventService; +import com.navercorp.pinpoint.web.service.AgentInfoService; +import com.navercorp.pinpoint.web.vo.AgentEvent; +import com.navercorp.pinpoint.web.vo.AgentInfo; +import com.navercorp.pinpoint.web.vo.AgentStatus; +import com.navercorp.pinpoint.web.vo.ApplicationAgentList; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Controller +public class AgentInfoController { + + @Autowired + private AgentInfoService agentInfoService; + + @Autowired + private AgentEventService agentEventService; + + @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"!application"}) + @ResponseBody + public ApplicationAgentList getAgentList() { + return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.APPLICATION_NAME); + } + + @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"!application", "from", "to"}) + @ResponseBody + public ApplicationAgentList getAgentList( + @RequestParam("from") long from, + @RequestParam("to") long to) { + return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.APPLICATION_NAME, to); + } + + @PreAuthorize("hasPermission(#applicationName, 'application', 'inspector')") + @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"!application", "timestamp"}) + @ResponseBody + public ApplicationAgentList getAgentList( + @RequestParam("timestamp") long timestamp) { + return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.APPLICATION_NAME, timestamp); + } + + @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"application"}) + @ResponseBody + public ApplicationAgentList getAgentList( + @RequestParam("application") String applicationName) { + return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.HOST_NAME, applicationName); + } + + @PreAuthorize("hasPermission(#applicationName, 'application', 'inspector')") + @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"application", "from", "to"}) + @ResponseBody + public ApplicationAgentList getAgentList( + @RequestParam("application") String applicationName, + @RequestParam("from") long from, + @RequestParam("to") long to) { + return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.HOST_NAME, applicationName, to); + } + + @PreAuthorize("hasPermission(#applicationName, 'application', 'inspector')") + @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"application", "timestamp"}) + @ResponseBody + public ApplicationAgentList getAgentList( + @RequestParam("application") String applicationName, + @RequestParam("timestamp") long timestamp) { + return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.HOST_NAME, applicationName, timestamp); + } + + @RequestMapping(value = "/getAgentInfo", method = RequestMethod.GET) + @ResponseBody + public AgentInfo getAgentInfo( + @RequestParam("agentId") String agentId, + @RequestParam("timestamp") long timestamp) { + return this.agentInfoService.getAgentInfo(agentId, timestamp); + } + + @RequestMapping(value = "/getAgentStatus", method = RequestMethod.GET) + @ResponseBody + public AgentStatus getAgentStatus( + @RequestParam("agentId") String agentId, + @RequestParam("timestamp") long timestamp) { + return this.agentInfoService.getAgentStatus(agentId, timestamp); + } + + @RequestMapping(value = "/getAgentEvent", method = RequestMethod.GET) + @ResponseBody + public AgentEvent getAgentEvent( + @RequestParam("agentId") String agentId, + @RequestParam("eventTimestamp") long eventTimestamp, + @RequestParam("eventTypeCode") int eventTypeCode) { + return this.agentEventService.getAgentEvent(agentId, eventTimestamp, eventTypeCode); + } + + @PreAuthorize("hasPermission(new com.navercorp.pinpoint.web.vo.AgentParam(#agentId, #to), 'agentParam', 'inspector')") + @RequestMapping(value = "/getAgentEvents", method = RequestMethod.GET) + @ResponseBody + public List getAgentEvents( + @RequestParam("agentId") String agentId, + @RequestParam("from") long from, + @RequestParam("to") long to, + @RequestParam(value = "exclude", defaultValue = "") int[] excludeEventTypeCodes) { + Range range = new Range(from, to); + return this.agentEventService.getAgentEvents(agentId, range, excludeEventTypeCodes); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentStatController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentStatController.java index 1022ded03..b16e45427 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentStatController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentStatController.java @@ -18,178 +18,136 @@ package com.navercorp.pinpoint.web.controller; import java.util.List; -import java.util.concurrent.TimeUnit; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; +import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; +import com.navercorp.pinpoint.web.service.stat.ActiveTraceChartService; +import com.navercorp.pinpoint.web.service.stat.AgentStatChartService; +import com.navercorp.pinpoint.web.service.stat.CpuLoadChartService; +import com.navercorp.pinpoint.web.service.stat.JvmGcChartService; +import com.navercorp.pinpoint.web.service.stat.JvmGcDetailedChartService; +import com.navercorp.pinpoint.web.service.stat.JvmGcService; +import com.navercorp.pinpoint.web.service.stat.TransactionChartService; +import com.navercorp.pinpoint.web.util.TimeWindowSampler; +import com.navercorp.pinpoint.web.vo.stat.chart.AgentStatChartGroup; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; -import org.springframework.util.StopWatch; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import com.navercorp.pinpoint.web.service.AgentEventService; -import com.navercorp.pinpoint.web.service.AgentInfoService; -import com.navercorp.pinpoint.web.service.AgentStatService; +import com.navercorp.pinpoint.web.service.stat.AgentStatService; import com.navercorp.pinpoint.web.util.TimeWindow; import com.navercorp.pinpoint.web.util.TimeWindowSlotCentricSampler; -import com.navercorp.pinpoint.web.vo.AgentEvent; -import com.navercorp.pinpoint.web.vo.AgentInfo; -import com.navercorp.pinpoint.web.vo.AgentStat; -import com.navercorp.pinpoint.web.vo.AgentStatus; -import com.navercorp.pinpoint.web.vo.ApplicationAgentList; import com.navercorp.pinpoint.web.vo.Range; -import com.navercorp.pinpoint.web.vo.linechart.agentstat.AgentStatChartGroup; /** * @author emeroad * @author minwoo.jung * @author HyunGil Jeong */ -@Controller -public class AgentStatController { - private static final long USE_AGGREGATED_THRESHOLD = TimeUnit.HOURS.toMillis(24); - private static final int MAX_RESPONSE_SIZE = 200; +public abstract class AgentStatController { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); + private final AgentStatService agentStatService; - @Autowired - private AgentStatService agentStatService; + private final AgentStatChartService agentStatChartService; - @Autowired - private AgentInfoService agentInfoService; - - @Autowired - private AgentEventService agentEventService; + public AgentStatController(AgentStatService agentStatService, AgentStatChartService agentStatChartService) { + this.agentStatService = agentStatService; + this.agentStatChartService = agentStatChartService; + } @PreAuthorize("hasPermission(new com.navercorp.pinpoint.web.vo.AgentParam(#agentId, #to), 'agentParam', 'inspector')") - @RequestMapping(value = "/getAgentStat", method = RequestMethod.GET) + @RequestMapping(method = RequestMethod.GET) @ResponseBody - public AgentStatChartGroup getAgentStat( + public List getAgentStat( @RequestParam("agentId") String agentId, @RequestParam("from") long from, - @RequestParam("to") long to, - @RequestParam(value = "sampleRate", required = false) Integer sampleRate) throws Exception { - StopWatch watch = new StopWatch(); - watch.start("agentStatService.selectAgentStatList"); - - Range requestRange = new Range(from, to); - boolean useAggregated = requestRange.getRange() > USE_AGGREGATED_THRESHOLD; - - long interval = useAggregated ? AgentStat.AGGR_SAMPLE_INTERVAL : AgentStat.RAW_SAMPLE_INTERVAL; - TimeWindowSlotCentricSampler sampler = new TimeWindowSlotCentricSampler(interval, MAX_RESPONSE_SIZE); + @RequestParam("to") long to) { + Range rangeToScan = new Range(from, to); + return this.agentStatService.selectAgentStatList(agentId, rangeToScan); + } + + @PreAuthorize("hasPermission(new com.navercorp.pinpoint.web.vo.AgentParam(#agentId, #to), 'agentParam', 'inspector')") + @RequestMapping(value = "/chart", method = RequestMethod.GET) + @ResponseBody + public AgentStatChartGroup getAgentStatChart( + @RequestParam("agentId") String agentId, + @RequestParam("from") long from, + @RequestParam("to") long to) { + TimeWindowSampler sampler = new TimeWindowSlotCentricSampler(); TimeWindow timeWindow = new TimeWindow(new Range(from, to), sampler); - - long scanFrom = timeWindow.getWindowRange().getFrom(); - long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); - Range rangeToScan = new Range(scanFrom, scanTo); - - - List agentStatList; - - if (useAggregated) { - agentStatList = agentStatService.selectAggregatedAgentStatList(agentId, rangeToScan); - } else { - agentStatList = agentStatService.selectAgentStatList(agentId, rangeToScan); - } - watch.stop(); - - if (logger.isInfoEnabled()) { - logger.info("getAgentStat(agentId={}, from={}, to={}) : {}ms", agentId, from, to, watch.getLastTaskTimeMillis()); - } - - AgentStatChartGroup chartGroup = new AgentStatChartGroup(timeWindow); - chartGroup.addAgentStats(agentStatList); - chartGroup.buildCharts(); - - return chartGroup; - } - - @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"!application"}) - @ResponseBody - public ApplicationAgentList getAgentList() { - return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.APPLICATION_NAME); - } - - @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"!application", "from", "to"}) - @ResponseBody - public ApplicationAgentList getAgentList( - @RequestParam("from") long from, - @RequestParam("to") long to) { - return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.APPLICATION_NAME, to); - } - - @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"!application", "timestamp"}) - @ResponseBody - public ApplicationAgentList getAgentList( - @RequestParam("timestamp") long timestamp) { - return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.APPLICATION_NAME, timestamp); - } - - @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"application"}) - @ResponseBody - public ApplicationAgentList getAgentList( - @RequestParam("application") String applicationName) { - return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.HOST_NAME, applicationName); - } - - @PreAuthorize("hasPermission(#applicationName, 'application', 'inspector')") - @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"application", "from", "to"}) - @ResponseBody - public ApplicationAgentList getAgentList( - @RequestParam("application") String applicationName, - @RequestParam("from") long from, - @RequestParam("to") long to) { - return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.HOST_NAME, applicationName, to); - } - - @PreAuthorize("hasPermission(#applicationName, 'application', 'inspector')") - @RequestMapping(value = "/getAgentList", method = RequestMethod.GET, params = {"application", "timestamp"}) - @ResponseBody - public ApplicationAgentList getAgentList( - @RequestParam("application") String applicationName, - @RequestParam("timestamp") long timestamp) { - return this.agentInfoService.getApplicationAgentList(ApplicationAgentList.Key.HOST_NAME, applicationName, timestamp); - } - - @RequestMapping(value = "/getAgentInfo", method = RequestMethod.GET) - @ResponseBody - public AgentInfo getAgentInfo( - @RequestParam("agentId") String agentId, - @RequestParam("timestamp") long timestamp) { - return this.agentInfoService.getAgentInfo(agentId, timestamp); - } - - @RequestMapping(value = "/getAgentStatus", method = RequestMethod.GET) - @ResponseBody - public AgentStatus getAgentStatus( - @RequestParam("agentId") String agentId, - @RequestParam("timestamp") long timestamp) { - return this.agentInfoService.getAgentStatus(agentId, timestamp); - } - - @RequestMapping(value = "/getAgentEvent", method = RequestMethod.GET) - @ResponseBody - public AgentEvent getAgentEvent( - @RequestParam("agentId") String agentId, - @RequestParam("eventTimestamp") long eventTimestamp, - @RequestParam("eventTypeCode") int eventTypeCode) { - return this.agentEventService.getAgentEvent(agentId, eventTimestamp, eventTypeCode); + return this.agentStatChartService.selectAgentChart(agentId, timeWindow); } @PreAuthorize("hasPermission(new com.navercorp.pinpoint.web.vo.AgentParam(#agentId, #to), 'agentParam', 'inspector')") - @RequestMapping(value = "/getAgentEvents", method = RequestMethod.GET) + @RequestMapping(value = "/chart", method = RequestMethod.GET, params = {"interval"}) @ResponseBody - public List getAgentEvents( + public AgentStatChartGroup getAgentStatChart( @RequestParam("agentId") String agentId, @RequestParam("from") long from, @RequestParam("to") long to, - @RequestParam(value = "exclude", defaultValue = "") int[] excludeEventTypeCodes) { - Range range = new Range(from, to); - return this.agentEventService.getAgentEvents(agentId, range, excludeEventTypeCodes); + @RequestParam("interval") Integer interval) { + final int minSamplingInterval = 5; + final long intervalMs = interval < minSamplingInterval ? minSamplingInterval * 1000L : interval * 1000L; + TimeWindowSampler sampler = new TimeWindowSampler() { + @Override + public long getWindowSize(Range range) { + return intervalMs; + } + }; + TimeWindow timeWindow = new TimeWindow(new Range(from, to), sampler); + return this.agentStatChartService.selectAgentChart(agentId, timeWindow); + } + + @Controller + @RequestMapping("/getAgentStat/jvmGc") + public static class JvmGcController extends AgentStatController { + @Autowired + public JvmGcController(JvmGcService jvmGcService, JvmGcChartService jvmGcChartService) { + super(jvmGcService, jvmGcChartService); + } + } + + @Controller + @RequestMapping("/getAgentStat/jvmGcDetailed") + public static class JvmGcDetailedController extends AgentStatController { + @Autowired + public JvmGcDetailedController(AgentStatService jvmGcDetailedService, JvmGcDetailedChartService jvmGcDetailedChartService) { + super(jvmGcDetailedService, jvmGcDetailedChartService); + } + } + + @Controller + @RequestMapping("/getAgentStat/cpuLoad") + public static class CpuLoadController extends AgentStatController { + @Autowired + public CpuLoadController(AgentStatService cpuLoadService, CpuLoadChartService cpuLoadChartService) { + super(cpuLoadService, cpuLoadChartService); + } + } + + @Controller + @RequestMapping("/getAgentStat/transaction") + public static class TransactionController extends AgentStatController { + @Autowired + public TransactionController(AgentStatService transactionService, TransactionChartService transactionChartService) { + super(transactionService, transactionChartService); + } + } + + @Controller + @RequestMapping("/getAgentStat/activeTrace") + public static class ActiveTraceController extends AgentStatController { + @Autowired + public ActiveTraceController(AgentStatService activeTraceService, ActiveTraceChartService activeTraceChartService) { + super(activeTraceService, activeTraceChartService); + } } - } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java index c76cd1ecf..dd0ad433e 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java @@ -15,9 +15,7 @@ package com.navercorp.pinpoint.web.controller; -import com.navercorp.pinpoint.web.service.AgentEventService; import com.navercorp.pinpoint.web.service.AgentInfoService; -import com.navercorp.pinpoint.web.service.AgentStatService; import com.navercorp.pinpoint.web.vo.ApplicationAgentHostList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -33,15 +31,9 @@ import org.springframework.web.bind.annotation.ResponseBody; @Controller public class ApplicationController { - @Autowired - private AgentStatService agentStatService; - @Autowired private AgentInfoService agentInfoService; - @Autowired - private AgentEventService agentEventService; - @RequestMapping(value = "/getApplicationHostInfo", method = RequestMethod.GET) @ResponseBody public ApplicationAgentHostList getApplicationHostInfo ( diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/LegacyAgentStatController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/LegacyAgentStatController.java new file mode 100644 index 000000000..5c78e920e --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/LegacyAgentStatController.java @@ -0,0 +1,121 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.controller; + +import com.navercorp.pinpoint.web.service.stat.LegacyAgentStatChartService; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.util.TimeWindowSlotCentricSampler; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.chart.LegacyAgentStatChartGroup; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.util.StopWatch; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * Deprecated agent stat controller only to preserve backwards compatibility until + * testing is done for agent stat v2, and the front-end API is changed. + * + * @author HyunGil Jeong + */ +@Deprecated +@Controller +public class LegacyAgentStatController { + + private static final int MAX_RESPONSE_SIZE = 200; + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + @Qualifier("legacyAgentStatChartServiceFactory") + private LegacyAgentStatChartService agentStatService; + + @Autowired + @Qualifier("legacyAgentStatChartV1Service") + private LegacyAgentStatChartService v1Service; + + @Autowired + @Qualifier("legacyAgentStatChartV2Service") + private LegacyAgentStatChartService v2Service; + + @Deprecated + @PreAuthorize("hasPermission(new com.navercorp.pinpoint.web.vo.AgentParam(#agentId, #to), 'agentParam', 'inspector')") + @RequestMapping(value = "/getAgentStat", method = RequestMethod.GET) + @ResponseBody + public LegacyAgentStatChartGroup getAgentStat( + @RequestParam("agentId") String agentId, + @RequestParam("from") long from, + @RequestParam("to") long to, + @RequestParam(value = "sampleRate", required = false) Integer sampleRate) throws Exception { + StopWatch watch = new StopWatch(); + watch.start("agentStatService.selectAgentStatList"); + TimeWindow timeWindow = new TimeWindow(new Range(from, to), new TimeWindowSlotCentricSampler()); + LegacyAgentStatChartGroup chartGroup = this.agentStatService.selectAgentStatList(agentId, timeWindow); + watch.stop(); + if (logger.isInfoEnabled()) { + logger.info("getAgentStat(agentId={}, from={}, to={}) : {}ms", agentId, from, to, watch.getLastTaskTimeMillis()); + } + return chartGroup; + } + + @Deprecated + @PreAuthorize("hasPermission(new com.navercorp.pinpoint.web.vo.AgentParam(#agentId, #to), 'agentParam', 'inspector')") + @RequestMapping(value = "/getAgentStat/v1", method = RequestMethod.GET) + @ResponseBody + public LegacyAgentStatChartGroup getAgentStatV1( + @RequestParam("agentId") String agentId, + @RequestParam("from") long from, + @RequestParam("to") long to, + @RequestParam(value = "sampleRate", required = false) Integer sampleRate) throws Exception { + StopWatch watch = new StopWatch(); + watch.start("agentStatService.selectAgentStatList"); + TimeWindow timeWindow = new TimeWindow(new Range(from, to), new TimeWindowSlotCentricSampler()); + LegacyAgentStatChartGroup chartGroup = this.v1Service.selectAgentStatList(agentId, timeWindow); + watch.stop(); + if (logger.isInfoEnabled()) { + logger.info("getAgentStatV1(agentId={}, from={}, to={}) : {}ms", agentId, from, to, watch.getLastTaskTimeMillis()); + } + return chartGroup; + } + + @Deprecated + @PreAuthorize("hasPermission(new com.navercorp.pinpoint.web.vo.AgentParam(#agentId, #to), 'agentParam', 'inspector')") + @RequestMapping(value = "/getAgentStat/v2", method = RequestMethod.GET) + @ResponseBody + public LegacyAgentStatChartGroup getAgentStatV2( + @RequestParam("agentId") String agentId, + @RequestParam("from") long from, + @RequestParam("to") long to, + @RequestParam(value = "sampleRate", required = false) Integer sampleRate) throws Exception { + StopWatch watch = new StopWatch(); + watch.start("agentStatService.selectAgentStatList"); + TimeWindow timeWindow = new TimeWindow(new Range(from, to), new TimeWindowSlotCentricSampler()); + LegacyAgentStatChartGroup chartGroup = this.v2Service.selectAgentStatList(agentId, timeWindow); + watch.stop(); + if (logger.isInfoEnabled()) { + logger.info("getAgentStatV2(agentId={}, from={}, to={}) : {}ms", agentId, from, to, watch.getLastTaskTimeMillis()); + } + return chartGroup; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesIntegerChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/SampledAgentStatDao.java similarity index 64% rename from web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesIntegerChartBuilder.java rename to web/src/main/java/com/navercorp/pinpoint/web/dao/SampledAgentStatDao.java index 73c392da0..4d1c5a5b1 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesIntegerChartBuilder.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/SampledAgentStatDao.java @@ -1,30 +1,31 @@ -/* - * Copyright 2015 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.vo.linechart; - -import com.navercorp.pinpoint.web.util.TimeWindow; - -/** - * @author HyunGil Jeong - */ -public class SampledTimeSeriesIntegerChartBuilder extends SampledTimeSeriesChartBuilder { - - public SampledTimeSeriesIntegerChartBuilder(DownSampler downSampler, TimeWindow timeWindow) { - super(downSampler, timeWindow); - } - -} +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao; + +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +public interface SampledAgentStatDao { + + List getSampledAgentStatList(String agentId, TimeWindow timeWindow); +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/AgentStatDaoFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/AgentStatDaoFactory.java new file mode 100644 index 000000000..6751738f6 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/AgentStatDaoFactory.java @@ -0,0 +1,236 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; +import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; +import com.navercorp.pinpoint.web.dao.hbase.stat.compatibility.HbaseAgentStatDualReadDao; +import com.navercorp.pinpoint.web.dao.stat.ActiveTraceDao; +import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; +import com.navercorp.pinpoint.web.dao.stat.CpuLoadDao; +import com.navercorp.pinpoint.web.dao.stat.JvmGcDao; +import com.navercorp.pinpoint.web.dao.stat.JvmGcDetailedDao; +import com.navercorp.pinpoint.web.dao.stat.TransactionDao; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Repository; + +/** + * @author HyunGil Jeong + */ +abstract class AgentStatDaoFactory> { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + protected D v1; + protected D v2; + + @Value("#{pinpointWebProps['web.experimental.stat.format.compatibility.version'] ?: 'v1'}") + private String mode = "v1"; + + D getDao() throws Exception { + logger.info("AgentStatDao Compatibility {}", mode); + if (mode.equalsIgnoreCase("v1")) { + return v1; + } else if (mode.equalsIgnoreCase("v2")) { + return v2; + } else if (mode.equalsIgnoreCase("compatibilityMode")) { + return getCompatibilityDao(this.v1, this.v2); + } + return v1; + } + + abstract D getCompatibilityDao(D v1, D v2); + + @Repository("jvmGcDaoFactory") + public static class JvmGcDaoFactory extends AgentStatDaoFactory implements FactoryBean { + + @Autowired + public void setV1(@Qualifier("jvmGcDaoV1") JvmGcDao v1) { + this.v1 = v1; + } + + @Autowired + public void setV2(@Qualifier("jvmGcDaoV2") JvmGcDao v2) { + this.v2 = v2; + } + + @Override + public JvmGcDao getObject() throws Exception { + return super.getDao(); + } + + @Override + public Class getObjectType() { + return JvmGcDao.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + JvmGcDao getCompatibilityDao(JvmGcDao v1, JvmGcDao v2) { + return new HbaseAgentStatDualReadDao.JvmGcDualReadDao(v2, v1); + } + } + + @Repository("jvmGcDetailedDaoFactory") + public static class JvmGcDetailedDaoFactory extends AgentStatDaoFactory implements FactoryBean { + + @Autowired + public void setV1(@Qualifier("jvmGcDetailedDaoV1") JvmGcDetailedDao v1) { + this.v1 = v1; + } + + @Autowired + public void setV2(@Qualifier("jvmGcDetailedDaoV2") JvmGcDetailedDao v2) { + this.v2 = v2; + } + + @Override + public JvmGcDetailedDao getObject() throws Exception { + return super.getDao(); + } + + @Override + public Class getObjectType() { + return JvmGcDetailedDao.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + JvmGcDetailedDao getCompatibilityDao(JvmGcDetailedDao v1, JvmGcDetailedDao v2) { + return new HbaseAgentStatDualReadDao.JvmGcDetailedDualReadDao(v2, v1); + } + } + + @Repository("cpuLoadDaoFactory") + public static class CpuLoadDaoFactory extends AgentStatDaoFactory implements FactoryBean { + + @Autowired + public void setV1(@Qualifier("cpuLoadDaoV1") CpuLoadDao v1) { + this.v1 = v1; + } + + @Autowired + public void setV2(@Qualifier("cpuLoadDaoV2") CpuLoadDao v2) { + this.v2 = v2; + } + + @Override + public CpuLoadDao getObject() throws Exception { + return super.getDao(); + } + + @Override + public Class getObjectType() { + return CpuLoadDao.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + CpuLoadDao getCompatibilityDao(CpuLoadDao v1, CpuLoadDao v2) { + return new HbaseAgentStatDualReadDao.CpuLoadDualReadDao(v2, v1); + } + } + + @Repository("transactionDaoFactory") + public static class TransactionDaoFactory extends AgentStatDaoFactory implements FactoryBean { + + @Autowired + public void setV1(@Qualifier("transactionDaoV1") TransactionDao v1) { + this.v1 = v1; + } + + @Autowired + public void setV2(@Qualifier("transactionDaoV2") TransactionDao v2) { + this.v2 = v2; + } + + @Override + public TransactionDao getObject() throws Exception { + return super.getDao(); + } + + @Override + public Class getObjectType() { + return TransactionDao.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + TransactionDao getCompatibilityDao(TransactionDao v1, TransactionDao v2) { + return new HbaseAgentStatDualReadDao.TransactionDualReadDao(v2, v1); + } + } + + @Repository("activeTraceDaoFactory") + public static class ActiveTraceDaoFactory extends AgentStatDaoFactory implements FactoryBean { + + @Autowired + public void setV1(@Qualifier("activeTraceDaoV1") ActiveTraceDao v1) { + this.v1 = v1; + } + + @Autowired + public void setV2(@Qualifier("activeTraceDaoV2") ActiveTraceDao v2) { + this.v2 = v2; + } + + @Override + public ActiveTraceDao getObject() throws Exception { + return super.getDao(); + } + + @Override + public Class getObjectType() { + return ActiveTraceDao.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + ActiveTraceDao getCompatibilityDao(ActiveTraceDao v1, ActiveTraceDao v2) { + return new HbaseAgentStatDualReadDao.ActiveTraceDualReadDao(v2, v1); + } + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/LegacyHbaseAgentStatDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/LegacyHbaseAgentStatDao.java new file mode 100644 index 000000000..efcc28cb5 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/LegacyHbaseAgentStatDao.java @@ -0,0 +1,131 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat; + +import static com.navercorp.pinpoint.common.hbase.HBaseTables.*; + +import java.util.ArrayList; +import java.util.List; + +import com.navercorp.pinpoint.web.dao.stat.LegacyAgentStatDao; +import org.apache.hadoop.hbase.client.Scan; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; + +import com.navercorp.pinpoint.common.hbase.HBaseTables; +import com.navercorp.pinpoint.common.hbase.HbaseOperations2; +import com.navercorp.pinpoint.common.hbase.RowMapper; +import com.navercorp.pinpoint.common.util.BytesUtils; +import com.navercorp.pinpoint.common.server.util.RowKeyUtils; +import com.navercorp.pinpoint.common.util.TimeUtils; +import com.navercorp.pinpoint.web.vo.AgentStat; +import com.navercorp.pinpoint.web.vo.Range; +import com.sematext.hbase.wd.AbstractRowKeyDistributor; + +/** + * @author emeroad + * @author hyungil.jeong + */ +@Deprecated +@Repository +public class LegacyHbaseAgentStatDao implements LegacyAgentStatDao { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private HbaseOperations2 hbaseOperations2; + + @Autowired + @Qualifier("legacyAgentStatMapper") + private RowMapper> agentStatMapper; + + @Autowired + @Qualifier("agentStatRowKeyDistributor") + private AbstractRowKeyDistributor rowKeyDistributor; + + private int scanCacheSize = 256; + + public void setScanCacheSize(int scanCacheSize) { + this.scanCacheSize = scanCacheSize; + } + + @Override + public List getAgentStatList(String agentId, Range range) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (range == null) { + throw new NullPointerException("range must not be null"); + } + + if (logger.isDebugEnabled()) { + logger.debug("scanAgentStat : agentId={}, {}", agentId, range); + } + + return getAgentStatListFromRaw(agentId, range); + } + + private List getAgentStatListFromRaw(String agentId, Range range) { + Scan scan = createScan(agentId, range); + scan.addFamily(HBaseTables.AGENT_STAT_CF_STATISTICS); + + List> intermediate = hbaseOperations2.find(HBaseTables.AGENT_STAT, scan, rowKeyDistributor, agentStatMapper); + + int expectedSize = (int) (range.getRange() / 5000); // data for 5 seconds + List merged = new ArrayList<>(expectedSize); + + for (List each : intermediate) { + merged.addAll(each); + } + + return merged; + } + + /** + * make a row key based on timestamp + * FIXME there is the same duplicate code at collector's dao module + */ + private byte[] getRowKey(String agentId, long timestamp) { + if (agentId == null) { + throw new IllegalArgumentException("agentId must not null"); + } + byte[] bAgentId = BytesUtils.toBytes(agentId); + return RowKeyUtils.concatFixedByteAndLong(bAgentId, AGENT_NAME_MAX_LEN, TimeUtils.reverseTimeMillis(timestamp)); + } + + private Scan createScan(String agentId, Range range) { + Scan scan = new Scan(); + scan.setCaching(this.scanCacheSize); + + byte[] startKey = getRowKey(agentId, range.getFrom() - 1); + byte[] endKey = getRowKey(agentId, range.getTo()); + + // start key is replaced by end key because key has been reversed + scan.setStartRow(endKey); + scan.setStopRow(startKey); + + // scan.addColumn(HBaseTables.AGENT_STAT_CF_STATISTICS, HBaseTables.AGENT_STAT_CF_STATISTICS_V1); + scan.addFamily(HBaseTables.AGENT_STAT_CF_STATISTICS); + scan.setId("AgentStatScan"); + + // toString() method of Scan converts a message to json format so it is slow for the first time. + logger.debug("create scan:{}", scan); + return scan; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/SampledAgentStatDaoFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/SampledAgentStatDaoFactory.java new file mode 100644 index 000000000..0ccabe2cf --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/SampledAgentStatDaoFactory.java @@ -0,0 +1,236 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat; + +import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; +import com.navercorp.pinpoint.web.dao.hbase.stat.compatibility.HbaseSampledAgentStatDualReadDao; +import com.navercorp.pinpoint.web.dao.stat.SampledActiveTraceDao; +import com.navercorp.pinpoint.web.dao.stat.SampledCpuLoadDao; +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDao; +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDetailedDao; +import com.navercorp.pinpoint.web.dao.stat.SampledTransactionDao; +import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; +import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; +import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; +import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Repository; + +/** + * @author HyunGil Jeong + */ +abstract class SampledAgentStatDaoFactory> { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + protected D v1; + protected D v2; + + @Value("#{pinpointWebProps['web.experimental.stat.format.compatibility.version'] ?: 'v1'}") + private String mode = "v1"; + + D getDao() throws Exception { + logger.info("SampledAgentStatDao Compatibility {}", mode); + if (mode.equalsIgnoreCase("v1")) { + return v1; + } else if (mode.equalsIgnoreCase("v2")) { + return v2; + } else if (mode.equalsIgnoreCase("compatibilityMode")) { + return getCompatibilityDao(this.v1, this.v2); + } + return v1; + } + + abstract D getCompatibilityDao(D v1, D v2); + + @Repository("sampledJvmGcDaoFactory") + public static class SampledJvmGcDaoFactory extends SampledAgentStatDaoFactory implements FactoryBean { + + @Autowired + public void setV1(@Qualifier("sampledJvmGcDaoV1") SampledJvmGcDao v1) { + this.v1 = v1; + } + + @Autowired + public void setV2(@Qualifier("sampledJvmGcDaoV2") SampledJvmGcDao v2) { + this.v2 = v2; + } + + @Override + public SampledJvmGcDao getObject() throws Exception { + return super.getDao(); + } + + @Override + public Class getObjectType() { + return SampledJvmGcDao.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + SampledJvmGcDao getCompatibilityDao(SampledJvmGcDao v1, SampledJvmGcDao v2) { + return new HbaseSampledAgentStatDualReadDao.SampledJvmGcDualReadDao(v2, v1); + } + } + + @Repository("sampledJvmGcDetailedDaoFactory") + public static class SampledJvmGcDetailedDaoFactory extends SampledAgentStatDaoFactory implements FactoryBean { + + @Autowired + public void setV1(@Qualifier("sampledJvmGcDetailedDaoV1") SampledJvmGcDetailedDao v1) { + this.v1 = v1; + } + + @Autowired + public void setV2(@Qualifier("sampledJvmGcDetailedDaoV2") SampledJvmGcDetailedDao v2) { + this.v2 = v2; + } + + @Override + public SampledJvmGcDetailedDao getObject() throws Exception { + return super.getDao(); + } + + @Override + public Class getObjectType() { + return SampledJvmGcDetailedDao.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + SampledJvmGcDetailedDao getCompatibilityDao(SampledJvmGcDetailedDao v1, SampledJvmGcDetailedDao v2) { + return new HbaseSampledAgentStatDualReadDao.SampledJvmGcDetailedDualReadDao(v2, v1); + } + } + + @Repository("sampledCpuLoadDaoFactory") + public static class SampledCpuLoadDaoFactory extends SampledAgentStatDaoFactory implements FactoryBean { + + @Autowired + public void setV1(@Qualifier("sampledCpuLoadDaoV1") SampledCpuLoadDao v1) { + this.v1 = v1; + } + + @Autowired + public void setV2(@Qualifier("sampledCpuLoadDaoV2") SampledCpuLoadDao v2) { + this.v2 = v2; + } + + @Override + public SampledCpuLoadDao getObject() throws Exception { + return super.getDao(); + } + + @Override + public Class getObjectType() { + return SampledCpuLoadDao.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + SampledCpuLoadDao getCompatibilityDao(SampledCpuLoadDao v1, SampledCpuLoadDao v2) { + return new HbaseSampledAgentStatDualReadDao.SampledCpuLoadDualReadDao(v2, v1); + } + } + + @Repository("sampledTransactionDaoFactory") + public static class SampledTransactionDaoFactory extends SampledAgentStatDaoFactory implements FactoryBean { + + @Autowired + public void setV1(@Qualifier("sampledTransactionDaoV1") SampledTransactionDao v1) { + this.v1 = v1; + } + + @Autowired + public void setV2(@Qualifier("sampledTransactionDaoV2") SampledTransactionDao v2) { + this.v2 = v2; + } + + @Override + public SampledTransactionDao getObject() throws Exception { + return super.getDao(); + } + + @Override + public Class getObjectType() { + return SampledTransactionDao.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + SampledTransactionDao getCompatibilityDao(SampledTransactionDao v1, SampledTransactionDao v2) { + return new HbaseSampledAgentStatDualReadDao.SampledTransactionDualReadDao(v2, v1); + } + } + + @Repository("sampledActiveTraceDaoFactory") + public static class SampledActiveTraceDaoFactory extends SampledAgentStatDaoFactory implements FactoryBean { + + @Autowired + public void setV1(@Qualifier("sampledActiveTraceDaoV1") SampledActiveTraceDao v1) { + this.v1 = v1; + } + + @Autowired + public void setV2(@Qualifier("sampledActiveTraceDaoV2") SampledActiveTraceDao v2) { + this.v2 = v2; + } + + @Override + public SampledActiveTraceDao getObject() throws Exception { + return super.getDao(); + } + + @Override + public Class getObjectType() { + return SampledActiveTraceDao.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + SampledActiveTraceDao getCompatibilityDao(SampledActiveTraceDao v1, SampledActiveTraceDao v2) { + return new HbaseSampledAgentStatDualReadDao.SampledActiveTraceDualReadDao(v2, v1); + } + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/compatibility/HbaseAgentStatDualReadDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/compatibility/HbaseAgentStatDualReadDao.java new file mode 100644 index 000000000..428399500 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/compatibility/HbaseAgentStatDualReadDao.java @@ -0,0 +1,99 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.compatibility; + +import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; +import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; +import com.navercorp.pinpoint.web.dao.stat.ActiveTraceDao; +import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; +import com.navercorp.pinpoint.web.dao.stat.CpuLoadDao; +import com.navercorp.pinpoint.web.dao.stat.JvmGcDao; +import com.navercorp.pinpoint.web.dao.stat.JvmGcDetailedDao; +import com.navercorp.pinpoint.web.dao.stat.TransactionDao; +import com.navercorp.pinpoint.web.vo.Range; +import org.apache.commons.collections.CollectionUtils; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +public abstract class HbaseAgentStatDualReadDao implements AgentStatDao { + + private final AgentStatDao master; + private final AgentStatDao slave; + + protected HbaseAgentStatDualReadDao(AgentStatDao master, AgentStatDao slave) { + this.master = master; + this.slave = slave; + } + + @Override + public List getAgentStatList(String agentId, Range range) { + List agentStats = this.master.getAgentStatList(agentId, range); + if (CollectionUtils.isNotEmpty(agentStats)) { + return agentStats; + } else { + return this.slave.getAgentStatList(agentId, range); + } + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + boolean exists = this.master.agentStatExists(agentId, range); + if (exists) { + return true; + } else { + return this.slave.agentStatExists(agentId, range); + } + } + + public static class JvmGcDualReadDao extends HbaseAgentStatDualReadDao implements JvmGcDao { + public JvmGcDualReadDao(AgentStatDao master, AgentStatDao slave) { + super(master, slave); + } + } + + public static class JvmGcDetailedDualReadDao extends HbaseAgentStatDualReadDao implements JvmGcDetailedDao { + public JvmGcDetailedDualReadDao(AgentStatDao master, AgentStatDao slave) { + super(master, slave); + } + } + + public static class CpuLoadDualReadDao extends HbaseAgentStatDualReadDao implements CpuLoadDao { + public CpuLoadDualReadDao(AgentStatDao master, AgentStatDao slave) { + super(master, slave); + } + } + + public static class TransactionDualReadDao extends HbaseAgentStatDualReadDao implements TransactionDao { + public TransactionDualReadDao(AgentStatDao master, AgentStatDao slave) { + super(master, slave); + } + } + + public static class ActiveTraceDualReadDao extends HbaseAgentStatDualReadDao implements ActiveTraceDao { + public ActiveTraceDualReadDao(AgentStatDao master, AgentStatDao slave) { + super(master, slave); + } + } + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/compatibility/HbaseSampledAgentStatDualReadDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/compatibility/HbaseSampledAgentStatDualReadDao.java new file mode 100644 index 000000000..28719b558 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/compatibility/HbaseSampledAgentStatDualReadDao.java @@ -0,0 +1,88 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.compatibility; + +import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; +import com.navercorp.pinpoint.web.dao.stat.SampledActiveTraceDao; +import com.navercorp.pinpoint.web.dao.stat.SampledCpuLoadDao; +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDao; +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDetailedDao; +import com.navercorp.pinpoint.web.dao.stat.SampledTransactionDao; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; +import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; +import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; +import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; +import org.apache.commons.collections.CollectionUtils; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +public abstract class HbaseSampledAgentStatDualReadDao implements SampledAgentStatDao { + + private final SampledAgentStatDao master; + private final SampledAgentStatDao slave; + + protected HbaseSampledAgentStatDualReadDao(SampledAgentStatDao master, SampledAgentStatDao slave) { + this.master = master; + this.slave = slave; + } + + @Override + public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { + List sampledAgentStats = this.master.getSampledAgentStatList(agentId, timeWindow); + if (CollectionUtils.isNotEmpty(sampledAgentStats)) { + return sampledAgentStats; + } else { + return this.slave.getSampledAgentStatList(agentId, timeWindow); + } + } + + public static class SampledJvmGcDualReadDao extends HbaseSampledAgentStatDualReadDao implements SampledJvmGcDao { + public SampledJvmGcDualReadDao(SampledAgentStatDao master, SampledAgentStatDao slave) { + super(master, slave); + } + } + + public static class SampledJvmGcDetailedDualReadDao extends HbaseSampledAgentStatDualReadDao implements SampledJvmGcDetailedDao { + public SampledJvmGcDetailedDualReadDao(SampledAgentStatDao master, SampledAgentStatDao slave) { + super(master, slave); + } + } + + public static class SampledCpuLoadDualReadDao extends HbaseSampledAgentStatDualReadDao implements SampledCpuLoadDao { + public SampledCpuLoadDualReadDao(SampledAgentStatDao master, SampledAgentStatDao slave) { + super(master, slave); + } + } + + public static class SampledTransactionDualReadDao extends HbaseSampledAgentStatDualReadDao implements SampledTransactionDao { + public SampledTransactionDualReadDao(SampledAgentStatDao master, SampledAgentStatDao slave) { + super(master, slave); + } + } + + public static class SampledActiveTraceDualReadDao extends HbaseSampledAgentStatDualReadDao implements SampledActiveTraceDao { + public SampledActiveTraceDualReadDao(SampledAgentStatDao master, SampledAgentStatDao slave) { + super(master, slave); + } + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/Aggregator.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/Aggregator.java new file mode 100644 index 000000000..6705ccfb5 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/Aggregator.java @@ -0,0 +1,278 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; +import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; +import org.springframework.stereotype.Component; + +/** + * @author Jongho Moon + * @author HyunGil Jeong + */ +public interface Aggregator { + + long AGGR_SAMPLE_INTERVAL = TimeUnit.MINUTES.toMillis(10); + long RAW_SAMPLE_INTERVAL = TimeUnit.SECONDS.toMillis(5); + Comparator TIMESTAMP_COMPARATOR = new Comparator() { + + @Override + public int compare(AgentStatDataPoint o1, AgentStatDataPoint o2) { + return Long.compare(o1.getTimestamp(), o2.getTimestamp()); + } + }; + + List aggregate(List statsToAggregate, long interval); + + abstract class AbstractAggregator implements Aggregator { + + private AbstractAggregator() { + } + + public List aggregate(List statsToAggregate, long interval) { + if (statsToAggregate.isEmpty()) { + return statsToAggregate; + } + List stats = new ArrayList<>(statsToAggregate); + Collections.sort(stats, TIMESTAMP_COMPARATOR); + + List result = new ArrayList<>(); + T current = null; + for (T stat : stats) { + long normalizedTimestamp = normalizeTimestamp(interval, stat.getTimestamp()); + if (current == null) { + current = normalizeAgentStat(stat, interval, normalizedTimestamp); + } else { + if (current.getTimestamp() == normalizedTimestamp) { + current = merge(current, stat, interval); + } else { + result.add(current); + current = normalizeAgentStat(stat, interval, normalizedTimestamp); + } + } + } + result.add(current); + return result; + } + + private long normalizeTimestamp(long interval, long timestamp) { + long normalizedTimestamp = (timestamp / interval) * interval; + return normalizedTimestamp; + } + + private T normalizeAgentStat(T stat, long interval, long normalizedTimestamp) { + T result = createNormalizedAgentStat(stat, normalizedTimestamp, interval); + return result; + } + + protected final long addUnsignedLongs(long v1, long v2) { + if (v1 < 0) { + if (v2 < 0) { + return -1; + } else { + return v2; + } + } else { + if (v2 < 0) { + return v1; + } else { + return v1 + v2; + } + } + } + + protected final long maxUnsignedLongs(long v1, long v2) { + if (v1 < 0) { + return v2; + } else if (v2 < 0) { + return v1; + } + + return v1 < v2 ? v2 : v1; + } + + protected final T getLatest(T s1, T s2) { + return s1.getTimestamp() > s2.getTimestamp() ? s1 : s2; + } + + protected abstract T createNormalizedAgentStat(T src, long normalizedTimestamp, long interval); + + protected abstract T merge(T s1, T s2, long interval); + } + + @Component + class JvmGcAggregator extends AbstractAggregator { + + @Override + protected JvmGcBo createNormalizedAgentStat(JvmGcBo src, long normalizedTimestamp, long interval) { + JvmGcBo normalized = new JvmGcBo(); + normalized.setAgentId(src.getAgentId()); + normalized.setTimestamp(normalizedTimestamp); + normalized.setHeapUsed(src.getHeapUsed()); + normalized.setHeapMax(src.getHeapMax()); + normalized.setNonHeapUsed(src.getNonHeapUsed()); + normalized.setNonHeapMax(src.getNonHeapMax()); + normalized.setGcOldCount(src.getGcOldCount()); + normalized.setGcOldTime(src.getGcOldTime()); + return normalized; + } + + @Override + protected JvmGcBo merge(JvmGcBo s1, JvmGcBo s2, long interval) { + JvmGcBo latest = getLatest(s1, s2); + JvmGcBo merged = new JvmGcBo(); + merged.setAgentId(latest.getAgentId()); + merged.setTimestamp(latest.getTimestamp()); + merged.setHeapUsed(latest.getHeapUsed()); + merged.setHeapMax(maxUnsignedLongs(s1.getHeapMax(), s2.getHeapMax())); + merged.setNonHeapUsed(latest.getNonHeapUsed()); + merged.setNonHeapMax(maxUnsignedLongs(s1.getNonHeapMax(), s2.getNonHeapMax())); + merged.setGcOldCount(latest.getGcOldCount()); + merged.setGcOldTime(latest.getGcOldTime()); + return merged; + } + } + + @Component + class JvmGcDetailedAggregator extends AbstractAggregator { + + @Override + protected JvmGcDetailedBo createNormalizedAgentStat(JvmGcDetailedBo src, long normalizedTimestamp, long interval) { + JvmGcDetailedBo normalized = new JvmGcDetailedBo(); + normalized.setAgentId(src.getAgentId()); + normalized.setTimestamp(normalizedTimestamp); + normalized.setGcNewCount(src.getGcNewCount()); + normalized.setGcNewTime(src.getGcNewTime()); + normalized.setCodeCacheUsed(src.getCodeCacheUsed()); + normalized.setNewGenUsed(src.getNewGenUsed()); + normalized.setOldGenUsed(src.getOldGenUsed()); + normalized.setSurvivorSpaceUsed(src.getSurvivorSpaceUsed()); + normalized.setPermGenUsed(src.getPermGenUsed()); + normalized.setMetaspaceUsed(src.getMetaspaceUsed()); + return normalized; + } + + @Override + protected JvmGcDetailedBo merge(JvmGcDetailedBo s1, JvmGcDetailedBo s2, long interval) { + JvmGcDetailedBo latest = getLatest(s1, s2); + JvmGcDetailedBo merged = new JvmGcDetailedBo(); + merged.setAgentId(latest.getAgentId()); + merged.setTimestamp(latest.getTimestamp()); + merged.setGcNewCount(latest.getGcNewCount()); + merged.setGcNewTime(latest.getGcNewTime()); + merged.setCodeCacheUsed(latest.getCodeCacheUsed()); + merged.setNewGenUsed(latest.getNewGenUsed()); + merged.setOldGenUsed(latest.getOldGenUsed()); + merged.setSurvivorSpaceUsed(latest.getSurvivorSpaceUsed()); + merged.setPermGenUsed(latest.getPermGenUsed()); + merged.setMetaspaceUsed(latest.getMetaspaceUsed()); + return merged; + } + } + + @Component + class CpuLoadAggregator extends AbstractAggregator { + + @Override + protected CpuLoadBo createNormalizedAgentStat(CpuLoadBo src, long normalizedTimestamp, long interval) { + CpuLoadBo normalized = new CpuLoadBo(); + normalized.setAgentId(src.getAgentId()); + normalized.setTimestamp(normalizedTimestamp); + normalized.setJvmCpuLoad(src.getJvmCpuLoad()); + normalized.setSystemCpuLoad(src.getSystemCpuLoad()); + return normalized; + } + + @Override + protected CpuLoadBo merge(CpuLoadBo s1, CpuLoadBo s2, long interval) { + CpuLoadBo latest = getLatest(s1, s2); + CpuLoadBo merged = new CpuLoadBo(); + merged.setAgentId(latest.getAgentId()); + merged.setTimestamp(latest.getTimestamp()); + merged.setJvmCpuLoad(latest.getJvmCpuLoad()); + merged.setSystemCpuLoad(latest.getSystemCpuLoad()); + return merged; + } + } + + @Component + class TransactionAggregator extends AbstractAggregator { + + @Override + protected TransactionBo createNormalizedAgentStat(TransactionBo src, long normalizedTimestamp, long interval) { + TransactionBo normalized = new TransactionBo(); + normalized.setAgentId(src.getAgentId()); + normalized.setTimestamp(normalizedTimestamp); + normalized.setCollectInterval(interval); + normalized.setSampledNewCount(src.getSampledNewCount()); + normalized.setSampledContinuationCount(src.getSampledContinuationCount()); + normalized.setUnsampledNewCount(src.getUnsampledNewCount()); + normalized.setUnsampledContinuationCount(src.getUnsampledContinuationCount()); + return normalized; + } + + @Override + protected TransactionBo merge(TransactionBo s1, TransactionBo s2, long interval) { + TransactionBo latest = getLatest(s1, s2); + TransactionBo merged = new TransactionBo(); + merged.setAgentId(latest.getAgentId()); + merged.setTimestamp(latest.getTimestamp()); + merged.setSampledNewCount(addUnsignedLongs(s1.getSampledNewCount(), s2.getSampledNewCount())); + merged.setSampledContinuationCount(addUnsignedLongs(s1.getSampledContinuationCount(), s2.getSampledContinuationCount())); + merged.setUnsampledNewCount(addUnsignedLongs(s1.getUnsampledNewCount(), s2.getUnsampledNewCount())); + merged.setUnsampledContinuationCount(addUnsignedLongs(s1.getUnsampledContinuationCount(), s2.getUnsampledContinuationCount())); + return merged; + } + } + + @Component + class ActiveTraceAggregator extends AbstractAggregator { + + @Override + protected ActiveTraceBo createNormalizedAgentStat(ActiveTraceBo src, long normalizedTimestamp, long interval) { + ActiveTraceBo normalized = new ActiveTraceBo(); + normalized.setAgentId(src.getAgentId()); + normalized.setTimestamp(normalizedTimestamp); + normalized.setVersion(src.getVersion()); + normalized.setHistogramSchemaType(src.getHistogramSchemaType()); + normalized.setActiveTraceCounts(src.getActiveTraceCounts()); + return normalized; + } + + @Override + protected ActiveTraceBo merge(ActiveTraceBo s1, ActiveTraceBo s2, long interval) { + ActiveTraceBo latest = getLatest(s1, s2); + ActiveTraceBo merged = new ActiveTraceBo(); + merged.setAgentId(latest.getAgentId()); + merged.setTimestamp(latest.getTimestamp()); + merged.setVersion(latest.getVersion()); + merged.setHistogramSchemaType(latest.getHistogramSchemaType()); + merged.setActiveTraceCounts(latest.getActiveTraceCounts()); + return merged; + } + } +} \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseActiveTraceDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseActiveTraceDao.java new file mode 100644 index 000000000..4738a1d0b --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseActiveTraceDao.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; + +import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; +import com.navercorp.pinpoint.web.dao.stat.ActiveTraceDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV1; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("activeTraceDaoV1") +public class HbaseActiveTraceDao implements ActiveTraceDao { + + @Autowired + private AgentStatMapperV1.ActiveTraceMapper mapper; + + @Autowired + private Aggregator.ActiveTraceAggregator aggregator; + + @Autowired + private HbaseAgentStatDaoOperations operations; + + @Override + public List getAgentStatList(String agentId, Range range) { + return operations.getAgentStatList(mapper, aggregator, agentId, range); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + return operations.agentStatExists(mapper, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentStatDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseAgentStatDaoOperations.java similarity index 59% rename from web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentStatDao.java rename to web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseAgentStatDaoOperations.java index 3f2a99b88..1f1a93806 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentStatDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseAgentStatDaoOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2016 Naver Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,19 @@ * limitations under the License. */ -package com.navercorp.pinpoint.web.dao.hbase; +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; import static com.navercorp.pinpoint.common.hbase.HBaseTables.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.TimeUnit; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV1; +import com.navercorp.pinpoint.web.mapper.stat.SampledAgentStatResultExtractor; +import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; @@ -29,7 +34,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Repository; import com.navercorp.pinpoint.common.hbase.HBaseTables; import com.navercorp.pinpoint.common.hbase.HbaseOperations2; @@ -38,39 +42,33 @@ import com.navercorp.pinpoint.common.hbase.RowMapper; import com.navercorp.pinpoint.common.util.BytesUtils; import com.navercorp.pinpoint.common.server.util.RowKeyUtils; import com.navercorp.pinpoint.common.util.TimeUtils; -import com.navercorp.pinpoint.web.dao.AgentStatDao; -import com.navercorp.pinpoint.web.util.AgentStats; -import com.navercorp.pinpoint.web.vo.AgentStat; import com.navercorp.pinpoint.web.vo.Range; import com.sematext.hbase.wd.AbstractRowKeyDistributor; +import org.springframework.stereotype.Component; /** * @author emeroad * @author hyungil.jeong */ -@Repository -public class HbaseAgentStatDao implements AgentStatDao { +@Component +public class HbaseAgentStatDaoOperations { + private static final long USE_AGGREGATED_THRESHOLD = TimeUnit.HOURS.toMillis(24); private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private HbaseOperations2 hbaseOperations2; - @Autowired - @Qualifier("agentStatMapper") - private RowMapper> agentStatMapper; - @Autowired @Qualifier("agentStatRowKeyDistributor") private AbstractRowKeyDistributor rowKeyDistributor; private int scanCacheSize = 256; - public void setScanCacheSize(int scanCacheSize) { + void setScanCacheSize(int scanCacheSize) { this.scanCacheSize = scanCacheSize; } - @Override - public List getAgentStatList(String agentId, Range range) { + List getAgentStatList(AgentStatMapperV1 mapper, Aggregator aggregator, String agentId, Range range) { if (agentId == null) { throw new NullPointerException("agentId must not be null"); } @@ -81,88 +79,78 @@ public class HbaseAgentStatDao implements AgentStatDao { if (logger.isDebugEnabled()) { logger.debug("scanAgentStat : agentId={}, {}", agentId, range); } - - return getAgentStatListFromRaw(agentId, range); - } - - private List getAgentStatListFromRaw(String agentId, Range range) { - Scan scan = createScan(agentId, range); - scan.addFamily(HBaseTables.AGENT_STAT_CF_STATISTICS); - List> intermediate = hbaseOperations2.find(HBaseTables.AGENT_STAT, scan, rowKeyDistributor, agentStatMapper); +// boolean useAggregated = range.getRange() > USE_AGGREGATED_THRESHOLD; +// if (useAggregated) { +// return getAggregatedAgentStatList(mapper, aggregator, agentId, range); +// } else { + return getAgentStatListFromRaw(mapper, agentId, range); +// } + } + + private List getAgentStatListFromRaw(AgentStatMapperV1 mapper, String agentId, Range range) { + Scan scan = createScan(agentId, range); + + List> intermediate = hbaseOperations2.find(HBaseTables.AGENT_STAT, scan, rowKeyDistributor, mapper); int expectedSize = (int) (range.getRange() / 5000); // data for 5 seconds - List merged = new ArrayList<>(expectedSize); + List merged = new ArrayList<>(expectedSize); - for (List each : intermediate) { + for (List each : intermediate) { merged.addAll(each); } return merged; } - - public List getAggregatedAgentStatList(String agentId, Range range) { - if (agentId == null) { - throw new NullPointerException("agentId must not be null"); - } - if (range == null) { - throw new NullPointerException("range must not be null"); - } - - if (logger.isDebugEnabled()) { - logger.debug("scanAgentStat : agentId={}, {}", agentId, range); - } + private List getAggregatedAgentStatList(AgentStatMapperV1 mapper, Aggregator aggregator, String agentId, Range range) { Scan scan = createScan(agentId, range); - scan.addFamily(HBaseTables.AGENT_STAT_CF_STATISTICS); - - List> intermediate = hbaseOperations2.find(HBaseTables.AGENT_STAT_AGGR, scan, rowKeyDistributor, agentStatMapper); - - List merged = new ArrayList<>(); - for (List each : intermediate) { + List> intermediate = hbaseOperations2.find(HBaseTables.AGENT_STAT_AGGR, scan, rowKeyDistributor, mapper); + + List merged = new ArrayList<>(); + + for (List each : intermediate) { merged.addAll(each); } - - Collections.sort(merged, AgentStats.TIMESTAMP_COMPARATOR); - - + + Collections.sort(merged, Aggregator.TIMESTAMP_COMPARATOR); + List missingRanges = new ArrayList<>(); long last = range.getFrom(); - - for (AgentStat stat : merged) { - if (last + AgentStat.AGGR_SAMPLE_INTERVAL * 2 < stat.getTimestamp()) { - Range r = new Range(last, stat.getTimestamp() - stat.getCollectInterval()); + + for (T stat : merged) { + if (last + Aggregator.AGGR_SAMPLE_INTERVAL * 2 < stat.getTimestamp()) { + Range r = new Range(last, stat.getTimestamp() - Aggregator.AGGR_SAMPLE_INTERVAL); missingRanges.add(r); } - + last = stat.getTimestamp(); } - - if (last + AgentStat.AGGR_SAMPLE_INTERVAL * 2 < range.getTo()) { + + if (last + Aggregator.AGGR_SAMPLE_INTERVAL * 2 < range.getTo()) { Range r = new Range(last, range.getTo()); missingRanges.add(r); } - + for (Range r : missingRanges) { logger.debug("AgentStatAggr doesn't have range: " + r.prettyToString() + " of " + agentId); - List list = getAgentStatListFromRaw(agentId, r); - + List list = getAgentStatListFromRaw(mapper, agentId, r); + if (list.isEmpty()) { logger.debug("AgentStat also doesn't have range: " + r.prettyToString() + " of " + agentId); continue; } - - List aggregated = AgentStats.aggregate(list, AgentStat.AGGR_SAMPLE_INTERVAL); + + List aggregated = aggregator.aggregate(list, Aggregator.AGGR_SAMPLE_INTERVAL); merged.addAll(aggregated); } return merged; } - - @Override - public boolean agentStatExists(String agentId, Range range) { + + boolean agentStatExists(AgentStatMapperV1 mapper, String agentId, Range range) { if (agentId == null) { throw new NullPointerException("agentId must not be null"); } @@ -176,16 +164,30 @@ public class HbaseAgentStatDao implements AgentStatDao { Scan scan = createScan(agentId, range); scan.setCaching(1); - scan.addFamily(HBaseTables.AGENT_STAT_CF_STATISTICS); - return hbaseOperations2.find(HBaseTables.AGENT_STAT, scan, rowKeyDistributor, new AgentStatDataExistsResultsExtractor(this.agentStatMapper)); + AgentStatDataExistsResultsExtractor extractor = new AgentStatDataExistsResultsExtractor(mapper); + return hbaseOperations2.find(HBaseTables.AGENT_STAT, scan, rowKeyDistributor, extractor); } - private class AgentStatDataExistsResultsExtractor implements ResultsExtractor { + List getSampledAgentStatList(SampledAgentStatResultExtractor resultExtractor, String agentId, Range range) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (range == null) { + throw new NullPointerException("range must not be null"); + } + if (resultExtractor == null) { + throw new NullPointerException("sampledResultExtractor must not be null"); + } + Scan scan = createScan(agentId, range); + return hbaseOperations2.find(HBaseTables.AGENT_STAT, scan, rowKeyDistributor, resultExtractor); + } - private final RowMapper> agentStatMapper; + private class AgentStatDataExistsResultsExtractor implements ResultsExtractor { - private AgentStatDataExistsResultsExtractor(RowMapper> agentStatMapper) { + private final RowMapper> agentStatMapper; + + private AgentStatDataExistsResultsExtractor(AgentStatMapperV1 agentStatMapper) { this.agentStatMapper = agentStatMapper; } @@ -222,7 +224,7 @@ public class HbaseAgentStatDao implements AgentStatDao { Scan scan = new Scan(); scan.setCaching(this.scanCacheSize); - byte[] startKey = getRowKey(agentId, range.getFrom()); + byte[] startKey = getRowKey(agentId, range.getFrom() - 1); byte[] endKey = getRowKey(agentId, range.getTo()); // start key is replaced by end key because key has been reversed @@ -237,37 +239,4 @@ public class HbaseAgentStatDao implements AgentStatDao { logger.debug("create scan:{}", scan); return scan; } - - // public List scanAgentStatList(String agentId, long start, long end, final int limit) { - // if (logger.isDebugEnabled()) { - // logger.debug("scanAgentStatList"); - // } - // Scan scan = createScan(agentId, start, end); - // - // List list = hbaseOperations2.find(HBaseTables.AGENT_STAT, scan, rowKeyDistributor, new ResultsExtractor>() { - // @Override - // public List extractData(ResultScanner results) throws Exception { - // TDeserializer deserializer = new TDeserializer(); - // List list = new ArrayList(); - // for (Result result : results) { - // if (result == null) { - // continue; - // } - // - // if (list.size() >= limit) { - // break; - // } - // - // for (KeyValue kv : result.raw()) { - // AgentStat agentStat = new AgentStat(); - // deserializer.deserialize(agentStat, kv.getBuffer()); - // list.add(agentStat); - // } - // } - // return list; - // } - // }); - // return list; - // } - -} +} \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseCpuLoadDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseCpuLoadDao.java new file mode 100644 index 000000000..4cffbf34d --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseCpuLoadDao.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; + +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.web.dao.stat.CpuLoadDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV1; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("cpuLoadDaoV1") +public class HbaseCpuLoadDao implements CpuLoadDao { + + @Autowired + private AgentStatMapperV1.CpuLoadMapper mapper; + + @Autowired + private Aggregator.CpuLoadAggregator aggregator; + + @Autowired + private HbaseAgentStatDaoOperations operations; + + @Override + public List getAgentStatList(String agentId, Range range) { + return operations.getAgentStatList(mapper, aggregator, agentId, range); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + return operations.agentStatExists(mapper, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseJvmGcDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseJvmGcDao.java new file mode 100644 index 000000000..5fa5b5479 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseJvmGcDao.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; + +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; +import com.navercorp.pinpoint.web.dao.stat.JvmGcDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV1; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("jvmGcDaoV1") +public class HbaseJvmGcDao implements JvmGcDao { + + @Autowired + private AgentStatMapperV1.JvmGcMapper mapper; + + @Autowired + private Aggregator.JvmGcAggregator aggregator; + + @Autowired + private HbaseAgentStatDaoOperations operations; + + @Override + public List getAgentStatList(String agentId, Range range) { + return this.operations.getAgentStatList(mapper, aggregator, agentId, range); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + return operations.agentStatExists(mapper, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseJvmGcDetailedDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseJvmGcDetailedDao.java new file mode 100644 index 000000000..c8dc05d8b --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseJvmGcDetailedDao.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; + +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; +import com.navercorp.pinpoint.web.dao.stat.JvmGcDetailedDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV1; +import com.navercorp.pinpoint.web.vo.Range; +import org.apache.thrift.TException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * @author HyunGil Jeong + */ +@Repository("jvmGcDetailedDaoV1") +public class HbaseJvmGcDetailedDao implements JvmGcDetailedDao { + + @Override + public List getAgentStatList(String agentId, Range range) { + return Collections.emptyList(); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + return false; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledActiveTraceDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledActiveTraceDao.java new file mode 100644 index 000000000..1ed4baa4d --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledActiveTraceDao.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; + +import com.navercorp.pinpoint.web.dao.stat.SampledActiveTraceDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV1; +import com.navercorp.pinpoint.web.mapper.stat.SampledActiveTraceResultExtractor; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("sampledActiveTraceDaoV1") +public class HbaseSampledActiveTraceDao implements SampledActiveTraceDao { + + @Autowired + private AgentStatMapperV1.ActiveTraceMapper mapper; + + @Autowired + private Aggregator.ActiveTraceAggregator aggregator; + + @Autowired + private HbaseAgentStatDaoOperations operations; + + @Override + public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { + long scanFrom = timeWindow.getWindowRange().getFrom(); + long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); + Range range = new Range(scanFrom, scanTo); + SampledActiveTraceResultExtractor resultExtractor = new SampledActiveTraceResultExtractor(timeWindow, mapper); + return operations.getSampledAgentStatList(resultExtractor, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledCpuLoadDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledCpuLoadDao.java new file mode 100644 index 000000000..b63059a8e --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledCpuLoadDao.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; + +import com.navercorp.pinpoint.web.dao.stat.SampledCpuLoadDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV1; +import com.navercorp.pinpoint.web.mapper.stat.SampledCpuLoadResultExtractor; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("sampledCpuLoadDaoV1") +public class HbaseSampledCpuLoadDao implements SampledCpuLoadDao { + + @Autowired + private AgentStatMapperV1.CpuLoadMapper mapper; + + @Autowired + private Aggregator.CpuLoadAggregator aggregator; + + @Autowired + private HbaseAgentStatDaoOperations operations; + + @Override + public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { + long scanFrom = timeWindow.getWindowRange().getFrom(); + long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); + Range range = new Range(scanFrom, scanTo); + SampledCpuLoadResultExtractor resultExtractor = new SampledCpuLoadResultExtractor(timeWindow, mapper); + return operations.getSampledAgentStatList(resultExtractor, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledJvmGcDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledJvmGcDao.java new file mode 100644 index 000000000..04e772ae5 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledJvmGcDao.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; + +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV1; +import com.navercorp.pinpoint.web.mapper.stat.SampledJvmGcResultExtractor; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("sampledJvmGcDaoV1") +public class HbaseSampledJvmGcDao implements SampledJvmGcDao { + + @Autowired + private AgentStatMapperV1.JvmGcMapper mapper; + + @Autowired + private Aggregator.JvmGcAggregator aggregator; + + @Autowired + private HbaseAgentStatDaoOperations operations; + + @Override + public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { + long scanFrom = timeWindow.getWindowRange().getFrom(); + long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); + Range range = new Range(scanFrom, scanTo); + SampledJvmGcResultExtractor resultExtractor = new SampledJvmGcResultExtractor(timeWindow, mapper); + return operations.getSampledAgentStatList(resultExtractor, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledJvmGcDetailedDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledJvmGcDetailedDao.java new file mode 100644 index 000000000..eb1873c90 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledJvmGcDetailedDao.java @@ -0,0 +1,37 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; + +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDetailedDao; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; +import org.springframework.stereotype.Repository; + +import java.util.Collections; +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("sampledJvmGcDetailedDaoV1") +public class HbaseSampledJvmGcDetailedDao implements SampledJvmGcDetailedDao { + + @Override + public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { + return Collections.emptyList(); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledTransactionDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledTransactionDao.java new file mode 100644 index 000000000..60bc62872 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseSampledTransactionDao.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; + +import com.navercorp.pinpoint.web.dao.stat.SampledTransactionDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV1; +import com.navercorp.pinpoint.web.mapper.stat.SampledTransactionResultExtractor; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("sampledTransactionDaoV1") +public class HbaseSampledTransactionDao implements SampledTransactionDao { + + @Autowired + private AgentStatMapperV1.TransactionMapper mapper; + + @Autowired + private Aggregator.TransactionAggregator aggregator; + + @Autowired + private HbaseAgentStatDaoOperations operations; + + @Override + public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { + long scanFrom = timeWindow.getWindowRange().getFrom(); + long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); + Range range = new Range(scanFrom, scanTo); + SampledTransactionResultExtractor resultExtractor = new SampledTransactionResultExtractor(timeWindow, mapper); + return operations.getSampledAgentStatList(resultExtractor, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseTransactionDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseTransactionDao.java new file mode 100644 index 000000000..bf0460c51 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v1/HbaseTransactionDao.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v1; + +import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; +import com.navercorp.pinpoint.web.dao.stat.TransactionDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV1; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("transactionDaoV1") +public class HbaseTransactionDao implements TransactionDao { + + @Autowired + private AgentStatMapperV1.TransactionMapper mapper; + + @Autowired + private Aggregator.TransactionAggregator aggregator; + + @Autowired + private HbaseAgentStatDaoOperations operations; + + @Override + public List getAgentStatList(String agentId, Range range) { + return operations.getAgentStatList(mapper, aggregator, agentId, range); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + return operations.agentStatExists(mapper, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseActiveTraceDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseActiveTraceDaoV2.java new file mode 100644 index 000000000..7dffcd431 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseActiveTraceDaoV2.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v2; + +import com.navercorp.pinpoint.common.server.bo.codec.stat.ActiveTraceDecoder; +import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.web.dao.stat.ActiveTraceDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("activeTraceDaoV2") +public class HbaseActiveTraceDaoV2 implements ActiveTraceDao { + + @Autowired + private ActiveTraceDecoder activeTraceDecoder; + + @Autowired + private HbaseAgentStatDaoOperationsV2 operations; + + @Override + public List getAgentStatList(String agentId, Range range) { + AgentStatMapperV2 mapper = operations.createRowMapper(activeTraceDecoder, range); + return operations.getAgentStatList(AgentStatType.ACTIVE_TRACE, mapper, agentId, range); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + AgentStatMapperV2 mapper = operations.createRowMapper(activeTraceDecoder, range); + return operations.agentStatExists(AgentStatType.ACTIVE_TRACE, mapper, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseAgentStatDaoOperationsV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseAgentStatDaoOperationsV2.java new file mode 100644 index 000000000..333daed9f --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseAgentStatDaoOperationsV2.java @@ -0,0 +1,140 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v2; + +import com.navercorp.pinpoint.common.hbase.HBaseTables; +import com.navercorp.pinpoint.common.hbase.HbaseOperations2; +import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDecoder; +import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatHbaseOperationFactory; +import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.web.mapper.RangeTimestampFilter; +import com.navercorp.pinpoint.web.mapper.TimestampFilter; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; +import com.navercorp.pinpoint.web.mapper.stat.SampledAgentStatResultExtractor; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; +import org.apache.hadoop.hbase.client.Scan; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Component +public class HbaseAgentStatDaoOperationsV2 { + + private static final int AGENT_STAT_VER2_NUM_PARTITIONS = 32; + private static final int MAX_SCAN_CACHE_SIZE = 256; + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private HbaseOperations2 hbaseOperations2; + + @Autowired + private AgentStatHbaseOperationFactory operationFactory; + + List getAgentStatList(AgentStatType agentStatType, AgentStatMapperV2 mapper, String agentId, Range range) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (range == null) { + throw new NullPointerException("range must not be null"); + } + + Scan scan = this.createScan(agentStatType, agentId, range); + + List> intermediate = hbaseOperations2.findParallel(HBaseTables.AGENT_STAT_VER2, scan, this.operationFactory.getRowKeyDistributor(), mapper, AGENT_STAT_VER2_NUM_PARTITIONS); + int expectedSize = (int) (range.getRange() / HBaseTables.AGENT_STAT_TIMESPAN_MS); + List merged = new ArrayList<>(expectedSize); + for (List each : intermediate) { + merged.addAll(each); + } + return merged; + } + + boolean agentStatExists(AgentStatType agentStatType, AgentStatMapperV2 mapper, String agentId, Range range) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (range == null) { + throw new NullPointerException("range must not be null"); + } + + if (logger.isDebugEnabled()) { + logger.debug("checking for stat data existence : agentId={}, {}", agentId, range); + } + + int resultLimit = 1; + Scan scan = this.createScan(agentStatType, agentId, range, resultLimit); + + List> result = hbaseOperations2.findParallel(HBaseTables.AGENT_STAT_VER2, scan, this.operationFactory.getRowKeyDistributor(), resultLimit, mapper, AGENT_STAT_VER2_NUM_PARTITIONS); + if (result.isEmpty()) { + return false; + } else { + return true; + } + } + + List getSampledAgentStatList(AgentStatType agentStatType, SampledAgentStatResultExtractor resultExtractor, String agentId, Range range) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (range == null) { + throw new NullPointerException("range must not be null"); + } + if (resultExtractor == null) { + throw new NullPointerException("resultExtractor must not be null"); + } + Scan scan = this.createScan(agentStatType, agentId, range); + return hbaseOperations2.findParallel(HBaseTables.AGENT_STAT_VER2, scan, this.operationFactory.getRowKeyDistributor(), resultExtractor, AGENT_STAT_VER2_NUM_PARTITIONS); + } + + AgentStatMapperV2 createRowMapper(AgentStatDecoder decoder, Range range) { + TimestampFilter filter = new RangeTimestampFilter(range); + return new AgentStatMapperV2<>(this.operationFactory, decoder, filter); + } + + private Scan createScan(AgentStatType agentStatType, String agentId, Range range) { + long scanRange = range.getTo() - range.getFrom(); + long expectedNumRows = ((scanRange - 1) / HBaseTables.AGENT_STAT_TIMESPAN_MS) + 1; + if (range.getFrom() != AgentStatUtils.getBaseTimestamp(range.getFrom())) { + expectedNumRows++; + } + if (expectedNumRows > MAX_SCAN_CACHE_SIZE) { + return this.createScan(agentStatType, agentId, range, MAX_SCAN_CACHE_SIZE); + } else { + // expectedNumRows guaranteed to be within integer range at this point + return this.createScan(agentStatType, agentId, range, (int) expectedNumRows); + } + } + + private Scan createScan(AgentStatType agentStatType, String agentId, Range range, int scanCacheSize) { + Scan scan = this.operationFactory.createScan(agentId, agentStatType, range.getFrom(), range.getTo()); + scan.setCaching(scanCacheSize); + scan.setId("AgentStat_" + agentStatType); + scan.addFamily(HBaseTables.AGENT_STAT_CF_STATISTICS); + return scan; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseCpuLoadDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseCpuLoadDaoV2.java new file mode 100644 index 000000000..77c206f8b --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseCpuLoadDaoV2.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v2; + +import com.navercorp.pinpoint.common.server.bo.codec.stat.CpuLoadDecoder; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.web.dao.stat.CpuLoadDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("cpuLoadDaoV2") +public class HbaseCpuLoadDaoV2 implements CpuLoadDao { + + @Autowired + private CpuLoadDecoder cpuLoadDecoder; + + @Autowired + private HbaseAgentStatDaoOperationsV2 operations; + + @Override + public List getAgentStatList(String agentId, Range range) { + AgentStatMapperV2 mapper = operations.createRowMapper(cpuLoadDecoder, range); + return operations.getAgentStatList(AgentStatType.CPU_LOAD, mapper, agentId, range); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + AgentStatMapperV2 mapper = operations.createRowMapper(cpuLoadDecoder, range); + return operations.agentStatExists(AgentStatType.CPU_LOAD, mapper, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseJvmGcDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseJvmGcDaoV2.java new file mode 100644 index 000000000..331d7a61a --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseJvmGcDaoV2.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v2; + +import com.navercorp.pinpoint.common.server.bo.codec.stat.JvmGcDecoder; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; +import com.navercorp.pinpoint.web.dao.stat.JvmGcDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("jvmGcDaoV2") +public class HbaseJvmGcDaoV2 implements JvmGcDao { + + @Autowired + private JvmGcDecoder jvmGcDecoder; + + @Autowired + private HbaseAgentStatDaoOperationsV2 operations; + + @Override + public List getAgentStatList(String agentId, Range range) { + AgentStatMapperV2 mapper = operations.createRowMapper(jvmGcDecoder, range); + return operations.getAgentStatList(AgentStatType.JVM_GC, mapper, agentId, range); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + AgentStatMapperV2 mapper = operations.createRowMapper(jvmGcDecoder, range); + return operations.agentStatExists(AgentStatType.JVM_GC, mapper, agentId, range); + } +} \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseJvmGcDetailedDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseJvmGcDetailedDaoV2.java new file mode 100644 index 000000000..89578ce29 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseJvmGcDetailedDaoV2.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v2; + +import com.navercorp.pinpoint.common.server.bo.codec.stat.JvmGcDetailedDecoder; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; +import com.navercorp.pinpoint.web.dao.stat.JvmGcDetailedDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("jvmGcDetailedDaoV2") +public class HbaseJvmGcDetailedDaoV2 implements JvmGcDetailedDao { + + @Autowired + private JvmGcDetailedDecoder jvmGcDetailedDecoder; + + @Autowired + private HbaseAgentStatDaoOperationsV2 operations; + + @Override + public List getAgentStatList(String agentId, Range range) { + AgentStatMapperV2 mapper = operations.createRowMapper(jvmGcDetailedDecoder, range); + return operations.getAgentStatList(AgentStatType.JVM_GC_DETAILED, mapper, agentId, range); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + AgentStatMapperV2 mapper = operations.createRowMapper(jvmGcDetailedDecoder, range); + return operations.agentStatExists(AgentStatType.JVM_GC_DETAILED, mapper, agentId, range); + } +} \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledActiveTraceDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledActiveTraceDaoV2.java new file mode 100644 index 000000000..5c275ff2c --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledActiveTraceDaoV2.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v2; + +import com.navercorp.pinpoint.common.server.bo.codec.stat.ActiveTraceDecoder; +import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.web.dao.stat.SampledActiveTraceDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; +import com.navercorp.pinpoint.web.mapper.stat.SampledActiveTraceResultExtractor; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("sampledActiveTraceDaoV2") +public class HbaseSampledActiveTraceDaoV2 implements SampledActiveTraceDao { + + @Autowired + private ActiveTraceDecoder activeTraceDecoder; + + @Autowired + private HbaseAgentStatDaoOperationsV2 operations; + + @Override + public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { + long scanFrom = timeWindow.getWindowRange().getFrom(); + long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); + Range range = new Range(scanFrom, scanTo); + AgentStatMapperV2 mapper = operations.createRowMapper(activeTraceDecoder, range); + SampledActiveTraceResultExtractor resultExtractor = new SampledActiveTraceResultExtractor(timeWindow, mapper); + return operations.getSampledAgentStatList(AgentStatType.ACTIVE_TRACE, resultExtractor, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledCpuLoadDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledCpuLoadDaoV2.java new file mode 100644 index 000000000..a75667e79 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledCpuLoadDaoV2.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v2; + +import com.navercorp.pinpoint.common.server.bo.codec.stat.CpuLoadDecoder; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.web.dao.stat.SampledCpuLoadDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; +import com.navercorp.pinpoint.web.mapper.stat.SampledCpuLoadResultExtractor; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("sampledCpuLoadDaoV2") +public class HbaseSampledCpuLoadDaoV2 implements SampledCpuLoadDao { + + @Autowired + private CpuLoadDecoder cpuLoadDecoder; + + @Autowired + private HbaseAgentStatDaoOperationsV2 operations; + + @Override + public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { + long scanFrom = timeWindow.getWindowRange().getFrom(); + long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); + Range range = new Range(scanFrom, scanTo); + AgentStatMapperV2 mapper = operations.createRowMapper(cpuLoadDecoder, range); + SampledCpuLoadResultExtractor resultExtractor = new SampledCpuLoadResultExtractor(timeWindow, mapper); + return operations.getSampledAgentStatList(AgentStatType.CPU_LOAD, resultExtractor, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledJvmGcDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledJvmGcDaoV2.java new file mode 100644 index 000000000..c1481d4c1 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledJvmGcDaoV2.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v2; + +import com.navercorp.pinpoint.common.server.bo.codec.stat.JvmGcDecoder; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; +import com.navercorp.pinpoint.web.mapper.stat.SampledJvmGcResultExtractor; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("sampledJvmGcDaoV2") +public class HbaseSampledJvmGcDaoV2 implements SampledJvmGcDao { + + @Autowired + private JvmGcDecoder jvmGcDecoder; + + @Autowired + private HbaseAgentStatDaoOperationsV2 operations; + + @Override + public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { + long scanFrom = timeWindow.getWindowRange().getFrom(); + long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); + Range range = new Range(scanFrom, scanTo); + AgentStatMapperV2 mapper = operations.createRowMapper(jvmGcDecoder, range); + SampledJvmGcResultExtractor resultExtractor = new SampledJvmGcResultExtractor(timeWindow, mapper); + return operations.getSampledAgentStatList(AgentStatType.JVM_GC, resultExtractor, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledJvmGcDetailedDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledJvmGcDetailedDaoV2.java new file mode 100644 index 000000000..5f8abe039 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledJvmGcDetailedDaoV2.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v2; + +import com.navercorp.pinpoint.common.server.bo.codec.stat.JvmGcDetailedDecoder; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDetailedDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; +import com.navercorp.pinpoint.web.mapper.stat.SampledJvmGcDetailedResultExtractor; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("sampledJvmGcDetailedDaoV2") +public class HbaseSampledJvmGcDetailedDaoV2 implements SampledJvmGcDetailedDao { + + @Autowired + private JvmGcDetailedDecoder jvmGcDetailedDecoder; + + @Autowired + private HbaseAgentStatDaoOperationsV2 operations; + + @Override + public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { + long scanFrom = timeWindow.getWindowRange().getFrom(); + long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); + Range range = new Range(scanFrom, scanTo); + AgentStatMapperV2 mapper = operations.createRowMapper(jvmGcDetailedDecoder, range); + SampledJvmGcDetailedResultExtractor resultExtractor = new SampledJvmGcDetailedResultExtractor(timeWindow, mapper); + return operations.getSampledAgentStatList(AgentStatType.JVM_GC_DETAILED, resultExtractor, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledTransactionDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledTransactionDaoV2.java new file mode 100644 index 000000000..a3eff9157 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseSampledTransactionDaoV2.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v2; + +import com.navercorp.pinpoint.common.server.bo.codec.stat.TransactionDecoder; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; +import com.navercorp.pinpoint.web.dao.stat.SampledTransactionDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; +import com.navercorp.pinpoint.web.mapper.stat.SampledTransactionResultExtractor; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("sampledTransactionDaoV2") +public class HbaseSampledTransactionDaoV2 implements SampledTransactionDao { + + @Autowired + private TransactionDecoder transactionDecoder; + + @Autowired + private HbaseAgentStatDaoOperationsV2 operations; + + @Override + public List getSampledAgentStatList(String agentId, TimeWindow timeWindow) { + long scanFrom = timeWindow.getWindowRange().getFrom(); + long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); + Range range = new Range(scanFrom, scanTo); + AgentStatMapperV2 mapper = operations.createRowMapper(transactionDecoder, range); + SampledTransactionResultExtractor resultExtractor = new SampledTransactionResultExtractor(timeWindow, mapper); + return operations.getSampledAgentStatList(AgentStatType.TRANSACTION, resultExtractor, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseTransactionDaoV2.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseTransactionDaoV2.java new file mode 100644 index 000000000..4c8270e4a --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/stat/v2/HbaseTransactionDaoV2.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.hbase.stat.v2; + +import com.navercorp.pinpoint.common.server.bo.codec.stat.TransactionDecoder; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; +import com.navercorp.pinpoint.web.dao.stat.TransactionDao; +import com.navercorp.pinpoint.web.mapper.stat.AgentStatMapperV2; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Repository("transactionDaoV2") +public class HbaseTransactionDaoV2 implements TransactionDao { + + @Autowired + private TransactionDecoder transactionDecoder; + + @Autowired + private HbaseAgentStatDaoOperationsV2 operations; + + @Override + public List getAgentStatList(String agentId, Range range) { + AgentStatMapperV2 mapper = operations.createRowMapper(transactionDecoder, range); + return operations.getAgentStatList(AgentStatType.TRANSACTION, mapper, agentId, range); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + AgentStatMapperV2 mapper = operations.createRowMapper(transactionDecoder, range); + return operations.agentStatExists(AgentStatType.TRANSACTION, mapper, agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataDoubleChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/ActiveTraceDao.java similarity index 63% rename from web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataDoubleChartBuilder.java rename to web/src/main/java/com/navercorp/pinpoint/web/dao/stat/ActiveTraceDao.java index b71bedc84..2e1fd4647 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataDoubleChartBuilder.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/ActiveTraceDao.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 NAVER Corp. + * Copyright 2016 Naver Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,12 @@ * limitations under the License. */ -package com.navercorp.pinpoint.web.vo.linechart; +package com.navercorp.pinpoint.web.dao.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; /** - * @author hyungil.jeong + * @author HyunGil Jeong */ -public class SampledDataDoubleChartBuilder extends SampledDataChartBuilder { - - public SampledDataDoubleChartBuilder(DownSampler downSampler, int sampleRate) { - super(downSampler, sampleRate); - } - +public interface ActiveTraceDao extends AgentStatDao { } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/AgentStatDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/AgentStatDao.java new file mode 100644 index 000000000..b6f7c7038 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/AgentStatDao.java @@ -0,0 +1,32 @@ +/* + * Copyright 2014 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.stat; + +import java.util.List; + +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.web.vo.Range; + +/** + * @author HyunGil Jeong + */ +public interface AgentStatDao { + + List getAgentStatList(String agentId, Range range); + + boolean agentStatExists(String agentId, Range range); +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/CpuLoadDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/CpuLoadDao.java new file mode 100644 index 000000000..5f67c7034 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/CpuLoadDao.java @@ -0,0 +1,25 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; + +/** + * @author HyunGil Jeong + */ +public interface CpuLoadDao extends AgentStatDao { +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/JvmGcDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/JvmGcDao.java new file mode 100644 index 000000000..83122bf19 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/JvmGcDao.java @@ -0,0 +1,25 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; + +/** + * @author HyunGil Jeong + */ +public interface JvmGcDao extends AgentStatDao { +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/JvmGcDetailedDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/JvmGcDetailedDao.java new file mode 100644 index 000000000..90917aed4 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/JvmGcDetailedDao.java @@ -0,0 +1,25 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; + +/** + * @author HyunGil Jeong + */ +public interface JvmGcDetailedDao extends AgentStatDao { +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/AgentStatDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/LegacyAgentStatDao.java similarity index 76% rename from web/src/main/java/com/navercorp/pinpoint/web/dao/AgentStatDao.java rename to web/src/main/java/com/navercorp/pinpoint/web/dao/stat/LegacyAgentStatDao.java index c4713974a..ef69d716a 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/AgentStatDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/LegacyAgentStatDao.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2016 Naver Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.web.dao; +package com.navercorp.pinpoint.web.dao.stat; import java.util.List; @@ -24,11 +24,7 @@ import com.navercorp.pinpoint.web.vo.Range; /** * @author hyungil.jeong */ -public interface AgentStatDao { - +@Deprecated +public interface LegacyAgentStatDao { List getAgentStatList(String agentId, Range range); - List getAggregatedAgentStatList(String agentId, Range range); - - boolean agentStatExists(String agentId, Range range); - } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledActiveTraceDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledActiveTraceDao.java new file mode 100644 index 000000000..adbc54ddf --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledActiveTraceDao.java @@ -0,0 +1,26 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.stat; + +import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; +import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; + +/** + * @author HyunGil Jeong + */ +public interface SampledActiveTraceDao extends SampledAgentStatDao { +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledCpuLoadDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledCpuLoadDao.java new file mode 100644 index 000000000..622b70890 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledCpuLoadDao.java @@ -0,0 +1,26 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.stat; + +import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; +import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; + +/** + * @author HyunGil Jeong + */ +public interface SampledCpuLoadDao extends SampledAgentStatDao { +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledJvmGcDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledJvmGcDao.java new file mode 100644 index 000000000..e3bd8545a --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledJvmGcDao.java @@ -0,0 +1,26 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.stat; + +import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; + +/** + * @author HyunGil Jeong + */ +public interface SampledJvmGcDao extends SampledAgentStatDao { +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledJvmGcDetailedDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledJvmGcDetailedDao.java new file mode 100644 index 000000000..7a49d72e8 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledJvmGcDetailedDao.java @@ -0,0 +1,26 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.stat; + +import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; + +/** + * @author HyunGil Jeong + */ +public interface SampledJvmGcDetailedDao extends SampledAgentStatDao { +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledTransactionDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledTransactionDao.java new file mode 100644 index 000000000..06f0fd0d4 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/SampledTransactionDao.java @@ -0,0 +1,26 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.stat; + +import com.navercorp.pinpoint.web.dao.SampledAgentStatDao; +import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; + +/** + * @author HyunGil Jeong + */ +public interface SampledTransactionDao extends SampledAgentStatDao { +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/TransactionDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/TransactionDao.java new file mode 100644 index 000000000..3b27cc51c --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/stat/TransactionDao.java @@ -0,0 +1,25 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.dao.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; + +/** + * @author HyunGil Jeong + */ +public interface TransactionDao extends AgentStatDao { +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/RangeTimestampFilter.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/RangeTimestampFilter.java new file mode 100644 index 000000000..b7c57d1b4 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/RangeTimestampFilter.java @@ -0,0 +1,36 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper; + +import com.navercorp.pinpoint.web.vo.Range; + +/** + * @author HyunGil Jeong + */ +public class RangeTimestampFilter implements TimestampFilter { + + private final Range range; + + public RangeTimestampFilter(Range range) { + this.range = range; + } + + @Override + public boolean filter(long timestamp) { + return timestamp < this.range.getFrom() || timestamp > this.range.getTo(); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/TimestampFilter.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/TimestampFilter.java new file mode 100644 index 000000000..c9ac27405 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/TimestampFilter.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper; + +/** + * @author HyunGil Jeong + */ +public interface TimestampFilter { + boolean filter(long timestamp); +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapper.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapper.java new file mode 100644 index 000000000..d1e710700 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper.stat; + +import com.navercorp.pinpoint.common.hbase.RowMapper; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +public interface AgentStatMapper extends RowMapper> { +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV1.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV1.java new file mode 100644 index 000000000..e14e5b356 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV1.java @@ -0,0 +1,287 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper.stat; + +import static com.navercorp.pinpoint.common.hbase.HBaseTables.*; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.NavigableMap; + +import com.navercorp.pinpoint.common.server.bo.ActiveTraceHistogramBo; +import com.navercorp.pinpoint.common.server.bo.AgentStatCpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.AgentStatMemoryGcBo; +import com.navercorp.pinpoint.common.hbase.RowMapper; +import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; +import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; +import com.navercorp.pinpoint.common.util.BytesUtils; +import com.navercorp.pinpoint.common.util.TimeUtils; +import com.navercorp.pinpoint.thrift.dto.TAgentStat; +import com.navercorp.pinpoint.thrift.dto.TJvmGc; +import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix; + +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.thrift.TDeserializer; +import org.apache.thrift.TException; +import org.apache.thrift.protocol.TCompactProtocol; +import org.apache.thrift.protocol.TProtocolFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +/** + * @author HyunGil Jeong + */ +public abstract class AgentStatMapperV1 implements AgentStatMapper { + + private static final TProtocolFactory FACTORY = new TCompactProtocol.Factory(); + + @Autowired + @Qualifier("agentStatRowKeyDistributor") + private RowKeyDistributorByHashPrefix rowKeyDistributorByHashPrefix; + + @Override + public List mapRow(Result result, int rowNum) throws Exception { + if (result.isEmpty()) { + return Collections.emptyList(); + } + final byte[] rowKey = getOriginalKey(result.getRow()); + final String agentId = BytesUtils.toString(rowKey, 0, AGENT_NAME_MAX_LEN).trim(); + final long reverseTimestamp = BytesUtils.bytesToLong(rowKey, AGENT_NAME_MAX_LEN); + final long timestamp = TimeUtils.recoveryTimeMillis(reverseTimestamp); + NavigableMap qualifierMap = result.getFamilyMap(AGENT_STAT_CF_STATISTICS); + + if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_V1)) { + // FIXME (2014.08) Legacy support for TAgentStat Thrift DTO stored directly into hbase. + return readAgentStatThriftDto(agentId, timestamp, qualifierMap.get(AGENT_STAT_CF_STATISTICS_V1)); + } else if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_MEMORY_GC) || qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_CPU_LOAD)) { + // FIXME (2015.10) Legacy column for storing serialzied Bos separately. + return readSerializedBos(agentId, timestamp, qualifierMap); + } else { + return mapQualifiers(agentId, timestamp, qualifierMap); + } + } + + private byte[] getOriginalKey(byte[] rowKey) { + return rowKeyDistributorByHashPrefix.getOriginalKey(rowKey); + } + + // FIXME (2014.08) Legacy support for TAgentStat Thrift DTO stored directly into hbase. + @Deprecated + protected abstract List readAgentStatThriftDto(String agentId, long timestamp, byte[]tAgentStatByteArray) throws TException; + + // FIXME (2015.10) Legacy column for storing serialzied Bos separately. + @Deprecated + protected abstract List readSerializedBos(String agentId, long timestamp, Map qualifierMap); + + protected abstract List mapQualifiers(String agentId, long timestamp, Map qualifierMap); + + @Component("jvmGcMapper") + public static class JvmGcMapper extends AgentStatMapperV1 { + + @Override + protected List readAgentStatThriftDto(String agentId, long timestamp, byte[] tAgentStatByteArray) throws TException { + // CompactProtocol used + TDeserializer deserializer = new TDeserializer(FACTORY); + TAgentStat tAgentStat = new TAgentStat(); + deserializer.deserialize(tAgentStat, tAgentStatByteArray); + TJvmGc gc = tAgentStat.getGc(); + if (gc == null) { + return Collections.emptyList(); + } + AgentStatMemoryGcBo.Builder memoryGcBoBuilder = new AgentStatMemoryGcBo.Builder(tAgentStat.getAgentId(), tAgentStat.getStartTimestamp(), tAgentStat.getTimestamp()); + memoryGcBoBuilder.gcType(gc.getType().name()); + memoryGcBoBuilder.jvmMemoryHeapUsed(gc.getJvmMemoryHeapUsed()); + memoryGcBoBuilder.jvmMemoryHeapMax(gc.getJvmMemoryHeapMax()); + memoryGcBoBuilder.jvmMemoryNonHeapUsed(gc.getJvmMemoryNonHeapUsed()); + memoryGcBoBuilder.jvmMemoryNonHeapMax(gc.getJvmMemoryNonHeapMax()); + memoryGcBoBuilder.jvmGcOldCount(gc.getJvmGcOldCount()); + memoryGcBoBuilder.jvmGcOldTime(gc.getJvmGcOldTime()); + AgentStatMemoryGcBo agentStatMemoryGcBo = memoryGcBoBuilder.build(); + JvmGcBo jvmGcBo = new JvmGcBo(); + jvmGcBo.setAgentId(agentStatMemoryGcBo.getAgentId()); + jvmGcBo.setTimestamp(agentStatMemoryGcBo.getTimestamp()); + jvmGcBo.setGcOldCount(agentStatMemoryGcBo.getJvmGcOldCount()); + jvmGcBo.setGcOldTime(agentStatMemoryGcBo.getJvmGcOldTime()); + jvmGcBo.setHeapUsed(agentStatMemoryGcBo.getJvmMemoryHeapUsed()); + jvmGcBo.setHeapMax(agentStatMemoryGcBo.getJvmMemoryHeapMax()); + jvmGcBo.setNonHeapUsed(agentStatMemoryGcBo.getJvmMemoryNonHeapUsed()); + jvmGcBo.setNonHeapMax(agentStatMemoryGcBo.getJvmMemoryNonHeapMax()); + return Arrays.asList(jvmGcBo); + } + + @Override + protected List readSerializedBos(String agentId, long timestamp, Map qualifierMap) { + if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_MEMORY_GC)) { + AgentStatMemoryGcBo.Builder builder = new AgentStatMemoryGcBo.Builder(qualifierMap.get(AGENT_STAT_CF_STATISTICS_MEMORY_GC)); + AgentStatMemoryGcBo agentStatMemoryGcBo = builder.build(); + JvmGcBo jvmGcBo = new JvmGcBo(); + jvmGcBo.setAgentId(agentStatMemoryGcBo.getAgentId()); + jvmGcBo.setTimestamp(agentStatMemoryGcBo.getTimestamp()); + jvmGcBo.setGcOldCount(agentStatMemoryGcBo.getJvmGcOldCount()); + jvmGcBo.setGcOldTime(agentStatMemoryGcBo.getJvmGcOldTime()); + jvmGcBo.setHeapUsed(agentStatMemoryGcBo.getJvmMemoryHeapUsed()); + jvmGcBo.setHeapMax(agentStatMemoryGcBo.getJvmMemoryHeapMax()); + jvmGcBo.setNonHeapUsed(agentStatMemoryGcBo.getJvmMemoryNonHeapUsed()); + jvmGcBo.setNonHeapMax(agentStatMemoryGcBo.getJvmMemoryNonHeapMax()); + return Arrays.asList(jvmGcBo); + } else { + return Collections.emptyList(); + } + } + + @Override + protected List mapQualifiers(String agentId, long timestamp, Map qualifierMap) { + JvmGcBo jvmGcBo = new JvmGcBo(); + jvmGcBo.setAgentId(agentId); + jvmGcBo.setTimestamp(timestamp); + if (qualifierMap.containsKey(AGENT_STAT_COL_GC_OLD_COUNT)) { + jvmGcBo.setGcOldCount(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_GC_OLD_COUNT))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_GC_OLD_TIME)) { + jvmGcBo.setGcOldTime(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_GC_OLD_TIME))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_HEAP_USED)) { + jvmGcBo.setHeapUsed(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_HEAP_USED))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_HEAP_MAX)) { + jvmGcBo.setHeapMax(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_HEAP_MAX))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_NON_HEAP_USED)) { + jvmGcBo.setNonHeapUsed(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_NON_HEAP_USED))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_NON_HEAP_MAX)) { + jvmGcBo.setNonHeapMax(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_NON_HEAP_MAX))); + } + return Arrays.asList(jvmGcBo); + } + } + + @Component("cpuLoadMapper") + public static class CpuLoadMapper extends AgentStatMapperV1 { + + @Override + protected List readAgentStatThriftDto(String agentId, long timestamp, byte[] tAgentStatByteArray) throws TException { + // cpu load collection wasn't implemented for this + return Collections.emptyList(); + } + + @Override + protected List readSerializedBos(String agentId, long timestamp, Map qualifierMap) { + if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_CPU_LOAD)) { + AgentStatCpuLoadBo.Builder builder = new AgentStatCpuLoadBo.Builder(qualifierMap.get(AGENT_STAT_CF_STATISTICS_CPU_LOAD)); + AgentStatCpuLoadBo agentStatCpuLoadBo = builder.build(); + CpuLoadBo cpuLoadBo = new CpuLoadBo(); + cpuLoadBo.setAgentId(agentStatCpuLoadBo.getAgentId()); + cpuLoadBo.setTimestamp(agentStatCpuLoadBo.getTimestamp()); + cpuLoadBo.setJvmCpuLoad(agentStatCpuLoadBo.getJvmCpuLoad()); + cpuLoadBo.setSystemCpuLoad(agentStatCpuLoadBo.getSystemCpuLoad()); + return Arrays.asList(cpuLoadBo); + } else { + return Collections.emptyList(); + } + } + + @Override + protected List mapQualifiers(String agentId, long timestamp, Map qualifierMap) { + CpuLoadBo cpuLoadBo = new CpuLoadBo(); + cpuLoadBo.setAgentId(agentId); + cpuLoadBo.setTimestamp(timestamp); + if (qualifierMap.containsKey(AGENT_STAT_COL_JVM_CPU)) { + cpuLoadBo.setJvmCpuLoad(Bytes.toDouble(qualifierMap.get(AGENT_STAT_COL_JVM_CPU))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_SYS_CPU)) { + cpuLoadBo.setSystemCpuLoad(Bytes.toDouble(qualifierMap.get(AGENT_STAT_COL_SYS_CPU))); + } + return Arrays.asList(cpuLoadBo); + } + } + + @Component("transactionMapper") + public static class TransactionMapper extends AgentStatMapperV1 { + + @Override + protected List readAgentStatThriftDto(String agentId, long timestamp, byte[] tAgentStatByteArray) throws TException { + // transaction collection wasn't implemented for this + return Collections.emptyList(); + } + + @Override + protected List readSerializedBos(String agentId, long timestamp, Map qualifierMap) { + // transaction collection wasn't implemented for this + return Collections.emptyList(); + } + + @Override + protected List mapQualifiers(String agentId, long timestamp, Map qualifierMap) { + TransactionBo transactionBo = new TransactionBo(); + transactionBo.setAgentId(agentId); + transactionBo.setTimestamp(timestamp); + if (qualifierMap.containsKey(AGENT_STAT_COL_INTERVAL)) { + transactionBo.setCollectInterval(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_INTERVAL))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_TRANSACTION_SAMPLED_NEW)) { + transactionBo.setSampledNewCount(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_TRANSACTION_SAMPLED_NEW))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_TRANSACTION_SAMPLED_CONTINUATION)) { + transactionBo.setSampledContinuationCount(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_TRANSACTION_SAMPLED_CONTINUATION))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_NEW)) { + transactionBo.setUnsampledNewCount(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_NEW))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_CONTINUATION)) { + transactionBo.setUnsampledContinuationCount(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_CONTINUATION))); + } + return Arrays.asList(transactionBo); + } + } + + @Component("activeTraceMapper") + public static class ActiveTraceMapper extends AgentStatMapperV1 { + + @Override + protected List readAgentStatThriftDto(String agentId, long timestamp, byte[] tAgentStatByteArray) throws TException { + // active trace collection wasn't implemented for this + return Collections.emptyList(); + } + + @Override + protected List readSerializedBos(String agentId, long timestamp, Map qualifierMap) { + // active trace collection wasn't implemented for this + return Collections.emptyList(); + } + + @Override + protected List mapQualifiers(String agentId, long timestamp, Map qualifierMap) { + ActiveTraceBo activeTraceBo = new ActiveTraceBo(); + activeTraceBo.setAgentId(agentId); + activeTraceBo.setTimestamp(timestamp); + if (qualifierMap.containsKey(AGENT_STAT_COL_ACTIVE_TRACE_HISTOGRAM)) { + ActiveTraceHistogramBo activeTraceHistogramBo = new ActiveTraceHistogramBo(qualifierMap.get(AGENT_STAT_COL_ACTIVE_TRACE_HISTOGRAM)); + activeTraceBo.setHistogramSchemaType(activeTraceHistogramBo.getHistogramSchemaType()); + activeTraceBo.setActiveTraceCounts(activeTraceHistogramBo.getActiveTraceCountMap()); + } + return Arrays.asList(activeTraceBo); + } + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2.java new file mode 100644 index 000000000..9c25fed67 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2.java @@ -0,0 +1,92 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper.stat; + +import com.navercorp.pinpoint.common.buffer.Buffer; +import com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer; +import com.navercorp.pinpoint.common.hbase.HBaseTables; +import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDecoder; +import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatHbaseOperationFactory; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.web.mapper.TimestampFilter; +import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.CellUtil; +import org.apache.hadoop.hbase.client.Result; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + + +/** + * @author HyunGil Jeong + */ +public class AgentStatMapperV2 implements AgentStatMapper { + + public static Comparator REVERSE_TIMESTAMP_COMPARATOR = new Comparator() { + @Override + public int compare(AgentStatDataPoint o1, AgentStatDataPoint o2) { + long x = o2.getTimestamp(); + long y = o1.getTimestamp(); + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + }; + + private final AgentStatHbaseOperationFactory hbaseOperationFactory; + private final AgentStatDecoder decoder; + private final TimestampFilter filter; + + public AgentStatMapperV2(AgentStatHbaseOperationFactory hbaseOperationFactory, AgentStatDecoder decoder, TimestampFilter filter) { + this.hbaseOperationFactory = hbaseOperationFactory; + this.decoder = decoder; + this.filter = filter; + } + + @Override + public List mapRow(Result result, int rowNum) throws Exception { + if (result.isEmpty()) { + return Collections.emptyList(); + } + final byte[] distributedRowKey = result.getRow(); + final String agentId = this.hbaseOperationFactory.getAgentId(distributedRowKey); + final long baseTimestamp = this.hbaseOperationFactory.getBaseTimestamp(distributedRowKey); + + List dataPoints = new ArrayList<>(); + + for (Cell cell : result.rawCells()) { + if (CellUtil.matchingFamily(cell, HBaseTables.AGENT_STAT_CF_STATISTICS)) { + Buffer qualifierBuffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); + Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); + + long initialTimestamp = this.decoder.decodeInitialTimestamp(baseTimestamp, qualifierBuffer); + List candidates = this.decoder.decodeDataPoints(initialTimestamp, valueBuffer); + for (T candidate : candidates) { + candidate.setAgentId(agentId); + long timestamp = candidate.getTimestamp(); + if (this.filter.filter(timestamp)) { + continue; + } + dataPoints.add(candidate); + } + } + } + // Reverse sort as timestamp is stored in a reversed order. + Collections.sort(dataPoints, REVERSE_TIMESTAMP_COMPARATOR); + return dataPoints; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/AgentStatMapper.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/LegacyAgentStatMapper.java similarity index 98% rename from web/src/main/java/com/navercorp/pinpoint/web/mapper/AgentStatMapper.java rename to web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/LegacyAgentStatMapper.java index 66dbfe41a..2c80074cd 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/AgentStatMapper.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/LegacyAgentStatMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2016 Naver Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.web.mapper; +package com.navercorp.pinpoint.web.mapper.stat; import static com.navercorp.pinpoint.common.hbase.HBaseTables.*; @@ -50,8 +50,9 @@ import org.springframework.stereotype.Component; * @author harebox * @author HyunGil Jeong */ -@Component -public class AgentStatMapper implements RowMapper> { +@Deprecated +@Component("legacyAgentStatMapper") +public class LegacyAgentStatMapper implements RowMapper> { private TProtocolFactory factory = new TCompactProtocol.Factory(); @@ -195,5 +196,4 @@ public class AgentStatMapper implements RowMapper> { result.add(agentStat); return result; } - -} +} \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledActiveTraceResultExtractor.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledActiveTraceResultExtractor.java new file mode 100644 index 000000000..7d7c3043b --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledActiveTraceResultExtractor.java @@ -0,0 +1,75 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; +import com.navercorp.pinpoint.common.trace.BaseHistogramSchema; +import com.navercorp.pinpoint.common.trace.HistogramSchema; +import com.navercorp.pinpoint.common.trace.SlotType; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers; +import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; +import com.navercorp.pinpoint.web.vo.chart.TitledPoint; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author HyunGil Jeong + */ +public class SampledActiveTraceResultExtractor extends SampledAgentStatResultExtractor { + + private static final int UNCOLLECTED_COUNT = -1; + public static final DownSampler INTEGER_DOWN_SAMPLER = DownSamplers.getIntegerDownSampler(UNCOLLECTED_COUNT); + + public SampledActiveTraceResultExtractor(TimeWindow timeWindow, AgentStatMapper rowMapper) { + super(timeWindow, rowMapper); + } + + @Override + protected SampledActiveTrace sampleCurrentBatch(long timestamp, List dataPointsToSample) { + HistogramSchema schema = BaseHistogramSchema.getDefaultHistogramSchemaByTypeCode(dataPointsToSample.get(0).getHistogramSchemaType()); + List fastCounts = new ArrayList<>(dataPointsToSample.size()); + List normalCounts = new ArrayList<>(dataPointsToSample.size()); + List slowCounts = new ArrayList<>(dataPointsToSample.size()); + List verySlowCounts = new ArrayList<>(dataPointsToSample.size()); + for (ActiveTraceBo activeTraceBo : dataPointsToSample) { + Map activeTraceCounts = activeTraceBo.getActiveTraceCounts(); + fastCounts.add(activeTraceCounts.get(SlotType.FAST)); + normalCounts.add(activeTraceCounts.get(SlotType.NORMAL)); + slowCounts.add(activeTraceCounts.get(SlotType.SLOW)); + verySlowCounts.add(activeTraceCounts.get(SlotType.VERY_SLOW)); + } + SampledActiveTrace sampledActiveTrace = new SampledActiveTrace(); + sampledActiveTrace.setFastCounts(createSampledTitledPoint(schema.getFastSlot().getSlotName(), timestamp, fastCounts)); + sampledActiveTrace.setNormalCounts(createSampledTitledPoint(schema.getNormalSlot().getSlotName(), timestamp, normalCounts)); + sampledActiveTrace.setSlowCounts(createSampledTitledPoint(schema.getSlowSlot().getSlotName(), timestamp, slowCounts)); + sampledActiveTrace.setVerySlowCounts(createSampledTitledPoint(schema.getVerySlowSlot().getSlotName(), timestamp, verySlowCounts)); + return sampledActiveTrace; + } + + private TitledPoint createSampledTitledPoint(String title, long timestamp, List values) { + return new TitledPoint<>( + title, + timestamp, + INTEGER_DOWN_SAMPLER.sampleMin(values), + INTEGER_DOWN_SAMPLER.sampleMax(values), + INTEGER_DOWN_SAMPLER.sampleAvg(values)); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractor.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractor.java new file mode 100644 index 000000000..e39e6cad3 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractor.java @@ -0,0 +1,88 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper.stat; + +import com.navercorp.pinpoint.common.hbase.ResultsExtractor; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; + +import java.util.ArrayList; +import java.util.List; + + +/** + * @author HyunGil Jeong + */ +public abstract class SampledAgentStatResultExtractor implements ResultsExtractor> { + + private final TimeWindow timeWindow; + private final AgentStatMapper rowMapper; + private final List sampledDataPoints; + + public SampledAgentStatResultExtractor(TimeWindow timeWindow, AgentStatMapper rowMapper) { + if (timeWindow.getWindowRangeCount() > Integer.MAX_VALUE) { + throw new IllegalArgumentException("range yields too many timeslots"); + } + this.timeWindow = timeWindow; + this.rowMapper = rowMapper; + this.sampledDataPoints = new ArrayList<>((int) timeWindow.getWindowRangeCount()); + } + + @Override + public List extractData(ResultScanner results) throws Exception { + int rowNum = 0; + // Sample straight away, tossing out already sampled data points so they can be garbage collected + // as soon as possible. + // This is mainly important when querying over a long period of time which simply using SampledChartBuilder + // could could consume too much memory. + List currentBatchToSample = new ArrayList<>(); + long currentTimeslotTimestamp = 0; + for (Result result : results) { + List dataPoints = this.rowMapper.mapRow(result, rowNum++); + for (T dataPoint : dataPoints) { + long timestamp = dataPoint.getTimestamp(); + long timeslotTimestamp = this.timeWindow.refineTimestamp(timestamp); + if (currentTimeslotTimestamp == 0 || currentTimeslotTimestamp == timeslotTimestamp) { + currentBatchToSample.add(dataPoint); + currentTimeslotTimestamp = timeslotTimestamp; + } else if (timeslotTimestamp < currentTimeslotTimestamp) { + // currentBatchToSample shouldn't be empty at this point + S sampledBatch = sampleCurrentBatch(currentTimeslotTimestamp, currentBatchToSample); + this.sampledDataPoints.add(sampledBatch); + currentBatchToSample = new ArrayList<>(); + currentBatchToSample.add(dataPoint); + currentTimeslotTimestamp = timeslotTimestamp; + } else { + // Results should be sorted in a descending order of their actual timestamp values + // as they are stored using reverse timestamp. + throw new IllegalStateException("Out of order AgentStatDataPoint"); + } + } + } + if (!currentBatchToSample.isEmpty()) { + S sampledBatch = sampleCurrentBatch(currentTimeslotTimestamp, currentBatchToSample); + sampledDataPoints.add(sampledBatch); + } + return this.sampledDataPoints; + } + + protected abstract S sampleCurrentBatch(long timestamp, List dataPointsToSample); + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledCpuLoadResultExtractor.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledCpuLoadResultExtractor.java new file mode 100644 index 000000000..9dc62b0bc --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledCpuLoadResultExtractor.java @@ -0,0 +1,59 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.chart.Point; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers; +import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author HyunGil Jeong + */ +public class SampledCpuLoadResultExtractor extends SampledAgentStatResultExtractor { + + private static final double UNCOLLECTED_CPU_LOAD = -1D; + private static final int NUM_DECIMAL_PLACES = 1; + public static final DownSampler DOUBLE_DOWN_SAMPLER = DownSamplers.getDoubleDownSampler(UNCOLLECTED_CPU_LOAD, NUM_DECIMAL_PLACES); + + public SampledCpuLoadResultExtractor(TimeWindow timeWindow, AgentStatMapper rowMapper) { + super(timeWindow, rowMapper); + } + + @Override + protected SampledCpuLoad sampleCurrentBatch(long timestamp, List dataPointsToSample) { + List jvmCpuLoads = new ArrayList<>(dataPointsToSample.size()); + List systemCpuLoads = new ArrayList<>(dataPointsToSample.size()); + for (CpuLoadBo cpuLoadBo : dataPointsToSample) { + jvmCpuLoads.add(cpuLoadBo.getJvmCpuLoad() * 100); + systemCpuLoads.add(cpuLoadBo.getSystemCpuLoad() * 100); + } + SampledCpuLoad sampledCpuLoad = new SampledCpuLoad(); + sampledCpuLoad.setJvmCpuLoad(createPoint(timestamp, jvmCpuLoads)); + sampledCpuLoad.setSystemCpuLoad(createPoint(timestamp, systemCpuLoads)); + return sampledCpuLoad; + } + + private Point createPoint(long timestamp, List values) { + return new Point<>(timestamp, DOUBLE_DOWN_SAMPLER.sampleMin(values), DOUBLE_DOWN_SAMPLER.sampleMax(values), DOUBLE_DOWN_SAMPLER.sampleAvg(values)); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledJvmGcDetailedResultExtractor.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledJvmGcDetailedResultExtractor.java new file mode 100644 index 000000000..2910c8669 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledJvmGcDetailedResultExtractor.java @@ -0,0 +1,82 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.chart.Point; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author HyunGil Jeong + */ +public class SampledJvmGcDetailedResultExtractor extends SampledAgentStatResultExtractor { + + private static final long UNCOLLECTED_VALUE = -1L; + private static final int NUM_DECIMAL_PLACES = 1; + public static final DownSampler LONG_DOWN_SAMPLER = DownSamplers.getLongDownSampler(UNCOLLECTED_VALUE); + public static final DownSampler DOUBLE_DOWN_SAMPLER = DownSamplers.getDoubleDownSampler(UNCOLLECTED_VALUE, NUM_DECIMAL_PLACES); + + public SampledJvmGcDetailedResultExtractor(TimeWindow timeWindow, AgentStatMapper rowMapper) { + super(timeWindow, rowMapper); + } + + @Override + protected SampledJvmGcDetailed sampleCurrentBatch(long timestamp, List dataPointsToSample) { + List gcNewCounts = new ArrayList<>(dataPointsToSample.size()); + List gcNewTimes = new ArrayList<>(dataPointsToSample.size()); + List codeCacheUseds = new ArrayList<>(dataPointsToSample.size()); + List newGenUseds = new ArrayList<>(dataPointsToSample.size()); + List oldGenUseds = new ArrayList<>(dataPointsToSample.size()); + List survivorSpaceUseds = new ArrayList<>(dataPointsToSample.size()); + List permGenUseds = new ArrayList<>(dataPointsToSample.size()); + List metaspaceUseds = new ArrayList<>(dataPointsToSample.size()); + for (JvmGcDetailedBo jvmGcDetailedBo : dataPointsToSample) { + gcNewCounts.add(jvmGcDetailedBo.getGcNewCount()); + gcNewTimes.add(jvmGcDetailedBo.getGcNewTime()); + codeCacheUseds.add(jvmGcDetailedBo.getCodeCacheUsed() * 100); + newGenUseds.add(jvmGcDetailedBo.getNewGenUsed() * 100); + oldGenUseds.add(jvmGcDetailedBo.getOldGenUsed() * 100); + survivorSpaceUseds.add(jvmGcDetailedBo.getSurvivorSpaceUsed() * 100); + permGenUseds.add(jvmGcDetailedBo.getPermGenUsed() * 100); + metaspaceUseds.add(jvmGcDetailedBo.getMetaspaceUsed() * 100); + } + SampledJvmGcDetailed sampledJvmGcDetailed = new SampledJvmGcDetailed(); + sampledJvmGcDetailed.setGcNewCount(createLongPoint(timestamp, gcNewCounts)); + sampledJvmGcDetailed.setGcNewTime(createLongPoint(timestamp, gcNewTimes)); + sampledJvmGcDetailed.setCodeCacheUsed(createDoublePoint(timestamp, codeCacheUseds)); + sampledJvmGcDetailed.setNewGenUsed(createDoublePoint(timestamp, newGenUseds)); + sampledJvmGcDetailed.setOldGenUsed(createDoublePoint(timestamp, oldGenUseds)); + sampledJvmGcDetailed.setSurvivorSpaceUsed(createDoublePoint(timestamp, survivorSpaceUseds)); + sampledJvmGcDetailed.setPermGenUsed(createDoublePoint(timestamp, permGenUseds)); + sampledJvmGcDetailed.setMetaspaceUsed(createDoublePoint(timestamp, metaspaceUseds)); + return sampledJvmGcDetailed; + } + + private Point createLongPoint(long timestamp, List values) { + return new Point<>(timestamp, LONG_DOWN_SAMPLER.sampleMin(values), LONG_DOWN_SAMPLER.sampleMax(values), LONG_DOWN_SAMPLER.sampleAvg(values)); + } + + private Point createDoublePoint(long timestamp, List values) { + return new Point(timestamp, DOUBLE_DOWN_SAMPLER.sampleMin(values), DOUBLE_DOWN_SAMPLER.sampleMax(values), DOUBLE_DOWN_SAMPLER.sampleAvg(values)); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledJvmGcResultExtractor.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledJvmGcResultExtractor.java new file mode 100644 index 000000000..11c5af28e --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledJvmGcResultExtractor.java @@ -0,0 +1,71 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.chart.Point; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author HyunGil Jeong + */ +public class SampledJvmGcResultExtractor extends SampledAgentStatResultExtractor { + + private static final long UNCOLLECTED_VALUE = -1L; + public static final DownSampler LONG_DOWN_SAMPLER = DownSamplers.getLongDownSampler(UNCOLLECTED_VALUE); + + public SampledJvmGcResultExtractor(TimeWindow timeWindow, AgentStatMapper rowMapper) { + super(timeWindow, rowMapper); + } + + @Override + protected SampledJvmGc sampleCurrentBatch(long timestamp, List dataPointsToSample) { + List heapUseds = new ArrayList<>(dataPointsToSample.size()); + List heapMaxes = new ArrayList<>(dataPointsToSample.size()); + List nonHeapUseds = new ArrayList<>(dataPointsToSample.size()); + List nonHeapMaxes = new ArrayList<>(dataPointsToSample.size()); + List gcOldCounts = new ArrayList<>(dataPointsToSample.size()); + List gcOldTimes = new ArrayList<>(dataPointsToSample.size()); + for (JvmGcBo jvmGcBo : dataPointsToSample) { + heapUseds.add(jvmGcBo.getHeapUsed()); + heapMaxes.add(jvmGcBo.getHeapMax()); + nonHeapUseds.add(jvmGcBo.getNonHeapUsed()); + nonHeapMaxes.add(jvmGcBo.getNonHeapMax()); + gcOldCounts.add(jvmGcBo.getGcOldCount()); + gcOldTimes.add(jvmGcBo.getGcOldTime()); + } + SampledJvmGc sampledJvmGc = new SampledJvmGc(); + sampledJvmGc.setHeapUsed(createPoint(timestamp, heapUseds)); + sampledJvmGc.setHeapMax(createPoint(timestamp, heapMaxes)); + sampledJvmGc.setNonHeapUsed(createPoint(timestamp, nonHeapUseds)); + sampledJvmGc.setNonHeapMax(createPoint(timestamp, nonHeapMaxes)); + sampledJvmGc.setGcOldCount(createPoint(timestamp, gcOldCounts)); + sampledJvmGc.setGcOldTime(createPoint(timestamp, gcOldTimes)); + return sampledJvmGc; + } + + private Point createPoint(long timestamp, List values) { + return new Point<>(timestamp, LONG_DOWN_SAMPLER.sampleMin(values), LONG_DOWN_SAMPLER.sampleMax(values), LONG_DOWN_SAMPLER.sampleAvg(values)); + } + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledTransactionResultExtractor.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledTransactionResultExtractor.java new file mode 100644 index 000000000..626ddc4b2 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/stat/SampledTransactionResultExtractor.java @@ -0,0 +1,80 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper.stat; + +import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; +import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.chart.Point; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSamplers; +import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author HyunGil Jeong + */ +public class SampledTransactionResultExtractor extends SampledAgentStatResultExtractor { + + private static final double UNCOLLECTED_TPS = -1D; + private static final int NUM_DECIMAL_PLACES = 1; + public static final DownSampler DOUBLE_DOWN_SAMPLER = DownSamplers.getDoubleDownSampler(UNCOLLECTED_TPS, NUM_DECIMAL_PLACES); + + public SampledTransactionResultExtractor(TimeWindow timeWindow, AgentStatMapper rowMapper) { + super(timeWindow, rowMapper); + } + + @Override + protected SampledTransaction sampleCurrentBatch(long timestamp, List dataPointsToSample) { + List sampledNews = new ArrayList<>(dataPointsToSample.size()); + List sampledContinuations = new ArrayList<>(dataPointsToSample.size()); + List unsampledNews = new ArrayList<>(dataPointsToSample.size()); + List unsampledContinuations = new ArrayList<>(dataPointsToSample.size()); + List totals = new ArrayList<>(dataPointsToSample.size()); + for (TransactionBo transactionBo : dataPointsToSample) { + long collectInterval = transactionBo.getCollectInterval(); + long sampledNewCount = transactionBo.getSampledNewCount(); + long sampledContinuationCount = transactionBo.getSampledContinuationCount(); + long unsampledNewCount = transactionBo.getUnsampledNewCount(); + long unsampledContinuationCount = transactionBo.getUnsampledContinuationCount(); + long total = sampledNewCount + sampledContinuationCount + unsampledNewCount + unsampledContinuationCount; + sampledNews.add(calculateTps(sampledNewCount, collectInterval)); + sampledContinuations.add(calculateTps(sampledContinuationCount, collectInterval)); + unsampledNews.add(calculateTps(unsampledNewCount, collectInterval)); + unsampledContinuations.add(calculateTps(unsampledContinuationCount, collectInterval)); + totals.add(calculateTps(total, collectInterval)); + } + SampledTransaction sampledTransaction = new SampledTransaction(); + sampledTransaction.setSampledNew(createPoint(timestamp, sampledNews)); + sampledTransaction.setSampledContinuation(createPoint(timestamp, sampledContinuations)); + sampledTransaction.setUnsampledNew(createPoint(timestamp, unsampledNews)); + sampledTransaction.setUnsampledContinuation(createPoint(timestamp, unsampledContinuations)); + sampledTransaction.setTotal(createPoint(timestamp, totals)); + return sampledTransaction; + } + + private double calculateTps(long count, long intervalMs) { + return AgentStatUtils.calculateRate(count, intervalMs, NUM_DECIMAL_PLACES, UNCOLLECTED_TPS); + } + + private Point createPoint(long timestamp, List values) { + return new Point<>(timestamp, DOUBLE_DOWN_SAMPLER.sampleMin(values), DOUBLE_DOWN_SAMPLER.sampleMax(values), DOUBLE_DOWN_SAMPLER.sampleAvg(values)); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AdminServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AdminServiceImpl.java index a8bc5c299..3f3facf4c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AdminServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AdminServiceImpl.java @@ -17,13 +17,14 @@ package com.navercorp.pinpoint.web.service; import com.google.common.collect.Ordering; -import com.navercorp.pinpoint.web.dao.AgentStatDao; +import com.navercorp.pinpoint.web.dao.stat.JvmGcDao; import com.navercorp.pinpoint.web.vo.Application; import com.navercorp.pinpoint.web.vo.Range; import org.apache.commons.collections.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; @@ -52,7 +53,8 @@ public class AdminServiceImpl implements AdminService { private ApplicationIndexDao applicationIndexDao; @Autowired - private AgentStatDao agentStatDao; + @Qualifier("jvmGcDaoFactory") + private JvmGcDao jvmGcDao; @Override public void removeApplicationName(String applicationName) { @@ -154,7 +156,10 @@ public class AdminServiceImpl implements AdminService { final long fromTimestamp = cal.getTimeInMillis(); Range queryRange = new Range(fromTimestamp, toTimestamp); for (String agentId : agentIds) { - boolean dataExists = this.agentStatDao.agentStatExists(agentId, queryRange); + // FIXME This needs to be done with a more accurate information. + // If at any time a non-java agent is introduced, or an agent that does not collect jvm data, + // this will fail + boolean dataExists = this.jvmGcDao.agentStatExists(agentId, queryRange); if (!dataExists) { inactiveAgentIds.add(agentId); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/ActiveTraceChartService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/ActiveTraceChartService.java new file mode 100644 index 000000000..0032768d0 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/ActiveTraceChartService.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.web.dao.stat.SampledActiveTraceDao; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; +import com.navercorp.pinpoint.web.vo.stat.chart.ActiveTraceChartGroup; +import com.navercorp.pinpoint.web.vo.stat.chart.AgentStatChartGroup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Service +public class ActiveTraceChartService implements AgentStatChartService { + + private final SampledActiveTraceDao sampledActiveTraceDao; + + @Autowired + public ActiveTraceChartService(@Qualifier("sampledActiveTraceDaoFactory") SampledActiveTraceDao sampledActiveTraceDao) { + this.sampledActiveTraceDao = sampledActiveTraceDao; + } + + @Override + public AgentStatChartGroup selectAgentChart(String agentId, TimeWindow timeWindow) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (timeWindow == null) { + throw new NullPointerException("timeWindow must not be null"); + } + List sampledActiveTraces = this.sampledActiveTraceDao.getSampledAgentStatList(agentId, timeWindow); + return new ActiveTraceChartGroup(timeWindow, sampledActiveTraces); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/ActiveTraceService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/ActiveTraceService.java new file mode 100644 index 000000000..8bc3841ed --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/ActiveTraceService.java @@ -0,0 +1,51 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.ActiveTraceBo; +import com.navercorp.pinpoint.web.dao.stat.ActiveTraceDao; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Service +public class ActiveTraceService implements AgentStatService { + + private final ActiveTraceDao activeTraceDao; + + @Autowired + public ActiveTraceService(@Qualifier("activeTraceDaoFactory") ActiveTraceDao activeTraceDao) { + this.activeTraceDao = activeTraceDao; + } + + @Override + public List selectAgentStatList(String agentId, Range range) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (range == null) { + throw new NullPointerException("range must not be null"); + } + return this.activeTraceDao.getAgentStatList(agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesLongChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatChartService.java similarity index 62% rename from web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesLongChartBuilder.java rename to web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatChartService.java index e14be8c93..bfebca46f 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesLongChartBuilder.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatChartService.java @@ -1,30 +1,27 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.vo.linechart; - -import com.navercorp.pinpoint.web.util.TimeWindow; - -/** - * @author hyungil.jeong - */ -public class SampledTimeSeriesLongChartBuilder extends SampledTimeSeriesChartBuilder { - - public SampledTimeSeriesLongChartBuilder(DownSampler downSampler, TimeWindow timeWindow) { - super(downSampler, timeWindow); - } - -} +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.chart.AgentStatChartGroup; + +/** + * @author HyunGil Jeong + */ +public interface AgentStatChartService { + AgentStatChartGroup selectAgentChart(String agentId, TimeWindow timeWindow); +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatService.java new file mode 100644 index 000000000..3e66f0791 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/AgentStatService.java @@ -0,0 +1,29 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.web.vo.Range; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +public interface AgentStatService { + List selectAgentStatList(String agentId, Range range); +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/CpuLoadChartService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/CpuLoadChartService.java new file mode 100644 index 000000000..bc039c3b8 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/CpuLoadChartService.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.web.dao.stat.SampledCpuLoadDao; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; +import com.navercorp.pinpoint.web.vo.stat.chart.AgentStatChartGroup; +import com.navercorp.pinpoint.web.vo.stat.chart.CpuLoadChartGroup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Service +public class CpuLoadChartService implements AgentStatChartService { + + private final SampledCpuLoadDao sampledCpuLoadDao; + + @Autowired + public CpuLoadChartService(@Qualifier("sampledCpuLoadDaoFactory") SampledCpuLoadDao sampledCpuLoadDao) { + this.sampledCpuLoadDao = sampledCpuLoadDao; + } + + @Override + public AgentStatChartGroup selectAgentChart(String agentId, TimeWindow timeWindow) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (timeWindow == null) { + throw new NullPointerException("timeWindow must not be null"); + } + List sampledCpuLoads = this.sampledCpuLoadDao.getSampledAgentStatList(agentId, timeWindow); + return new CpuLoadChartGroup(timeWindow, sampledCpuLoads); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/CpuLoadService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/CpuLoadService.java new file mode 100644 index 000000000..961ed1f66 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/CpuLoadService.java @@ -0,0 +1,51 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.web.dao.stat.CpuLoadDao; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Service +public class CpuLoadService implements AgentStatService { + + private final CpuLoadDao cpuLoadDao; + + @Autowired + public CpuLoadService(@Qualifier("cpuLoadDaoFactory") CpuLoadDao cpuLoadDao) { + this.cpuLoadDao = cpuLoadDao; + } + + @Override + public List selectAgentStatList(String agentId, Range range) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (range == null) { + throw new NullPointerException("range must not be null"); + } + return this.cpuLoadDao.getAgentStatList(agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcChartService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcChartService.java new file mode 100644 index 000000000..8f4fe4931 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcChartService.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDao; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; +import com.navercorp.pinpoint.web.vo.stat.chart.AgentStatChartGroup; +import com.navercorp.pinpoint.web.vo.stat.chart.JvmGcChartGroup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Service +public class JvmGcChartService implements AgentStatChartService { + + private final SampledJvmGcDao sampledJvmGcDao; + + @Autowired + public JvmGcChartService(@Qualifier("sampledJvmGcDaoFactory") SampledJvmGcDao sampledJvmGcDao) { + this.sampledJvmGcDao = sampledJvmGcDao; + } + + @Override + public AgentStatChartGroup selectAgentChart(String agentId, TimeWindow timeWindow) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (timeWindow == null) { + throw new NullPointerException("timeWindow must not be null"); + } + List sampledJvmGcs = this.sampledJvmGcDao.getSampledAgentStatList(agentId, timeWindow); + return new JvmGcChartGroup(timeWindow, sampledJvmGcs); + } +} \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcDetailedChartService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcDetailedChartService.java new file mode 100644 index 000000000..9e1ba5bf2 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcDetailedChartService.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDetailedDao; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; +import com.navercorp.pinpoint.web.vo.stat.chart.AgentStatChartGroup; +import com.navercorp.pinpoint.web.vo.stat.chart.JvmGcDetailedChartGroup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Service +public class JvmGcDetailedChartService implements AgentStatChartService { + + private final SampledJvmGcDetailedDao sampledJvmGcDetailedDao; + + @Autowired + public JvmGcDetailedChartService(@Qualifier("sampledJvmGcDetailedDaoFactory") SampledJvmGcDetailedDao sampledJvmGcDetailedDao) { + this.sampledJvmGcDetailedDao = sampledJvmGcDetailedDao; + } + + @Override + public AgentStatChartGroup selectAgentChart(String agentId, TimeWindow timeWindow) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (timeWindow == null) { + throw new NullPointerException("timeWindow must not be null"); + } + List sampledJvmGcDetaileds = this.sampledJvmGcDetailedDao.getSampledAgentStatList(agentId, timeWindow); + return new JvmGcDetailedChartGroup(timeWindow, sampledJvmGcDetaileds); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcDetailedService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcDetailedService.java new file mode 100644 index 000000000..252010f0e --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcDetailedService.java @@ -0,0 +1,51 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcDetailedBo; +import com.navercorp.pinpoint.web.dao.stat.JvmGcDetailedDao; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Service +public class JvmGcDetailedService implements AgentStatService { + + private final JvmGcDetailedDao jvmGcDetailedDao; + + @Autowired + public JvmGcDetailedService(@Qualifier("jvmGcDetailedDaoFactory") JvmGcDetailedDao jvmGcDetailedDao) { + this.jvmGcDetailedDao = jvmGcDetailedDao; + } + + @Override + public List selectAgentStatList(String agentId, Range range) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (range == null) { + throw new NullPointerException("range must not be null"); + } + return this.jvmGcDetailedDao.getAgentStatList(agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentStatServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcService.java similarity index 55% rename from web/src/main/java/com/navercorp/pinpoint/web/service/AgentStatServiceImpl.java rename to web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcService.java index 7362c9284..fab2b7acb 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentStatServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/JvmGcService.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2016 Naver Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,39 +14,38 @@ * limitations under the License. */ -package com.navercorp.pinpoint.web.service; +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; +import com.navercorp.pinpoint.web.dao.stat.JvmGcDao; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; import java.util.List; -import com.navercorp.pinpoint.web.dao.AgentStatDao; -import com.navercorp.pinpoint.web.vo.AgentStat; -import com.navercorp.pinpoint.web.vo.Range; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - /** - * @author harebox - * @author hyungil.jeong + * @author HyunGil Jeong */ @Service -public class AgentStatServiceImpl implements AgentStatService { +public class JvmGcService implements AgentStatService { + + private final JvmGcDao jvmGcDao; @Autowired - private AgentStatDao agentStatDao; + public JvmGcService(@Qualifier("jvmGcDaoFactory") JvmGcDao jvmGcDao) { + this.jvmGcDao = jvmGcDao; + } - public List selectAgentStatList(String agentId, Range range) { + @Override + public List selectAgentStatList(String agentId, Range range) { if (agentId == null) { throw new NullPointerException("agentId must not be null"); } - return agentStatDao.getAgentStatList(agentId, range); - } - - public List selectAggregatedAgentStatList(String agentId, Range range) { - if (agentId == null) { - throw new NullPointerException("agentId must not be null"); + if (range == null) { + throw new NullPointerException("range must not be null"); } - return agentStatDao.getAggregatedAgentStatList(agentId, range); + return this.jvmGcDao.getAgentStatList(agentId, range); } - } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartCompatibilityService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartCompatibilityService.java new file mode 100644 index 000000000..8f64e4346 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartCompatibilityService.java @@ -0,0 +1,95 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.web.dao.stat.LegacyAgentStatDao; +import com.navercorp.pinpoint.web.dao.stat.SampledActiveTraceDao; +import com.navercorp.pinpoint.web.dao.stat.SampledCpuLoadDao; +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDao; +import com.navercorp.pinpoint.web.dao.stat.SampledTransactionDao; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.AgentStat; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.chart.LegacyAgentStatChartGroup; +import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; +import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; +import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Deprecated +@Service +public class LegacyAgentStatChartCompatibilityService implements LegacyAgentStatChartService { + + @Autowired + private LegacyAgentStatDao legacyAgentStatDao; + + @Autowired + @Qualifier("sampledJvmGcDaoV2") + private SampledJvmGcDao sampledJvmGcDao; + + @Autowired + @Qualifier("sampledCpuLoadDaoV2") + private SampledCpuLoadDao sampledCpuLoadDao; + + @Autowired + @Qualifier("sampledTransactionDaoV2") + private SampledTransactionDao sampledTransactionDao; + + @Autowired + @Qualifier("sampledActiveTraceDaoV2") + private SampledActiveTraceDao sampledActiveTraceDao; + + @Override + public LegacyAgentStatChartGroup selectAgentStatList(String agentId, TimeWindow timeWindow) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (timeWindow == null) { + throw new NullPointerException("timeWindow must not be null"); + } + List jvmGcs = sampledJvmGcDao.getSampledAgentStatList(agentId, timeWindow); + if (CollectionUtils.isNotEmpty(jvmGcs)) { + List cpuLoads = sampledCpuLoadDao.getSampledAgentStatList(agentId, timeWindow); + List transactions = sampledTransactionDao.getSampledAgentStatList(agentId, timeWindow); + List activeTraces = sampledActiveTraceDao.getSampledAgentStatList(agentId, timeWindow); + LegacyAgentStatChartGroup.LegacyAgentStatChartGroupBuilder builder = new LegacyAgentStatChartGroup.LegacyAgentStatChartGroupBuilder(timeWindow); + builder.jvmGcs(jvmGcs); + builder.cpuLoads(cpuLoads); + builder.transactions(transactions); + builder.activeTraces(activeTraces); + return builder.build(); + } else { + long scanFrom = timeWindow.getWindowRange().getFrom(); + long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); + Range rangeToScan = new Range(scanFrom, scanTo); + List agentStats = legacyAgentStatDao.getAgentStatList(agentId, rangeToScan); + LegacyAgentStatChartGroup chartGroup = new LegacyAgentStatChartGroup(timeWindow); + chartGroup.addAgentStats(agentStats); + chartGroup.buildCharts(); + return chartGroup; + } + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesDoubleChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartService.java similarity index 62% rename from web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesDoubleChartBuilder.java rename to web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartService.java index eb664985e..97f361b3c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesDoubleChartBuilder.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartService.java @@ -1,30 +1,28 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.vo.linechart; - -import com.navercorp.pinpoint.web.util.TimeWindow; - -/** - * @author hyungil.jeong - */ -public class SampledTimeSeriesDoubleChartBuilder extends SampledTimeSeriesChartBuilder { - - public SampledTimeSeriesDoubleChartBuilder(DownSampler downSampler, TimeWindow timeWindow) { - super(downSampler, timeWindow); - } - -} +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.chart.LegacyAgentStatChartGroup; + +/** + * @author HyunGil Jeong + */ +@Deprecated +public interface LegacyAgentStatChartService { + LegacyAgentStatChartGroup selectAgentStatList(String agentId, TimeWindow timeWindow); +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartServiceFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartServiceFactory.java new file mode 100644 index 000000000..90649f577 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartServiceFactory.java @@ -0,0 +1,73 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +/** + * @author HyunGil Jeong + */ +@Deprecated +@Service("legacyAgentStatChartServiceFactory") +public class LegacyAgentStatChartServiceFactory implements FactoryBean { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Value("#{pinpointWebProps['web.experimental.stat.format.compatibility.version'] ?: 'v1'}") + private String mode = "v1"; + + @Autowired + @Qualifier("legacyAgentStatChartV1Service") + private LegacyAgentStatChartService v1; + + @Autowired + @Qualifier("legacyAgentStatChartV2Service") + private LegacyAgentStatChartService v2; + + @Autowired + @Qualifier("legacyAgentStatChartCompatibilityService") + private LegacyAgentStatChartService compatibility; + + @Override + public LegacyAgentStatChartService getObject() throws Exception { + logger.info("LegacyAgentStatService Compatibility {}", mode); + if (mode.equalsIgnoreCase("v1")) { + return v1; + } else if (mode.equalsIgnoreCase("v2")) { + return v2; + } else if (mode.equalsIgnoreCase("compatibilityMode")) { + return compatibility; + } + return v1; + } + + @Override + public Class getObjectType() { + return LegacyAgentStatChartService.class; + } + + @Override + public boolean isSingleton() { + return true; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartV1Service.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartV1Service.java new file mode 100644 index 000000000..076635700 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartV1Service.java @@ -0,0 +1,56 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.web.dao.stat.LegacyAgentStatDao; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.AgentStat; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.chart.LegacyAgentStatChartGroup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Deprecated +@Service +public class LegacyAgentStatChartV1Service implements LegacyAgentStatChartService { + + @Autowired + private LegacyAgentStatDao legacyAgentStatDao; + + @Override + public LegacyAgentStatChartGroup selectAgentStatList(String agentId, TimeWindow timeWindow) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (timeWindow == null) { + throw new NullPointerException("timeWindow must not be null"); + } + long scanFrom = timeWindow.getWindowRange().getFrom(); + long scanTo = timeWindow.getWindowRange().getTo() + timeWindow.getWindowSlotSize(); + Range rangeToScan = new Range(scanFrom, scanTo); + List agentStats = legacyAgentStatDao.getAgentStatList(agentId, rangeToScan); + LegacyAgentStatChartGroup chartGroup = new LegacyAgentStatChartGroup(timeWindow); + chartGroup.addAgentStats(agentStats); + chartGroup.buildCharts(); + return chartGroup; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartV2Service.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartV2Service.java new file mode 100644 index 000000000..e44f6797d --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/LegacyAgentStatChartV2Service.java @@ -0,0 +1,77 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.web.dao.stat.SampledActiveTraceDao; +import com.navercorp.pinpoint.web.dao.stat.SampledCpuLoadDao; +import com.navercorp.pinpoint.web.dao.stat.SampledJvmGcDao; +import com.navercorp.pinpoint.web.dao.stat.SampledTransactionDao; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.chart.LegacyAgentStatChartGroup; +import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; +import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; +import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Deprecated +@Service +public class LegacyAgentStatChartV2Service implements LegacyAgentStatChartService { + + @Autowired + @Qualifier("sampledJvmGcDaoV2") + private SampledJvmGcDao sampledJvmGcDao; + + @Autowired + @Qualifier("sampledCpuLoadDaoV2") + private SampledCpuLoadDao sampledCpuLoadDao; + + @Autowired + @Qualifier("sampledTransactionDaoV2") + private SampledTransactionDao sampledTransactionDao; + + @Autowired + @Qualifier("sampledActiveTraceDaoV2") + private SampledActiveTraceDao sampledActiveTraceDao; + + @Override + public LegacyAgentStatChartGroup selectAgentStatList(String agentId, TimeWindow timeWindow) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (timeWindow == null) { + throw new NullPointerException("timeWindow must not be null"); + } + List jvmGcs = sampledJvmGcDao.getSampledAgentStatList(agentId, timeWindow); + List cpuLoads = sampledCpuLoadDao.getSampledAgentStatList(agentId, timeWindow); + List transactions = sampledTransactionDao.getSampledAgentStatList(agentId, timeWindow); + List activeTraces = sampledActiveTraceDao.getSampledAgentStatList(agentId, timeWindow); + LegacyAgentStatChartGroup.LegacyAgentStatChartGroupBuilder builder = new LegacyAgentStatChartGroup.LegacyAgentStatChartGroupBuilder(timeWindow); + builder.jvmGcs(jvmGcs); + builder.cpuLoads(cpuLoads); + builder.transactions(transactions); + builder.activeTraces(activeTraces); + return builder.build(); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/TransactionChartService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/TransactionChartService.java new file mode 100644 index 000000000..5998ee403 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/TransactionChartService.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.web.dao.stat.SampledTransactionDao; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; +import com.navercorp.pinpoint.web.vo.stat.chart.AgentStatChartGroup; +import com.navercorp.pinpoint.web.vo.stat.chart.TransactionChartGroup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Service +public class TransactionChartService implements AgentStatChartService { + + private final SampledTransactionDao sampledTransactionDao; + + @Autowired + public TransactionChartService(@Qualifier("sampledTransactionDaoFactory") SampledTransactionDao sampledTransactionDao) { + this.sampledTransactionDao = sampledTransactionDao; + } + + @Override + public AgentStatChartGroup selectAgentChart(String agentId, TimeWindow timeWindow) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (timeWindow == null) { + throw new NullPointerException("timeWindow must not be null"); + } + List sampledTransactions = this.sampledTransactionDao.getSampledAgentStatList(agentId, timeWindow); + return new TransactionChartGroup(timeWindow, sampledTransactions); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/stat/TransactionService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/TransactionService.java new file mode 100644 index 000000000..52eedbe93 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/stat/TransactionService.java @@ -0,0 +1,51 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.service.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.TransactionBo; +import com.navercorp.pinpoint.web.dao.stat.TransactionDao; +import com.navercorp.pinpoint.web.vo.Range; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Service +public class TransactionService implements AgentStatService { + + private final TransactionDao transactionDao; + + @Autowired + public TransactionService(@Qualifier("transactionDaoFactory") TransactionDao transactionDao) { + this.transactionDao = transactionDao; + } + + @Override + public List selectAgentStatList(String agentId, Range range) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (range == null) { + throw new NullPointerException("range must not be null"); + } + return this.transactionDao.getAgentStatList(agentId, range); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/util/AgentStats.java b/web/src/main/java/com/navercorp/pinpoint/web/util/AgentStats.java deleted file mode 100644 index 77c9b347a..000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/util/AgentStats.java +++ /dev/null @@ -1,169 +0,0 @@ -/** - * Copyright 2014 NAVER Corp. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.navercorp.pinpoint.web.util; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import com.navercorp.pinpoint.web.vo.AgentStat; - -/** - * @author Jongho Moon - * - */ -public class AgentStats { - public static final Comparator TIMESTAMP_COMPARATOR = new Comparator() { - - @Override - public int compare(AgentStat o1, AgentStat o2) { - return Long.compare(o1.getTimestamp(), o2.getTimestamp()); - } - }; - - public static List aggregate(List stats, long newInterval) { - return new Aggregator(stats, newInterval).aggregate(); - } - - - private static class Aggregator { - private final List stats; - private final long interval; - - public Aggregator(List stats, long interval) { - this.interval = interval; - this.stats = new ArrayList<>(stats); - Collections.sort(this.stats, TIMESTAMP_COMPARATOR); - } - - public List aggregate() { - if (stats.isEmpty()) { - return stats; - } - - List result = new ArrayList<>(); - AgentStat current = toAggregatedAgentStat(stats.get(0)); - - for (AgentStat stat : stats.subList(1, stats.size())) { - long timestamp = toAggregatedTimestamp(stat, interval); - - if (current.getTimestamp() == timestamp) { - current = merge(current, stat, interval); - } else { - result.add(current); - current = toAggregatedAgentStat(stat); - } - } - - current.setCollectInterval(interval); - result.add(current); - - return result; - } - - private AgentStat toAggregatedAgentStat(AgentStat stat) { - long timestamp = toAggregatedTimestamp(stat, interval); - AgentStat result = new AgentStat(stat.getAgentId(), timestamp); - - result.setCollectInterval(interval); - - result.setGcType(stat.getGcType()); - result.setGcOldCount(stat.getGcOldCount()); - result.setGcOldTime(stat.getGcOldTime()); - - result.setHeapUsed(stat.getHeapUsed()); - result.setHeapMax(stat.getHeapMax()); - - result.setNonHeapUsed(stat.getNonHeapUsed()); - result.setNonHeapMax(stat.getNonHeapMax()); - - result.setJvmCpuUsage(stat.getJvmCpuUsage()); - result.setSystemCpuUsage(stat.getSystemCpuUsage()); - - result.setSampledNewCount(stat.getSampledNewCount()); - result.setSampledContinuationCount(stat.getSampledContinuationCount()); - result.setUnsampledNewCount(stat.getUnsampledNewCount()); - result.setUnsampledContinuationCount(stat.getUnsampledContinuationCount()); - - result.setHistogramSchema(stat.getHistogramSchema()); - result.setActiveTraceCounts(stat.getActiveTraceCounts()); - - return result; - } - - } - - public static long toAggregatedTimestamp(AgentStat stat, long interval) { - long timestamp = (stat.getTimestamp() / interval) * interval; - return timestamp; - } - - public static AgentStat merge(AgentStat s1, AgentStat s2, long interval) { - AgentStat latest = s1.getTimestamp() > s2.getTimestamp() ? s1 : s2; - - AgentStat stat = new AgentStat(s1.getAgentId(), latest.getTimestamp()); - stat.setCollectInterval(interval); - - stat.setGcType(latest.getGcType()); - stat.setGcOldCount(latest.getGcOldCount()); - stat.setGcOldTime(latest.getGcOldTime()); - - stat.setHeapUsed(latest.getHeapUsed()); - stat.setHeapMax(maxValue(s1.getHeapMax(), s2.getHeapMax())); - - stat.setNonHeapUsed(latest.getNonHeapUsed()); - stat.setNonHeapMax(maxValue(s1.getNonHeapMax(), s2.getNonHeapMax())); - - stat.setJvmCpuUsage(latest.getJvmCpuUsage()); - stat.setSystemCpuUsage(latest.getSystemCpuUsage()); - - stat.setSampledNewCount(addValue(s1.getSampledNewCount(), s2.getSampledNewCount())); - stat.setSampledContinuationCount(addValue(s1.getSampledContinuationCount(), s2.getSampledContinuationCount())); - stat.setUnsampledNewCount(addValue(s1.getUnsampledNewCount(), s2.getUnsampledNewCount())); - stat.setUnsampledContinuationCount(addValue(s1.getUnsampledContinuationCount(), s2.getUnsampledContinuationCount())); - - stat.setHistogramSchema(latest.getHistogramSchema()); - stat.setActiveTraceCounts(latest.getActiveTraceCounts()); - - return stat; - } - - private static long addValue(long v1, long v2) { - if (v1 == AgentStat.NOT_COLLECTED) { - if (v2 == AgentStat.NOT_COLLECTED) { - return AgentStat.NOT_COLLECTED; - } else { - return v2; - } - } else { - if (v1 == AgentStat.NOT_COLLECTED) { - return v1; - } else { - return v1 + v2; - } - } - } - - private static long maxValue(long v1, long v2) { - if (v1 == AgentStat.NOT_COLLECTED) { - return v2; - } else if (v2 == AgentStat.NOT_COLLECTED) { - return v1; - } - - return v1 < v2 ? v2 : v1; - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentStat.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentStat.java index 2647d0d37..274bc3bc0 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentStat.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentStat.java @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.web.vo; -import java.io.Serializable; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -26,6 +25,7 @@ import com.navercorp.pinpoint.common.trace.SlotType; /** * @author HyunGil Jeong */ +@Deprecated public class AgentStat { public static final long AGGR_SAMPLE_INTERVAL = TimeUnit.MINUTES.toMillis(10); public static final long RAW_SAMPLE_INTERVAL = TimeUnit.SECONDS.toMillis(5); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/Chart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/Chart.java new file mode 100644 index 000000000..310ac6421 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/Chart.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.chart; + +import java.util.List; + +public class Chart { + + private final List> points; + + Chart(List> points) { + this.points = points; + } + + public List> getPoints() { + return this.points; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Chart chart = (Chart) o; + + return points != null ? points.equals(chart.points) : chart.points == null; + } + + @Override + public int hashCode() { + return points != null ? points.hashCode() : 0; + } + + @Override + public String toString() { + return "Chart{" + + "points=" + points + + '}'; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/DataPoint.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/DataPoint.java similarity index 84% rename from web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/DataPoint.java rename to web/src/main/java/com/navercorp/pinpoint/web/vo/chart/DataPoint.java index 17ec2dddd..de21e06a6 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/DataPoint.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/DataPoint.java @@ -1,45 +1,45 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.vo.linechart; - -/** - * @author hyungil.jeong - */ -public class DataPoint { - - private final X xVal; - private final Y yVal; - - public DataPoint(X xVal, Y yVal) { - this.xVal = xVal; - this.yVal = yVal; - } - - public X getxVal() { - return xVal; - } - - public Y getyVal() { - return yVal; - } - - @Override - public String toString() { - return "(" + xVal + "," + yVal + ")"; - } - -} +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.chart; + +/** + * @author hyungil.jeong + */ +@Deprecated +public class DataPoint { + + private final X xVal; + private final Y yVal; + + public DataPoint(X xVal, Y yVal) { + this.xVal = xVal; + this.yVal = yVal; + } + + public X getXVal() { + return xVal; + } + + public Y getYVal() { + return yVal; + } + + @Override + public String toString() { + return "(" + xVal + "," + yVal + ")"; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacyChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacyChartBuilder.java new file mode 100644 index 000000000..24753f9f0 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacyChartBuilder.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.chart; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Deprecated +public class LegacyChartBuilder, X extends Number, Y extends Number> { + + private final List dataPoints; + + protected LegacyChartBuilder() { + this.dataPoints = new ArrayList<>(); + } + + public void addDataPoint(D dataPoint) { + this.dataPoints.add(dataPoint); + } + + public Chart buildChart() { + List> points = makePoints(this.dataPoints); + return new Chart<>(points); + } + + protected List> makePoints(List dataPoints) { + List> points = new ArrayList<>(dataPoints.size()); + for (D dataPoint : dataPoints) { + points.add(new Point<>(dataPoint.getXVal(), dataPoint.getYVal(), dataPoint.getYVal(), dataPoint.getYVal())); + } + return points; + } + + public int numDataPoints() { + return this.dataPoints.size(); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacySampledChartBuilder.java similarity index 72% rename from web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledChartBuilder.java rename to web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacySampledChartBuilder.java index 312c44031..2c65cf17e 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledChartBuilder.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacySampledChartBuilder.java @@ -1,49 +1,51 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.vo.linechart; - -import java.util.List; - -import com.navercorp.pinpoint.web.vo.linechart.Chart.ChartBuilder; - -/** - * @author hyungil.jeong - */ -public abstract class SampledChartBuilder extends ChartBuilder { - - private final DownSampler downSampler; - - protected SampledChartBuilder(DownSampler downSampler) { - if (downSampler == null) { - throw new NullPointerException("downSampler must not be null"); - } - this.downSampler = downSampler; - } - - protected final Y sampleMin(List sampleBuffer) { - return this.downSampler.sampleMin(sampleBuffer); - } - - protected final Y sampleMax(List sampleBuffer) { - return this.downSampler.sampleMax(sampleBuffer); - } - - protected final Y sampleAvg(List sampleBuffer) { - return this.downSampler.sampleAvg(sampleBuffer); - } - -} +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.chart; + +import java.util.List; + +import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler; + +/** + * @author hyungil.jeong + */ +@Deprecated +public abstract class LegacySampledChartBuilder, X extends Number, Y extends Number> extends LegacyChartBuilder { + + private final DownSampler downSampler; + protected final Y defaultValue; + + protected LegacySampledChartBuilder(DownSampler downSampler) { + if (downSampler == null) { + throw new NullPointerException("downSampler must not be null"); + } + this.downSampler = downSampler; + this.defaultValue = downSampler.getDefaultValue(); + } + + protected final Y sampleMin(List sampleBuffer) { + return this.downSampler.sampleMin(sampleBuffer); + } + + protected final Y sampleMax(List sampleBuffer) { + return this.downSampler.sampleMax(sampleBuffer); + } + + protected final Y sampleAvg(List sampleBuffer) { + return this.downSampler.sampleAvg(sampleBuffer); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacySampledTimeSeriesChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacySampledTimeSeriesChartBuilder.java new file mode 100644 index 000000000..22e7cf5fd --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacySampledTimeSeriesChartBuilder.java @@ -0,0 +1,82 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.chart; + +import java.util.ArrayList; +import java.util.List; + +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler; + +/** + * @author hyungil.jeong + */ +@Deprecated +public class LegacySampledTimeSeriesChartBuilder, Y extends Number> extends LegacySampledChartBuilder { + + private final TimeWindow timeWindow; + + public LegacySampledTimeSeriesChartBuilder(DownSampler downSampler, TimeWindow timeWindow) { + super(downSampler); + if (timeWindow.getWindowRangeCount() > Integer.MAX_VALUE) { + throw new IllegalArgumentException("range yields too many timeslots"); + } + this.timeWindow = timeWindow; + } + + @Override + protected final List> makePoints(List dataPoints) { + List> timeSlots = createTimeSlots(dataPoints); + List> sampledPoints = new ArrayList<>(timeSlots.size()); + int index = 0; + for (Long timestamp : this.timeWindow) { + List samples = timeSlots.get(index); + if (samples.isEmpty()) { + sampledPoints.add(new UncollectedPoint<>(timestamp, this.defaultValue)); + } else { + sampledPoints.add(sampleDataPoints(timestamp, samples)); + } + ++index; + } + return sampledPoints; + } + + protected Point sampleDataPoints(long timestamp, List samples) { + List values = new ArrayList<>(samples.size()); + for (D sample : samples) { + values.add(sample.getYVal()); + } + return new Point<>(timestamp, sampleMin(values), sampleMax(values), sampleAvg(values)); + } + + private List> createTimeSlots(List dataPoints) { + int numTimeSlots = (int) this.timeWindow.getWindowRangeCount(); + List> timeSlots = new ArrayList<>(numTimeSlots); + for (int i = 0; i < numTimeSlots; ++i) { + timeSlots.add(new ArrayList()); + } + for (D dataPoint : dataPoints) { + long timestamp = dataPoint.getXVal(); + int index = this.timeWindow.getWindowIndex(timestamp); + if (index >= 0 && index < timeSlots.size()) { + List timeSlot = timeSlots.get(index); + timeSlot.add(dataPoint); + } + } + return timeSlots; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacySampledTitledTimeSeriesChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacySampledTitledTimeSeriesChartBuilder.java new file mode 100644 index 000000000..965304e34 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/LegacySampledTitledTimeSeriesChartBuilder.java @@ -0,0 +1,44 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.chart; + +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.stat.chart.DownSampler; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author HyunGil Jeong + */ +@Deprecated +public class LegacySampledTitledTimeSeriesChartBuilder extends LegacySampledTimeSeriesChartBuilder, Y> { + + public LegacySampledTitledTimeSeriesChartBuilder(DownSampler downSampler, TimeWindow timeWindow) { + super(downSampler, timeWindow); + } + + @Override + protected Point sampleDataPoints(long timestamp, List> samples) { + String title = samples.get(0).getTitle(); + List values = new ArrayList<>(samples.size()); + for (TitledDataPoint sample : samples) { + values.add(sample.getYVal()); + } + return new TitledPoint<>(title, timestamp, sampleMin(values), sampleMax(values), sampleAvg(values)); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/Point.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/Point.java new file mode 100644 index 000000000..5e68b49ea --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/Point.java @@ -0,0 +1,82 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.chart; + +/** + * @author HyunGil Jeong + */ +public class Point { + private final X xVal; + private final Y minYVal; + private final Y maxYVal; + private final Y avgYVal; + + public Point(X xVal, Y minYVal, Y maxYVal, Y avgYVal) { + this.xVal = xVal; + this.minYVal = minYVal; + this.maxYVal = maxYVal; + this.avgYVal = avgYVal; + } + + public X getxVal() { + return xVal; + } + + public Y getMinYVal() { + return minYVal; + } + + public Y getMaxYVal() { + return maxYVal; + } + + public Y getAvgYVal() { + return avgYVal; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Point point = (Point) o; + + if (xVal != null ? !xVal.equals(point.xVal) : point.xVal != null) return false; + if (minYVal != null ? !minYVal.equals(point.minYVal) : point.minYVal != null) return false; + if (maxYVal != null ? !maxYVal.equals(point.maxYVal) : point.maxYVal != null) return false; + return avgYVal != null ? avgYVal.equals(point.avgYVal) : point.avgYVal == null; + } + + @Override + public int hashCode() { + int result = xVal != null ? xVal.hashCode() : 0; + result = 31 * result + (minYVal != null ? minYVal.hashCode() : 0); + result = 31 * result + (maxYVal != null ? maxYVal.hashCode() : 0); + result = 31 * result + (avgYVal != null ? avgYVal.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "Point{" + + "xVal=" + xVal + + ", minYVal=" + minYVal + + ", maxYVal=" + maxYVal + + ", avgYVal=" + avgYVal + + '}'; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/TimeSeriesChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/TimeSeriesChartBuilder.java new file mode 100644 index 000000000..a120a781a --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/TimeSeriesChartBuilder.java @@ -0,0 +1,55 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.chart; + +import com.navercorp.pinpoint.web.util.TimeWindow; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author HyunGil Jeong + */ +public class TimeSeriesChartBuilder { + + private final TimeWindow timeWindow; + private final List> points; + + public TimeSeriesChartBuilder(TimeWindow timeWindow) { + this(timeWindow, null); + } + + public TimeSeriesChartBuilder(TimeWindow timeWindow, Y uncollectedValue) { + if (timeWindow.getWindowRangeCount() > Integer.MAX_VALUE) { + throw new IllegalArgumentException("range yields too many timeslots"); + } + this.timeWindow = timeWindow; + int numTimeslots = (int) this.timeWindow.getWindowRangeCount(); + this.points = new ArrayList<>(numTimeslots); + for (long timestamp : this.timeWindow) { + this.points.add(new UncollectedPoint<>(timestamp, uncollectedValue)); + } + } + + public Chart build(List> sampledPoints) { + for (Point sampledPoint : sampledPoints) { + int timeslotIndex = this.timeWindow.getWindowIndex(sampledPoint.getxVal()); + this.points.set(timeslotIndex, sampledPoint); + } + return new Chart<>(this.points); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/TitledDataPoint.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/TitledDataPoint.java similarity index 92% rename from web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/TitledDataPoint.java rename to web/src/main/java/com/navercorp/pinpoint/web/vo/chart/TitledDataPoint.java index b2073496c..a9b8c5cb2 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/TitledDataPoint.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/TitledDataPoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 NAVER Corp. + * Copyright 2016 Naver Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,12 @@ * limitations under the License. */ -package com.navercorp.pinpoint.web.vo.linechart; +package com.navercorp.pinpoint.web.vo.chart; /** * @author HyunGil Jeong */ +@Deprecated public class TitledDataPoint extends DataPoint { private final String title; diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/TitledPoint.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/TitledPoint.java new file mode 100644 index 000000000..6c822517e --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/TitledPoint.java @@ -0,0 +1,59 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.chart; + +/** + * @author HyunGil Jeong + */ +public class TitledPoint extends Point { + + private final String title; + + public TitledPoint(String title, X xVal, Y minYVal, Y maxYVal, Y avgYVal) { + super(xVal, minYVal, maxYVal, avgYVal); + this.title = title; + } + + public String getTitle() { + return title; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + TitledPoint that = (TitledPoint) o; + + return title != null ? title.equals(that.title) : that.title == null; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (title != null ? title.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "TitledPoint{" + + "title='" + title + '\'' + + "} " + super.toString(); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/UncollectedPoint.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/UncollectedPoint.java new file mode 100644 index 000000000..459fb3981 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/chart/UncollectedPoint.java @@ -0,0 +1,36 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.chart; + +/** + * @author HyunGil Jeong + */ +public class UncollectedPoint extends Point { + + public UncollectedPoint(X xVal) { + this(xVal, null); + } + + public UncollectedPoint(X xVal, Y uncollectedValue) { + super(xVal, uncollectedValue, uncollectedValue, uncollectedValue); + } + + @Override + public String toString() { + return "UncollectedPoint{" + super.toString() + "}"; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/Chart.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/Chart.java deleted file mode 100644 index 11827413f..000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/Chart.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.vo.linechart; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class Chart { - - private final Points points; - - private Chart(Points points) { - this.points = points; - } - - public List getPoints() { - return this.points.getPoints(); - } - - public static abstract class ChartBuilder { - - protected abstract Points makePoints(List> dataPoints); - - private final List> dataPoints; - - protected ChartBuilder() { - this.dataPoints = new ArrayList<>(); - } - - public void addDataPoint(DataPoint dataPoint) { - this.dataPoints.add(dataPoint); - } - - public Chart buildChart() { - Points points = makePoints(this.dataPoints); - return new Chart(points); - } - - public int numDataPoints() { - return this.dataPoints.size(); - } - - } - - static final class Points { - - private final List points; - - public Points() { - this.points = new ArrayList<>(); - } - - public void addPoint(Point point) { - this.points.add(point); - } - - public List getPoints() { - return Collections.unmodifiableList(this.points); - } - - } - - public static final class Point { - - private final Number timestamp; - private final Number minVal; - private final Number maxVal; - private final Number avgVal; - - public Point(Number timestamp, Number minVal, Number maxVal, Number avgVal) { - this.timestamp = timestamp; - this.minVal = minVal; - this.maxVal = maxVal; - this.avgVal = avgVal; - } - - public Number getTimestamp() { - return timestamp; - } - - public Number getMinVal() { - return minVal; - } - - public Number getMaxVal() { - return maxVal; - } - - public Number getAvgVal() { - return avgVal; - } - - @Override - public String toString() { - return "Point [timestamp=" + timestamp + ", minVal=" + minVal + ", maxVal=" + maxVal + ", avgVal=" + avgVal + "]"; - } - - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataChartBuilder.java deleted file mode 100644 index 82924eceb..000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataChartBuilder.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.vo.linechart; - -import java.util.ArrayList; -import java.util.List; - -import com.navercorp.pinpoint.web.vo.linechart.Chart.Point; -import com.navercorp.pinpoint.web.vo.linechart.Chart.Points; - -/** - * @author hyungil.jeong - */ -public abstract class SampledDataChartBuilder extends SampledChartBuilder { - - private final int sampleRate; - - protected SampledDataChartBuilder(DownSampler downSampler, int sampleRate) { - super(downSampler); - this.sampleRate = sampleRate; - } - - @Override - protected Points makePoints(List> dataPoints) { - Points points = new Points(); - for (int i = 0; i < dataPoints.size(); i += this.sampleRate) { - final int beginIndex = i; - final int endIndex = Math.min(beginIndex + this.sampleRate, dataPoints.size()); - List> sampleDataPoints = dataPoints.subList(beginIndex, endIndex); - points.addPoint(makePoint(sampleDataPoints)); - } - return points; - } - - private Point makePoint(List> sampleDataPoints) { - X xVal = sampleDataPoints.get(sampleDataPoints.size() - 1).getxVal(); - List sampleBuffer = new ArrayList<>(sampleDataPoints.size()); - for (DataPoint sampleDataPoint : sampleDataPoints) { - sampleBuffer.add(sampleDataPoint.getyVal()); - } - Y minVal = sampleMin(sampleBuffer); - Y maxVal = sampleMax(sampleBuffer); - Y avgVal = sampleAvg(sampleBuffer); - return new Point(xVal, minVal, maxVal, avgVal); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesChartBuilder.java deleted file mode 100644 index 9b1c8e988..000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesChartBuilder.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.vo.linechart; - -import java.util.ArrayList; -import java.util.List; - -import com.navercorp.pinpoint.web.util.TimeWindow; -import com.navercorp.pinpoint.web.vo.linechart.Chart.Point; -import com.navercorp.pinpoint.web.vo.linechart.Chart.Points; - -/** - * @author hyungil.jeong - */ -public class SampledTimeSeriesChartBuilder extends SampledChartBuilder { - - private final TimeWindow timeWindow; - private final List> timeslots; - - public SampledTimeSeriesChartBuilder(DownSampler downSampler, TimeWindow timeWindow) { - super(downSampler); - if (timeWindow.getWindowRangeCount() > Integer.MAX_VALUE) { - throw new IllegalArgumentException("range yields too many timeslots"); - } - this.timeWindow = timeWindow; - int numTimeslots = (int) this.timeWindow.getWindowRangeCount(); - this.timeslots = new ArrayList<>(numTimeslots); - initializeTimeslots(numTimeslots); - } - - private void initializeTimeslots(int numTimeslots) { - for (int i = 0; i < numTimeslots; ++i) { - this.timeslots.add(new ArrayList()); - } - } - - @Override - public Points makePoints(List> dataPoints) { - Points points = new Points(); - allocateDataPoints(dataPoints); - int timeSlotIndex = 0; - for (Long timestamp : this.timeWindow) { - List samples = this.timeslots.get(timeSlotIndex); - Point point = new Point(timestamp, sampleMin(samples), sampleMax(samples), sampleAvg(samples)); - points.addPoint(point); - ++timeSlotIndex; - } - return points; - } - - private void allocateDataPoints(List> dataPoints) { - for (DataPoint dataPoint : dataPoints) { - int timeslotIndex = this.timeWindow.getWindowIndex(dataPoint.getxVal()); - if (isValidIndex(timeslotIndex)) { - List timeSlottedDataPoints = this.timeslots.get(timeslotIndex); - timeSlottedDataPoints.add(dataPoint.getyVal()); - } - } - } - - private boolean isValidIndex(int timeslot) { - return timeslot >= 0 && timeslot < this.timeslots.size(); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/agentstat/AgentStatChartGroup.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/agentstat/AgentStatChartGroup.java deleted file mode 100644 index b67cd3309..000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/agentstat/AgentStatChartGroup.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.vo.linechart.agentstat; - -import java.math.BigDecimal; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; - -import com.navercorp.pinpoint.common.trace.HistogramSchema; -import com.navercorp.pinpoint.common.trace.SlotType; -import com.navercorp.pinpoint.web.util.TimeWindow; -import com.navercorp.pinpoint.web.vo.AgentStat; -import com.navercorp.pinpoint.web.vo.linechart.Chart; -import com.navercorp.pinpoint.web.vo.linechart.DataPoint; -import com.navercorp.pinpoint.web.vo.linechart.DownSampler; -import com.navercorp.pinpoint.web.vo.linechart.DownSamplers; -import com.navercorp.pinpoint.web.vo.linechart.SampledTimeSeriesDoubleChartBuilder; -import com.navercorp.pinpoint.web.vo.linechart.SampledTimeSeriesIntegerChartBuilder; -import com.navercorp.pinpoint.web.vo.linechart.SampledTimeSeriesLongChartBuilder; -import com.navercorp.pinpoint.web.vo.linechart.Chart.ChartBuilder; -import com.navercorp.pinpoint.web.vo.linechart.TitledDataPoint; - -/** - * @author harebox - * @author HyunGil Jeong - */ -public class AgentStatChartGroup { - - private enum ChartType { - JVM_MEMORY_HEAP_USED, - JVM_MEMORY_HEAP_MAX, - JVM_MEMORY_NON_HEAP_USED, - JVM_MEMORY_NON_HEAP_MAX, - JVM_GC_OLD_COUNT, - JVM_GC_OLD_TIME, - CPU_LOAD_JVM, - CPU_LOAD_SYSTEM, - TPS_SAMPLED_NEW, - TPS_SAMPLED_CONTINUATION, - TPS_UNSAMPLED_NEW, - TPS_UNSAMPLED_CONTINUATION, - TPS_TOTAL, - ACTIVE_TRACE_FAST, - ACTIVE_TRACE_NORMAL, - ACTIVE_TRACE_SLOW, - ACTIVE_TRACE_VERY_SLOW - } - - private static final int UNCOLLECTED_DATA = AgentStat.NOT_COLLECTED; - private static final DownSampler INTEGER_DOWN_SAMPLER = DownSamplers.getIntegerDownSampler(UNCOLLECTED_DATA); - private static final DownSampler LONG_DOWN_SAMPLER = DownSamplers.getLongDownSampler(UNCOLLECTED_DATA); - private static final DownSampler DOUBLE_DOWN_SAMPLER = DownSamplers.getDoubleDownSampler(UNCOLLECTED_DATA, 1); - - private String type; - - private final Map> chartBuilders; - - private final Map charts; - - public AgentStatChartGroup(TimeWindow timeWindow) { - this.chartBuilders = new EnumMap<>(ChartType.class); - this.chartBuilders.put(ChartType.JVM_MEMORY_HEAP_USED, new SampledTimeSeriesLongChartBuilder(LONG_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.JVM_MEMORY_HEAP_MAX, new SampledTimeSeriesLongChartBuilder(LONG_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.JVM_MEMORY_NON_HEAP_USED, new SampledTimeSeriesLongChartBuilder(LONG_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.JVM_MEMORY_NON_HEAP_MAX, new SampledTimeSeriesLongChartBuilder(LONG_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.JVM_GC_OLD_COUNT, new SampledTimeSeriesLongChartBuilder(LONG_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.JVM_GC_OLD_TIME, new SampledTimeSeriesLongChartBuilder(LONG_DOWN_SAMPLER, timeWindow)); - - this.chartBuilders.put(ChartType.CPU_LOAD_JVM, new SampledTimeSeriesDoubleChartBuilder(DOUBLE_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.CPU_LOAD_SYSTEM, new SampledTimeSeriesDoubleChartBuilder(DOUBLE_DOWN_SAMPLER, timeWindow)); - - this.chartBuilders.put(ChartType.TPS_SAMPLED_NEW, new SampledTimeSeriesDoubleChartBuilder(DOUBLE_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.TPS_SAMPLED_CONTINUATION, new SampledTimeSeriesDoubleChartBuilder(DOUBLE_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.TPS_UNSAMPLED_NEW, new SampledTimeSeriesDoubleChartBuilder(DOUBLE_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.TPS_UNSAMPLED_CONTINUATION, new SampledTimeSeriesDoubleChartBuilder(DOUBLE_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.TPS_TOTAL, new SampledTimeSeriesDoubleChartBuilder(DOUBLE_DOWN_SAMPLER, timeWindow)); - - this.chartBuilders.put(ChartType.ACTIVE_TRACE_FAST, new SampledTimeSeriesIntegerChartBuilder(INTEGER_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.ACTIVE_TRACE_NORMAL, new SampledTimeSeriesIntegerChartBuilder(INTEGER_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.ACTIVE_TRACE_SLOW, new SampledTimeSeriesIntegerChartBuilder(INTEGER_DOWN_SAMPLER, timeWindow)); - this.chartBuilders.put(ChartType.ACTIVE_TRACE_VERY_SLOW, new SampledTimeSeriesIntegerChartBuilder(INTEGER_DOWN_SAMPLER, timeWindow)); - this.charts = new EnumMap<>(ChartType.class); - } - - public void addAgentStats(List agentStats) { - for (AgentStat agentStat : agentStats) { - if (agentStat != null) { - addMemoryGcData(agentStat); - addCpuLoadData(agentStat); - addTransactionData(agentStat); - addActiveTraceData(agentStat); - } - } - } - - public void buildCharts() { - for (ChartType chartType : ChartType.values()) { - this.charts.put(chartType, this.chartBuilders.get(chartType).buildChart()); - } - } - - private void addMemoryGcData(AgentStat agentStat) { - this.type = agentStat.getGcType(); - long timestamp = agentStat.getTimestamp(); - ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_HEAP_USED)).addDataPoint(new DataPoint<>(timestamp, agentStat.getHeapUsed())); - ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_HEAP_MAX)).addDataPoint(new DataPoint<>(timestamp, agentStat.getHeapMax())); - ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_NON_HEAP_USED)).addDataPoint(new DataPoint<>(timestamp, agentStat.getNonHeapUsed())); - ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_NON_HEAP_MAX)).addDataPoint(new DataPoint<>(timestamp, agentStat.getNonHeapMax())); - ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_GC_OLD_COUNT)).addDataPoint(new DataPoint<>(timestamp, agentStat.getGcOldCount())); - ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_GC_OLD_TIME)).addDataPoint(new DataPoint<>(timestamp, agentStat.getGcOldTime())); - } - - private void addCpuLoadData(AgentStat agentStat) { - long timestamp = agentStat.getTimestamp(); - double jvmCpuUsagePercentage = agentStat.getJvmCpuUsage() * 100; - double systemCpuUsagePercentage = agentStat.getSystemCpuUsage() * 100; - ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.CPU_LOAD_JVM)).addDataPoint(new DataPoint<>(timestamp, jvmCpuUsagePercentage)); - ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.CPU_LOAD_SYSTEM)).addDataPoint(new DataPoint<>(timestamp, systemCpuUsagePercentage)); - } - - private void addTransactionData(AgentStat agentStat) { - long timestamp = agentStat.getTimestamp(); - long interval = agentStat.getCollectInterval(); - if (interval > 0) { - double sampledNewTps = calculateTps(agentStat.getSampledNewCount(), interval); - double sampledContinuationTps = calculateTps(agentStat.getSampledContinuationCount(), interval); - double unsampledNewTps = calculateTps(agentStat.getUnsampledNewCount(), interval); - double unsampledContinuationTps = calculateTps(agentStat.getUnsampledContinuationCount(), interval); - double totalTps = sampledNewTps + sampledContinuationTps + unsampledNewTps + unsampledContinuationTps; - ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_SAMPLED_NEW)).addDataPoint(new DataPoint<>(timestamp, sampledNewTps)); - ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_SAMPLED_CONTINUATION)).addDataPoint(new DataPoint<>(timestamp, sampledContinuationTps)); - ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_UNSAMPLED_NEW)).addDataPoint(new DataPoint<>(timestamp, unsampledNewTps)); - ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_UNSAMPLED_CONTINUATION)).addDataPoint(new DataPoint<>(timestamp, unsampledContinuationTps)); - ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_TOTAL)).addDataPoint(new DataPoint<>(timestamp, totalTps)); - } - } - - private void addActiveTraceData(AgentStat agentStat) { - long timestamp = agentStat.getTimestamp(); - HistogramSchema schema = agentStat.getHistogramSchema(); - if (schema != null) { - Map activeTraceCounts = agentStat.getActiveTraceCounts(); - - DataPoint fastDataPoint = new TitledDataPoint<>(schema.getFastSlot().getSlotName(), timestamp, activeTraceCounts.get(SlotType.FAST)); - ((SampledTimeSeriesIntegerChartBuilder) this.chartBuilders.get(ChartType.ACTIVE_TRACE_FAST)).addDataPoint(fastDataPoint); - - DataPoint normalDataPoint = new TitledDataPoint<>(schema.getNormalSlot().getSlotName(), timestamp, activeTraceCounts.get(SlotType.NORMAL)); - ((SampledTimeSeriesIntegerChartBuilder) this.chartBuilders.get(ChartType.ACTIVE_TRACE_NORMAL)).addDataPoint(normalDataPoint); - - DataPoint slowDataPoint = new TitledDataPoint<>(schema.getSlowSlot().getSlotName(), timestamp, activeTraceCounts.get(SlotType.SLOW)); - ((SampledTimeSeriesIntegerChartBuilder) this.chartBuilders.get(ChartType.ACTIVE_TRACE_SLOW)).addDataPoint(slowDataPoint); - - DataPoint verySlowDataPoint = new TitledDataPoint<>(schema.getVerySlowSlot().getSlotName(), timestamp, activeTraceCounts.get(SlotType.VERY_SLOW)); - ((SampledTimeSeriesIntegerChartBuilder) this.chartBuilders.get(ChartType.ACTIVE_TRACE_VERY_SLOW)).addDataPoint(verySlowDataPoint); - } - } - - private double calculateTps(long count, long intervalMs) { - final int numDecimal = 1; - if (count == UNCOLLECTED_DATA) { - return UNCOLLECTED_DATA; - } - return new BigDecimal(count / (intervalMs / 1000D)).setScale(numDecimal, BigDecimal.ROUND_HALF_UP).doubleValue(); - } - - public String getType() { - return type; - } - - public Map getCharts() { - return charts; - } -} \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/JvmGc.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/JvmGc.java new file mode 100644 index 000000000..e8b7c739d --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/JvmGc.java @@ -0,0 +1,130 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat; + +/** + * @author HyunGil Jeong + */ +public class JvmGc { + + private final String agentId; + private final long timestamp; + + private long heapUsed; + private long heapMax; + private long nonHeapUsed; + private long nonHeapMax; + private long gcOldCount; + private long gcOldTime; + + public JvmGc(String agentId, long timestamp) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + this.agentId = agentId; + this.timestamp = timestamp; + } + + public String getAgentId() { + return agentId; + } + + public long getTimestamp() { + return timestamp; + } + + public long getHeapUsed() { + return heapUsed; + } + + public void setHeapUsed(long heapUsed) { + this.heapUsed = heapUsed; + } + + public long getHeapMax() { + return heapMax; + } + + public void setHeapMax(long heapMax) { + this.heapMax = heapMax; + } + + public long getNonHeapUsed() { + return nonHeapUsed; + } + + public void setNonHeapUsed(long nonHeapUsed) { + this.nonHeapUsed = nonHeapUsed; + } + + public long getNonHeapMax() { + return nonHeapMax; + } + + public void setNonHeapMax(long nonHeapMax) { + this.nonHeapMax = nonHeapMax; + } + + public long getGcOldCount() { + return gcOldCount; + } + + public void setGcOldCount(long gcOldCount) { + this.gcOldCount = gcOldCount; + } + + public long getGcOldTime() { + return gcOldTime; + } + + public void setGcOldTime(long gcOldTime) { + this.gcOldTime = gcOldTime; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JvmGc jvmGc = (JvmGc) o; + + if (timestamp != jvmGc.timestamp) return false; + return agentId.equals(jvmGc.agentId); + + } + + @Override + public int hashCode() { + int result = agentId.hashCode(); + result = 31 * result + (int) (timestamp ^ (timestamp >>> 32)); + return result; + } + + @Override + public String toString() { + return "JvmGc{" + + "agentId='" + agentId + '\'' + + ", timestamp=" + timestamp + + ", heapUsed=" + heapUsed + + ", heapMax=" + heapMax + + ", nonHeapUsed=" + nonHeapUsed + + ", nonHeapMax=" + nonHeapMax + + ", gcOldCount=" + gcOldCount + + ", gcOldTime=" + gcOldTime + + '}'; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledActiveTrace.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledActiveTrace.java new file mode 100644 index 000000000..cb454cf7e --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledActiveTrace.java @@ -0,0 +1,94 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat; + +import com.navercorp.pinpoint.web.vo.chart.TitledPoint; + +/** + * @author HyunGil Jeong + */ +public class SampledActiveTrace implements SampledAgentStatDataPoint { + + private TitledPoint fastCounts; + private TitledPoint normalCounts; + private TitledPoint slowCounts; + private TitledPoint verySlowCounts; + + public TitledPoint getFastCounts() { + return fastCounts; + } + + public void setFastCounts(TitledPoint fastCounts) { + this.fastCounts = fastCounts; + } + + public TitledPoint getNormalCounts() { + return normalCounts; + } + + public void setNormalCounts(TitledPoint normalCounts) { + this.normalCounts = normalCounts; + } + + public TitledPoint getSlowCounts() { + return slowCounts; + } + + public void setSlowCounts(TitledPoint slowCounts) { + this.slowCounts = slowCounts; + } + + public TitledPoint getVerySlowCounts() { + return verySlowCounts; + } + + public void setVerySlowCounts(TitledPoint verySlowCounts) { + this.verySlowCounts = verySlowCounts; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SampledActiveTrace that = (SampledActiveTrace) o; + + if (fastCounts != null ? !fastCounts.equals(that.fastCounts) : that.fastCounts != null) return false; + if (normalCounts != null ? !normalCounts.equals(that.normalCounts) : that.normalCounts != null) return false; + if (slowCounts != null ? !slowCounts.equals(that.slowCounts) : that.slowCounts != null) return false; + return verySlowCounts != null ? verySlowCounts.equals(that.verySlowCounts) : that.verySlowCounts == null; + } + + @Override + public int hashCode() { + int result = fastCounts != null ? fastCounts.hashCode() : 0; + result = 31 * result + (normalCounts != null ? normalCounts.hashCode() : 0); + result = 31 * result + (slowCounts != null ? slowCounts.hashCode() : 0); + result = 31 * result + (verySlowCounts != null ? verySlowCounts.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "SampledActiveTrace{" + + "fastCounts=" + fastCounts + + ", normalCounts=" + normalCounts + + ", slowCounts=" + slowCounts + + ", verySlowCounts=" + verySlowCounts + + '}'; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledAgentStatDataPoint.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledAgentStatDataPoint.java new file mode 100644 index 000000000..6f478edc6 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledAgentStatDataPoint.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat; + +/** + * @author HyunGil Jeong + */ +public interface SampledAgentStatDataPoint { + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledCpuLoad.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledCpuLoad.java new file mode 100644 index 000000000..8d2b8ba32 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledCpuLoad.java @@ -0,0 +1,70 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat; + +import com.navercorp.pinpoint.web.vo.chart.Point; + +/** + * @author HyunGil Jeong + */ +public class SampledCpuLoad implements SampledAgentStatDataPoint { + + private Point jvmCpuLoad; + private Point systemCpuLoad; + + public Point getJvmCpuLoad() { + return jvmCpuLoad; + } + + public void setJvmCpuLoad(Point jvmCpuLoad) { + this.jvmCpuLoad = jvmCpuLoad; + } + + public Point getSystemCpuLoad() { + return systemCpuLoad; + } + + public void setSystemCpuLoad(Point systemCpuLoad) { + this.systemCpuLoad = systemCpuLoad; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SampledCpuLoad that = (SampledCpuLoad) o; + + if (jvmCpuLoad != null ? !jvmCpuLoad.equals(that.jvmCpuLoad) : that.jvmCpuLoad != null) return false; + return systemCpuLoad != null ? systemCpuLoad.equals(that.systemCpuLoad) : that.systemCpuLoad == null; + } + + @Override + public int hashCode() { + int result = jvmCpuLoad != null ? jvmCpuLoad.hashCode() : 0; + result = 31 * result + (systemCpuLoad != null ? systemCpuLoad.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "SampledCpuLoad{" + + "jvmCpuLoad=" + jvmCpuLoad + + ", systemCpuLoad=" + systemCpuLoad + + '}'; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGc.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGc.java new file mode 100644 index 000000000..d40fd32cc --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGc.java @@ -0,0 +1,118 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat; + +import com.navercorp.pinpoint.web.vo.chart.Point; + +/** + * @author HyunGil Jeong + */ +public class SampledJvmGc implements SampledAgentStatDataPoint { + + private Point heapUsed; + private Point heapMax; + private Point nonHeapUsed; + private Point nonHeapMax; + private Point gcOldCount; + private Point gcOldTime; + + public Point getHeapUsed() { + return heapUsed; + } + + public void setHeapUsed(Point heapUsed) { + this.heapUsed = heapUsed; + } + + public Point getHeapMax() { + return heapMax; + } + + public void setHeapMax(Point heapMax) { + this.heapMax = heapMax; + } + + public Point getNonHeapUsed() { + return nonHeapUsed; + } + + public void setNonHeapUsed(Point nonHeapUsed) { + this.nonHeapUsed = nonHeapUsed; + } + + public Point getNonHeapMax() { + return nonHeapMax; + } + + public void setNonHeapMax(Point nonHeapMax) { + this.nonHeapMax = nonHeapMax; + } + + public Point getGcOldCount() { + return gcOldCount; + } + + public void setGcOldCount(Point gcOldCount) { + this.gcOldCount = gcOldCount; + } + + public Point getGcOldTime() { + return gcOldTime; + } + + public void setGcOldTime(Point gcOldTime) { + this.gcOldTime = gcOldTime; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SampledJvmGc that = (SampledJvmGc) o; + + if (heapUsed != null ? !heapUsed.equals(that.heapUsed) : that.heapUsed != null) return false; + if (heapMax != null ? !heapMax.equals(that.heapMax) : that.heapMax != null) return false; + if (nonHeapUsed != null ? !nonHeapUsed.equals(that.nonHeapUsed) : that.nonHeapUsed != null) return false; + if (nonHeapMax != null ? !nonHeapMax.equals(that.nonHeapMax) : that.nonHeapMax != null) return false; + if (gcOldCount != null ? !gcOldCount.equals(that.gcOldCount) : that.gcOldCount != null) return false; + return gcOldTime != null ? gcOldTime.equals(that.gcOldTime) : that.gcOldTime == null; + } + + @Override + public int hashCode() { + int result = heapUsed != null ? heapUsed.hashCode() : 0; + result = 31 * result + (heapMax != null ? heapMax.hashCode() : 0); + result = 31 * result + (nonHeapUsed != null ? nonHeapUsed.hashCode() : 0); + result = 31 * result + (nonHeapMax != null ? nonHeapMax.hashCode() : 0); + result = 31 * result + (gcOldCount != null ? gcOldCount.hashCode() : 0); + result = 31 * result + (gcOldTime != null ? gcOldTime.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "SampledJvmGc{" + + "heapUsed=" + heapUsed + + ", heapMax=" + heapMax + + ", nonHeapUsed=" + nonHeapUsed + + ", nonHeapMax=" + nonHeapMax + + ", gcOldCount=" + gcOldCount + + ", gcOldTime=" + gcOldTime + + '}'; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGcDetailed.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGcDetailed.java new file mode 100644 index 000000000..076f768bf --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledJvmGcDetailed.java @@ -0,0 +1,144 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat; + +import com.navercorp.pinpoint.web.vo.chart.Point; + +/** + * @author HyunGil Jeong + */ +public class SampledJvmGcDetailed implements SampledAgentStatDataPoint { + + private Point gcNewCount; + private Point gcNewTime; + private Point codeCacheUsed; + private Point newGenUsed; + private Point oldGenUsed; + private Point survivorSpaceUsed; + private Point permGenUsed; + private Point metaspaceUsed; + + public Point getGcNewCount() { + return gcNewCount; + } + + public void setGcNewCount(Point gcNewCount) { + this.gcNewCount = gcNewCount; + } + + public Point getGcNewTime() { + return gcNewTime; + } + + public void setGcNewTime(Point gcNewTime) { + this.gcNewTime = gcNewTime; + } + + public Point getCodeCacheUsed() { + return codeCacheUsed; + } + + public void setCodeCacheUsed(Point codeCacheUsed) { + this.codeCacheUsed = codeCacheUsed; + } + + public Point getNewGenUsed() { + return newGenUsed; + } + + public void setNewGenUsed(Point newGenUsed) { + this.newGenUsed = newGenUsed; + } + + public Point getOldGenUsed() { + return oldGenUsed; + } + + public void setOldGenUsed(Point oldGenUsed) { + this.oldGenUsed = oldGenUsed; + } + + public Point getSurvivorSpaceUsed() { + return survivorSpaceUsed; + } + + public void setSurvivorSpaceUsed(Point survivorSpaceUsed) { + this.survivorSpaceUsed = survivorSpaceUsed; + } + + public Point getPermGenUsed() { + return permGenUsed; + } + + public void setPermGenUsed(Point permGenUsed) { + this.permGenUsed = permGenUsed; + } + + public Point getMetaspaceUsed() { + return metaspaceUsed; + } + + public void setMetaspaceUsed(Point metaspaceUsed) { + this.metaspaceUsed = metaspaceUsed; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SampledJvmGcDetailed that = (SampledJvmGcDetailed) o; + + if (gcNewCount != null ? !gcNewCount.equals(that.gcNewCount) : that.gcNewCount != null) return false; + if (gcNewTime != null ? !gcNewTime.equals(that.gcNewTime) : that.gcNewTime != null) return false; + if (codeCacheUsed != null ? !codeCacheUsed.equals(that.codeCacheUsed) : that.codeCacheUsed != null) + return false; + if (newGenUsed != null ? !newGenUsed.equals(that.newGenUsed) : that.newGenUsed != null) return false; + if (oldGenUsed != null ? !oldGenUsed.equals(that.oldGenUsed) : that.oldGenUsed != null) return false; + if (survivorSpaceUsed != null ? !survivorSpaceUsed.equals(that.survivorSpaceUsed) : that.survivorSpaceUsed != null) + return false; + if (permGenUsed != null ? !permGenUsed.equals(that.permGenUsed) : that.permGenUsed != null) return false; + return metaspaceUsed != null ? metaspaceUsed.equals(that.metaspaceUsed) : that.metaspaceUsed == null; + } + + @Override + public int hashCode() { + int result = gcNewCount != null ? gcNewCount.hashCode() : 0; + result = 31 * result + (gcNewTime != null ? gcNewTime.hashCode() : 0); + result = 31 * result + (codeCacheUsed != null ? codeCacheUsed.hashCode() : 0); + result = 31 * result + (newGenUsed != null ? newGenUsed.hashCode() : 0); + result = 31 * result + (oldGenUsed != null ? oldGenUsed.hashCode() : 0); + result = 31 * result + (survivorSpaceUsed != null ? survivorSpaceUsed.hashCode() : 0); + result = 31 * result + (permGenUsed != null ? permGenUsed.hashCode() : 0); + result = 31 * result + (metaspaceUsed != null ? metaspaceUsed.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "SampledJvmGcDetailed{" + + "gcNewCount=" + gcNewCount + + ", gcNewTime=" + gcNewTime + + ", codeCacheUsed=" + codeCacheUsed + + ", newGenUsed=" + newGenUsed + + ", oldGenUsed=" + oldGenUsed + + ", survivorSpaceUsed=" + survivorSpaceUsed + + ", permGenUsed=" + permGenUsed + + ", metaspaceUsed=" + metaspaceUsed + + '}'; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledTransaction.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledTransaction.java new file mode 100644 index 000000000..d7a65a910 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/SampledTransaction.java @@ -0,0 +1,108 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat; + +import com.navercorp.pinpoint.web.vo.chart.Point; + +/** + * @author HyunGil Jeong + */ +public class SampledTransaction implements SampledAgentStatDataPoint { + + private Point sampledNew; + private Point sampledContinuation; + private Point unsampledNew; + private Point unsampledContinuation; + private Point total; + + public Point getSampledNew() { + return sampledNew; + } + + public void setSampledNew(Point sampledNew) { + this.sampledNew = sampledNew; + } + + public Point getSampledContinuation() { + return sampledContinuation; + } + + public void setSampledContinuation(Point sampledContinuation) { + this.sampledContinuation = sampledContinuation; + } + + public Point getUnsampledNew() { + return unsampledNew; + } + + public void setUnsampledNew(Point unsampledNew) { + this.unsampledNew = unsampledNew; + } + + public Point getUnsampledContinuation() { + return unsampledContinuation; + } + + public void setUnsampledContinuation(Point unsampledContinuation) { + this.unsampledContinuation = unsampledContinuation; + } + + public Point getTotal() { + return total; + } + + public void setTotal(Point total) { + this.total = total; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SampledTransaction that = (SampledTransaction) o; + + if (sampledNew != null ? !sampledNew.equals(that.sampledNew) : that.sampledNew != null) return false; + if (sampledContinuation != null ? !sampledContinuation.equals(that.sampledContinuation) : that.sampledContinuation != null) + return false; + if (unsampledNew != null ? !unsampledNew.equals(that.unsampledNew) : that.unsampledNew != null) return false; + if (unsampledContinuation != null ? !unsampledContinuation.equals(that.unsampledContinuation) : that.unsampledContinuation != null) + return false; + return total != null ? total.equals(that.total) : that.total == null; + } + + @Override + public int hashCode() { + int result = sampledNew != null ? sampledNew.hashCode() : 0; + result = 31 * result + (sampledContinuation != null ? sampledContinuation.hashCode() : 0); + result = 31 * result + (unsampledNew != null ? unsampledNew.hashCode() : 0); + result = 31 * result + (unsampledContinuation != null ? unsampledContinuation.hashCode() : 0); + result = 31 * result + (total != null ? total.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "SampledTransaction{" + + "sampledNew=" + sampledNew + + ", sampledContinuation=" + sampledContinuation + + ", unsampledNew=" + unsampledNew + + ", unsampledContinuation=" + unsampledContinuation + + ", total=" + total + + '}'; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/ActiveTraceChartGroup.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/ActiveTraceChartGroup.java new file mode 100644 index 000000000..64af378f8 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/ActiveTraceChartGroup.java @@ -0,0 +1,68 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat.chart; + +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.chart.Chart; +import com.navercorp.pinpoint.web.vo.chart.Point; +import com.navercorp.pinpoint.web.vo.chart.TimeSeriesChartBuilder; +import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author HyunGil Jeong + */ +public class ActiveTraceChartGroup implements AgentStatChartGroup { + + private static final Integer UNCOLLECTED_VALUE = -1; + + private final Map activeTraceCharts; + + public enum ActiveTraceChartType implements ChartType { + ACTIVE_TRACE_VERY_SLOW, + ACTIVE_TRACE_SLOW, + ACTIVE_TRACE_NORMAL, + ACTIVE_TRACE_FAST + } + + public ActiveTraceChartGroup(TimeWindow timeWindow, List sampledActiveTraces) { + this.activeTraceCharts = new HashMap<>(); + List> fastCounts = new ArrayList<>(sampledActiveTraces.size()); + List> normalCounts = new ArrayList<>(sampledActiveTraces.size()); + List> slowCounts = new ArrayList<>(sampledActiveTraces.size()); + List> verySlowCounts = new ArrayList<>(sampledActiveTraces.size()); + for (SampledActiveTrace sampledActiveTrace : sampledActiveTraces) { + fastCounts.add(sampledActiveTrace.getFastCounts()); + normalCounts.add(sampledActiveTrace.getNormalCounts()); + slowCounts.add(sampledActiveTrace.getSlowCounts()); + verySlowCounts.add(sampledActiveTrace.getVerySlowCounts()); + } + activeTraceCharts.put(ActiveTraceChartType.ACTIVE_TRACE_FAST, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(fastCounts)); + activeTraceCharts.put(ActiveTraceChartType.ACTIVE_TRACE_NORMAL, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(normalCounts)); + activeTraceCharts.put(ActiveTraceChartType.ACTIVE_TRACE_SLOW, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(slowCounts)); + activeTraceCharts.put(ActiveTraceChartType.ACTIVE_TRACE_VERY_SLOW, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(verySlowCounts)); + } + + @Override + public Map getCharts() { + return this.activeTraceCharts; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataLongChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/AgentStatChartGroup.java similarity index 63% rename from web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataLongChartBuilder.java rename to web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/AgentStatChartGroup.java index 046614419..bf8f7fbb4 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataLongChartBuilder.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/AgentStatChartGroup.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 NAVER Corp. + * Copyright 2016 Naver Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,18 @@ * limitations under the License. */ -package com.navercorp.pinpoint.web.vo.linechart; +package com.navercorp.pinpoint.web.vo.stat.chart; + +import com.navercorp.pinpoint.web.vo.chart.Chart; + +import java.util.Map; /** - * @author hyungil.jeong + * @author HyunGil Jeong */ -public final class SampledDataLongChartBuilder extends SampledDataChartBuilder { +public interface AgentStatChartGroup { - public SampledDataLongChartBuilder(DownSampler downSampler, int sampleRate) { - super(downSampler, sampleRate); - } + interface ChartType {} + Map getCharts(); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/CpuLoadChartGroup.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/CpuLoadChartGroup.java new file mode 100644 index 000000000..449253426 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/CpuLoadChartGroup.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat.chart; + +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.chart.Chart; +import com.navercorp.pinpoint.web.vo.chart.Point; +import com.navercorp.pinpoint.web.vo.chart.TimeSeriesChartBuilder; +import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author HyunGil Jeong + */ +public class CpuLoadChartGroup implements AgentStatChartGroup { + + private static final Double UNCOLLECTED_PERCENTAGE = -1D; + + private final Map cpuLoadCharts; + + public enum CpuLoadChartType implements ChartType { + CPU_LOAD_JVM, + CPU_LOAD_SYSTEM + } + + public CpuLoadChartGroup(TimeWindow timeWindow, List sampledCpuLoads) { + this.cpuLoadCharts = new HashMap<>(); + List> jvmCpuLoads = new ArrayList<>(sampledCpuLoads.size()); + List> systemCpuLoads = new ArrayList(sampledCpuLoads.size()); + for (SampledCpuLoad sampledCpuLoad : sampledCpuLoads) { + jvmCpuLoads.add(sampledCpuLoad.getJvmCpuLoad()); + systemCpuLoads.add(sampledCpuLoad.getSystemCpuLoad()); + } + this.cpuLoadCharts.put(CpuLoadChartType.CPU_LOAD_JVM, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_PERCENTAGE).build(jvmCpuLoads)); + this.cpuLoadCharts.put(CpuLoadChartType.CPU_LOAD_SYSTEM, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_PERCENTAGE).build(systemCpuLoads)); + } + + @Override + public Map getCharts() { + return this.cpuLoadCharts; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/DownSampler.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/DownSampler.java new file mode 100644 index 000000000..4fa831ccc --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/DownSampler.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat.chart; + +import java.util.Collection; + +/** + * @author harebox + * @author HyunGil Jeong + */ +public interface DownSampler { + + T getDefaultValue(); + + T sampleMin(Collection values); + + T sampleAvg(Collection values); + + T sampleMax(Collection values); + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/DownSamplers.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/DownSamplers.java similarity index 96% rename from web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/DownSamplers.java rename to web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/DownSamplers.java index d4bd2a44b..d1317c0df 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/DownSamplers.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/DownSamplers.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2016 Naver Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.navercorp.pinpoint.web.vo.linechart; +package com.navercorp.pinpoint.web.vo.stat.chart; import java.math.BigDecimal; import java.math.RoundingMode; @@ -58,6 +58,10 @@ public class DownSamplers { this.defaultValue = defaultValue; } + @Override + public T getDefaultValue() { + return this.defaultValue; + } } private static class IntegerDownSampler extends AbstractDownSampler { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/JvmGcChartGroup.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/JvmGcChartGroup.java new file mode 100644 index 000000000..f599269d4 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/JvmGcChartGroup.java @@ -0,0 +1,76 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat.chart; + +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.chart.Chart; +import com.navercorp.pinpoint.web.vo.chart.Point; +import com.navercorp.pinpoint.web.vo.chart.TimeSeriesChartBuilder; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author HyunGil Jeong + */ +public class JvmGcChartGroup implements AgentStatChartGroup { + + private static final Long UNCOLLECTED_VALUE = -1L; + + private final Map jvmGcCharts; + + public enum JvmGcChartType implements ChartType { + JVM_MEMORY_HEAP_USED, + JVM_MEMORY_HEAP_MAX, + JVM_MEMORY_NON_HEAP_USED, + JVM_MEMORY_NON_HEAP_MAX, + JVM_GC_OLD_COUNT, + JVM_GC_OLD_TIME + } + + public JvmGcChartGroup(TimeWindow timeWindow, List sampledJvmGcs) { + this.jvmGcCharts = new HashMap<>(); + List> heapUseds = new ArrayList<>(sampledJvmGcs.size()); + List> heapMaxes = new ArrayList<>(sampledJvmGcs.size()); + List> nonHeapUseds = new ArrayList<>(sampledJvmGcs.size()); + List> nonHeapMaxes = new ArrayList<>(sampledJvmGcs.size()); + List> gcOldCounts = new ArrayList<>(sampledJvmGcs.size()); + List> gcOldTimes = new ArrayList<>(sampledJvmGcs.size()); + for (SampledJvmGc sampledJvmGc : sampledJvmGcs) { + heapUseds.add(sampledJvmGc.getHeapUsed()); + heapMaxes.add(sampledJvmGc.getHeapMax()); + nonHeapUseds.add(sampledJvmGc.getNonHeapUsed()); + nonHeapMaxes.add(sampledJvmGc.getNonHeapMax()); + gcOldCounts.add(sampledJvmGc.getGcOldCount()); + gcOldTimes.add(sampledJvmGc.getGcOldTime()); + } + jvmGcCharts.put(JvmGcChartType.JVM_MEMORY_HEAP_USED, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(heapUseds)); + jvmGcCharts.put(JvmGcChartType.JVM_MEMORY_HEAP_MAX, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(heapMaxes)); + jvmGcCharts.put(JvmGcChartType.JVM_MEMORY_NON_HEAP_USED, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(nonHeapUseds)); + jvmGcCharts.put(JvmGcChartType.JVM_MEMORY_NON_HEAP_MAX, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(nonHeapMaxes)); + jvmGcCharts.put(JvmGcChartType.JVM_GC_OLD_COUNT, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(gcOldCounts)); + jvmGcCharts.put(JvmGcChartType.JVM_GC_OLD_TIME, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(gcOldTimes)); + } + + @Override + public Map getCharts() { + return this.jvmGcCharts; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/JvmGcDetailedChartGroup.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/JvmGcDetailedChartGroup.java new file mode 100644 index 000000000..ef8ae8c84 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/JvmGcDetailedChartGroup.java @@ -0,0 +1,85 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat.chart; + +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.chart.Chart; +import com.navercorp.pinpoint.web.vo.chart.Point; +import com.navercorp.pinpoint.web.vo.chart.TimeSeriesChartBuilder; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGcDetailed; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author HyunGil Jeong + */ +public class JvmGcDetailedChartGroup implements AgentStatChartGroup{ + + private static final Long UNCOLLECTED_VALUE = -1L; + private static final Double UNCOLLECTED_PERCENTAGE = -1D; + + private final Map jvmGcDetailedCharts; + + public enum JvmGcDetailedChartType implements ChartType { + JVM_DETAILED_GC_NEW_COUNT, + JVM_DETAILED_GC_NEW_TIME, + JVM_DETAILED_CODE_CACHE_USED, + JVM_DETAILED_NEW_GEN_USED, + JVM_DETAILED_OLD_GEN_USED, + JVM_DETAILED_SURVIVOR_SPACE_USED, + JVM_DETAILED_PERM_GEN_USED, + JVM_DETAILED_METASPACE_USED + } + + public JvmGcDetailedChartGroup(TimeWindow timeWindow, List sampledJvmGcDetaileds) { + this.jvmGcDetailedCharts = new HashMap<>(); + List> gcNewCounts = new ArrayList<>(sampledJvmGcDetaileds.size()); + List> gcNewTimes = new ArrayList<>(sampledJvmGcDetaileds.size()); + List> codeCacheUseds = new ArrayList<>(sampledJvmGcDetaileds.size()); + List> newGenUseds = new ArrayList<>(sampledJvmGcDetaileds.size()); + List> oldGenUseds = new ArrayList<>(sampledJvmGcDetaileds.size()); + List> survivorSpaceUseds = new ArrayList<>(sampledJvmGcDetaileds.size()); + List> permGenUseds = new ArrayList<>(sampledJvmGcDetaileds.size()); + List> metaspaceUseds = new ArrayList<>(sampledJvmGcDetaileds.size()); + for (SampledJvmGcDetailed sampledJvmGcDetailed : sampledJvmGcDetaileds) { + gcNewCounts.add(sampledJvmGcDetailed.getGcNewCount()); + gcNewTimes.add(sampledJvmGcDetailed.getGcNewTime()); + codeCacheUseds.add(sampledJvmGcDetailed.getCodeCacheUsed()); + newGenUseds.add(sampledJvmGcDetailed.getNewGenUsed()); + oldGenUseds.add(sampledJvmGcDetailed.getOldGenUsed()); + survivorSpaceUseds.add(sampledJvmGcDetailed.getSurvivorSpaceUsed()); + permGenUseds.add(sampledJvmGcDetailed.getPermGenUsed()); + metaspaceUseds.add(sampledJvmGcDetailed.getMetaspaceUsed()); + } + this.jvmGcDetailedCharts.put(JvmGcDetailedChartType.JVM_DETAILED_GC_NEW_COUNT, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(gcNewCounts)); + this.jvmGcDetailedCharts.put(JvmGcDetailedChartType.JVM_DETAILED_GC_NEW_TIME, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_VALUE).build(gcNewTimes)); + this.jvmGcDetailedCharts.put(JvmGcDetailedChartType.JVM_DETAILED_CODE_CACHE_USED, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_PERCENTAGE).build(codeCacheUseds)); + this.jvmGcDetailedCharts.put(JvmGcDetailedChartType.JVM_DETAILED_NEW_GEN_USED, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_PERCENTAGE).build(newGenUseds)); + this.jvmGcDetailedCharts.put(JvmGcDetailedChartType.JVM_DETAILED_OLD_GEN_USED, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_PERCENTAGE).build(oldGenUseds)); + this.jvmGcDetailedCharts.put(JvmGcDetailedChartType.JVM_DETAILED_SURVIVOR_SPACE_USED, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_PERCENTAGE).build(survivorSpaceUseds)); + this.jvmGcDetailedCharts.put(JvmGcDetailedChartType.JVM_DETAILED_PERM_GEN_USED, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_PERCENTAGE).build(permGenUseds)); + this.jvmGcDetailedCharts.put(JvmGcDetailedChartType.JVM_DETAILED_METASPACE_USED, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_PERCENTAGE).build(metaspaceUseds)); + } + + @Override + public Map getCharts() { + return this.jvmGcDetailedCharts; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/LegacyAgentStatChartGroup.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/LegacyAgentStatChartGroup.java new file mode 100644 index 000000000..445977635 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/LegacyAgentStatChartGroup.java @@ -0,0 +1,306 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat.chart; + +import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatUtils; +import com.navercorp.pinpoint.common.trace.HistogramSchema; +import com.navercorp.pinpoint.common.trace.SlotType; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.AgentStat; +import com.navercorp.pinpoint.web.vo.chart.LegacySampledTimeSeriesChartBuilder; +import com.navercorp.pinpoint.web.vo.chart.Chart; +import com.navercorp.pinpoint.web.vo.chart.DataPoint; +import com.navercorp.pinpoint.web.vo.chart.LegacySampledTitledTimeSeriesChartBuilder; +import com.navercorp.pinpoint.web.vo.chart.TitledDataPoint; +import com.navercorp.pinpoint.web.vo.stat.SampledActiveTrace; +import com.navercorp.pinpoint.web.vo.stat.SampledCpuLoad; +import com.navercorp.pinpoint.web.vo.stat.SampledJvmGc; +import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; +import org.apache.commons.collections.CollectionUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author harebox + * @author HyunGil Jeong + */ +@Deprecated +public class LegacyAgentStatChartGroup implements AgentStatChartGroup { + + public enum AgentStatChartType implements ChartType { + JVM_MEMORY_HEAP_USED, + JVM_MEMORY_HEAP_MAX, + JVM_MEMORY_NON_HEAP_USED, + JVM_MEMORY_NON_HEAP_MAX, + JVM_GC_OLD_COUNT, + JVM_GC_OLD_TIME, + CPU_LOAD_JVM, + CPU_LOAD_SYSTEM, + TPS_SAMPLED_NEW, + TPS_SAMPLED_CONTINUATION, + TPS_UNSAMPLED_NEW, + TPS_UNSAMPLED_CONTINUATION, + TPS_TOTAL, + ACTIVE_TRACE_FAST, + ACTIVE_TRACE_NORMAL, + ACTIVE_TRACE_SLOW, + ACTIVE_TRACE_VERY_SLOW + } + + private static final int UNCOLLECTED_DATA = AgentStat.NOT_COLLECTED; + private static final DownSampler INTEGER_DOWN_SAMPLER = DownSamplers.getIntegerDownSampler(UNCOLLECTED_DATA); + private static final DownSampler LONG_DOWN_SAMPLER = DownSamplers.getLongDownSampler(UNCOLLECTED_DATA); + private static final DownSampler DOUBLE_DOWN_SAMPLER = DownSamplers.getDoubleDownSampler(UNCOLLECTED_DATA, 1); + + private String type; + + private LegacySampledTimeSeriesChartBuilder, Long> heapUsedChartBuilder; + private LegacySampledTimeSeriesChartBuilder, Long> heapMaxChartBuilder; + private LegacySampledTimeSeriesChartBuilder, Long> nonHeapUsedChartBuilder; + private LegacySampledTimeSeriesChartBuilder, Long> nonHeapMaxChartBuilder; + private LegacySampledTimeSeriesChartBuilder, Long> gcOldCountChartBuilder; + private LegacySampledTimeSeriesChartBuilder, Long> gcOldTimeChartBuilder; + + private LegacySampledTimeSeriesChartBuilder, Double> jvmCpuLoadChartBuilder; + private LegacySampledTimeSeriesChartBuilder, Double> systemCpuLoadChartBuilder; + + private LegacySampledTimeSeriesChartBuilder, Double> tpsSampledNewChartBuilder; + private LegacySampledTimeSeriesChartBuilder, Double> tpsSampledContinuationChartBuilder; + private LegacySampledTimeSeriesChartBuilder, Double> tpsUnsampledNewChartBuilder; + private LegacySampledTimeSeriesChartBuilder, Double> tpsUnsampledContinuationChartBuilder; + private LegacySampledTimeSeriesChartBuilder, Double> tpsTotalChartBuilder; + + private LegacySampledTitledTimeSeriesChartBuilder activeTraceFastChartBuilder; + private LegacySampledTitledTimeSeriesChartBuilder activeTraceNormalChartBuilder; + private LegacySampledTitledTimeSeriesChartBuilder activeTraceSlowChartBuilder; + private LegacySampledTitledTimeSeriesChartBuilder activeTraceVerySlowChartBuilder; + + private final Map charts; + + private LegacyAgentStatChartGroup(Map charts) { + this.charts = charts; + } + + public LegacyAgentStatChartGroup(TimeWindow timeWindow) { + this.charts = new HashMap<>(); + + this.heapUsedChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(LONG_DOWN_SAMPLER, timeWindow); + this.heapMaxChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(LONG_DOWN_SAMPLER, timeWindow); + this.nonHeapUsedChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(LONG_DOWN_SAMPLER, timeWindow); + this.nonHeapMaxChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(LONG_DOWN_SAMPLER, timeWindow); + this.gcOldCountChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(LONG_DOWN_SAMPLER, timeWindow); + this.gcOldTimeChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(LONG_DOWN_SAMPLER, timeWindow); + + this.jvmCpuLoadChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(DOUBLE_DOWN_SAMPLER, timeWindow); + this.systemCpuLoadChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(DOUBLE_DOWN_SAMPLER, timeWindow); + + this.tpsSampledNewChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(DOUBLE_DOWN_SAMPLER, timeWindow); + this.tpsSampledContinuationChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(DOUBLE_DOWN_SAMPLER, timeWindow); + this.tpsUnsampledNewChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(DOUBLE_DOWN_SAMPLER, timeWindow); + this.tpsUnsampledContinuationChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(DOUBLE_DOWN_SAMPLER, timeWindow); + this.tpsTotalChartBuilder = new LegacySampledTimeSeriesChartBuilder<>(DOUBLE_DOWN_SAMPLER, timeWindow); + + this.activeTraceFastChartBuilder = new LegacySampledTitledTimeSeriesChartBuilder<>(INTEGER_DOWN_SAMPLER, timeWindow); + this.activeTraceNormalChartBuilder = new LegacySampledTitledTimeSeriesChartBuilder<>(INTEGER_DOWN_SAMPLER, timeWindow); + this.activeTraceSlowChartBuilder = new LegacySampledTitledTimeSeriesChartBuilder<>(INTEGER_DOWN_SAMPLER, timeWindow); + this.activeTraceVerySlowChartBuilder = new LegacySampledTitledTimeSeriesChartBuilder<>(INTEGER_DOWN_SAMPLER, timeWindow); + } + + public void addAgentStats(List agentStats) { + for (AgentStat agentStat : agentStats) { + if (agentStat != null) { + addMemoryGcData(agentStat); + addCpuLoadData(agentStat); + addTransactionData(agentStat); + addActiveTraceData(agentStat); + } + } + } + + public void buildCharts() { + if (this.charts.isEmpty()) { + this.charts.put(AgentStatChartType.JVM_MEMORY_HEAP_USED, this.heapUsedChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.JVM_MEMORY_HEAP_MAX, this.heapMaxChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.JVM_MEMORY_NON_HEAP_USED, this.nonHeapUsedChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.JVM_MEMORY_NON_HEAP_MAX, this.nonHeapMaxChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.JVM_GC_OLD_COUNT, this.gcOldCountChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.JVM_GC_OLD_TIME, this.gcOldTimeChartBuilder.buildChart()); + + this.charts.put(AgentStatChartType.CPU_LOAD_JVM, this.jvmCpuLoadChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.CPU_LOAD_SYSTEM, this.systemCpuLoadChartBuilder.buildChart()); + + this.charts.put(AgentStatChartType.TPS_SAMPLED_NEW, this.tpsSampledNewChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.TPS_SAMPLED_CONTINUATION, this.tpsSampledContinuationChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.TPS_UNSAMPLED_NEW, this.tpsUnsampledNewChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.TPS_UNSAMPLED_CONTINUATION, this.tpsUnsampledContinuationChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.TPS_TOTAL, this.tpsTotalChartBuilder.buildChart()); + + this.charts.put(AgentStatChartType.ACTIVE_TRACE_FAST, this.activeTraceFastChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.ACTIVE_TRACE_NORMAL, this.activeTraceNormalChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.ACTIVE_TRACE_SLOW, this.activeTraceSlowChartBuilder.buildChart()); + this.charts.put(AgentStatChartType.ACTIVE_TRACE_VERY_SLOW, this.activeTraceVerySlowChartBuilder.buildChart()); + } + } + + private void addMemoryGcData(AgentStat agentStat) { + this.type = agentStat.getGcType(); + long timestamp = agentStat.getTimestamp(); + if (agentStat.getHeapUsed() != UNCOLLECTED_DATA) { + this.heapUsedChartBuilder.addDataPoint(new DataPoint<>(timestamp, agentStat.getHeapUsed())); + } + if (agentStat.getHeapMax() != UNCOLLECTED_DATA) { + this.heapMaxChartBuilder.addDataPoint(new DataPoint<>(timestamp, agentStat.getHeapMax())); + } + if (agentStat.getNonHeapUsed() != UNCOLLECTED_DATA) { + this.nonHeapUsedChartBuilder.addDataPoint(new DataPoint<>(timestamp, agentStat.getNonHeapUsed())); + } + if (agentStat.getNonHeapMax() != UNCOLLECTED_DATA) { + this.nonHeapMaxChartBuilder.addDataPoint(new DataPoint<>(timestamp, agentStat.getNonHeapMax())); + } + if (agentStat.getGcOldCount() != UNCOLLECTED_DATA) { + this.gcOldCountChartBuilder.addDataPoint(new DataPoint<>(timestamp, agentStat.getGcOldCount())); + } + if (agentStat.getGcOldTime() != UNCOLLECTED_DATA) { + this.gcOldTimeChartBuilder.addDataPoint(new DataPoint<>(timestamp, agentStat.getGcOldTime())); + } + } + + private void addCpuLoadData(AgentStat agentStat) { + long timestamp = agentStat.getTimestamp(); + if (agentStat.getJvmCpuUsage() != UNCOLLECTED_DATA) { + double jvmCpuUsage = agentStat.getJvmCpuUsage(); + this.jvmCpuLoadChartBuilder.addDataPoint(new DataPoint<>(timestamp, jvmCpuUsage * 100)); + } + if (agentStat.getSystemCpuUsage() != UNCOLLECTED_DATA) { + double systemCpuUsage = agentStat.getSystemCpuUsage(); + this.systemCpuLoadChartBuilder.addDataPoint(new DataPoint<>(timestamp, systemCpuUsage * 100)); + } + } + + private void addTransactionData(AgentStat agentStat) { + long timestamp = agentStat.getTimestamp(); + long interval = agentStat.getCollectInterval(); + if (interval > 0) { + boolean isTransactionCollected = false; + long total = 0; + if (agentStat.getSampledNewCount() != UNCOLLECTED_DATA) { + isTransactionCollected = true; + double sampledNewTps = calculateTps(agentStat.getSampledNewCount(), interval); + this.tpsSampledNewChartBuilder.addDataPoint(new DataPoint<>(timestamp, sampledNewTps)); + total += agentStat.getSampledNewCount(); + } + if (agentStat.getSampledContinuationCount() != UNCOLLECTED_DATA) { + isTransactionCollected = true; + double sampledContinuationTps = calculateTps(agentStat.getSampledContinuationCount(), interval); + this.tpsSampledContinuationChartBuilder.addDataPoint(new DataPoint<>(timestamp, sampledContinuationTps)); + total += agentStat.getSampledContinuationCount(); + } + if (agentStat.getUnsampledNewCount() != UNCOLLECTED_DATA) { + isTransactionCollected = true; + double unsampledNewTps = calculateTps(agentStat.getUnsampledNewCount(), interval); + this.tpsUnsampledNewChartBuilder.addDataPoint(new DataPoint<>(timestamp, unsampledNewTps)); + total += agentStat.getUnsampledNewCount(); + } + if (agentStat.getUnsampledContinuationCount() != UNCOLLECTED_DATA) { + isTransactionCollected = true; + double unsampledContinuationTps = calculateTps(agentStat.getUnsampledContinuationCount(), interval); + this.tpsUnsampledContinuationChartBuilder.addDataPoint(new DataPoint<>(timestamp, unsampledContinuationTps)); + total += agentStat.getUnsampledContinuationCount(); + } + if (isTransactionCollected) { + double totalTps = calculateTps(total, interval); + this.tpsTotalChartBuilder.addDataPoint(new DataPoint<>(timestamp, totalTps)); + } + } + } + + private void addActiveTraceData(AgentStat agentStat) { + long timestamp = agentStat.getTimestamp(); + HistogramSchema schema = agentStat.getHistogramSchema(); + if (schema != null) { + Map activeTraceCounts = agentStat.getActiveTraceCounts(); + + TitledDataPoint fastDataPoint = new TitledDataPoint<>(schema.getFastSlot().getSlotName(), timestamp, activeTraceCounts.get(SlotType.FAST)); + this.activeTraceFastChartBuilder.addDataPoint(fastDataPoint); + + TitledDataPoint normalDataPoint = new TitledDataPoint<>(schema.getNormalSlot().getSlotName(), timestamp, activeTraceCounts.get(SlotType.NORMAL)); + this.activeTraceNormalChartBuilder.addDataPoint(normalDataPoint); + + TitledDataPoint slowDataPoint = new TitledDataPoint<>(schema.getSlowSlot().getSlotName(), timestamp, activeTraceCounts.get(SlotType.SLOW)); + this.activeTraceSlowChartBuilder.addDataPoint(slowDataPoint); + + TitledDataPoint verySlowDataPoint = new TitledDataPoint<>(schema.getVerySlowSlot().getSlotName(), timestamp, activeTraceCounts.get(SlotType.VERY_SLOW)); + this.activeTraceVerySlowChartBuilder.addDataPoint(verySlowDataPoint); + } + } + + private double calculateTps(long count, long intervalMs) { + final int numDecimal = 1; + return AgentStatUtils.calculateRate(count, intervalMs, numDecimal, UNCOLLECTED_DATA); + } + + public String getType() { + return type; + } + + public Map getCharts() { + return charts; + } + + public static class LegacyAgentStatChartGroupBuilder { + private final TimeWindow timeWindow; + private List jvmGcs; + private List cpuLoads; + private List transactions; + private List activeTraces; + + public LegacyAgentStatChartGroupBuilder(TimeWindow timeWindow) { + this.timeWindow = timeWindow; + } + + public LegacyAgentStatChartGroupBuilder jvmGcs(List jvmGcs) { + this.jvmGcs = jvmGcs; + return this; + } + + public LegacyAgentStatChartGroupBuilder cpuLoads(List cpuLoads) { + this.cpuLoads = cpuLoads; + return this; + } + + public LegacyAgentStatChartGroupBuilder transactions(List transactions) { + this.transactions = transactions; + return this; + } + + public LegacyAgentStatChartGroupBuilder activeTraces(List activeTraces) { + this.activeTraces = activeTraces; + return this; + } + + public LegacyAgentStatChartGroup build() { + Map charts = new HashMap<>(); + charts.putAll(new JvmGcChartGroup(this.timeWindow, this.jvmGcs).getCharts()); + charts.putAll(new CpuLoadChartGroup(this.timeWindow, this.cpuLoads).getCharts()); + charts.putAll(new TransactionChartGroup(this.timeWindow, this.transactions).getCharts()); + charts.putAll(new ActiveTraceChartGroup(this.timeWindow, this.activeTraces).getCharts()); + return new LegacyAgentStatChartGroup(charts); + } + } +} \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/TransactionChartGroup.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/TransactionChartGroup.java new file mode 100644 index 000000000..09a450d27 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/stat/chart/TransactionChartGroup.java @@ -0,0 +1,72 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.vo.stat.chart; + +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.vo.chart.Chart; +import com.navercorp.pinpoint.web.vo.chart.Point; +import com.navercorp.pinpoint.web.vo.chart.TimeSeriesChartBuilder; +import com.navercorp.pinpoint.web.vo.stat.SampledTransaction; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author HyunGil Jeong + */ +public class TransactionChartGroup implements AgentStatChartGroup { + + private static final Double UNCOLLECTED_TPS = -1D; + + private final Map transactionCharts; + + public enum TransactionChartType implements ChartType { + TPS_SAMPLED_NEW, + TPS_SAMPLED_CONTINUATION, + TPS_UNSAMPLED_NEW, + TPS_UNSAMPLED_CONTINUATION, + TPS_TOTAL + } + + public TransactionChartGroup(TimeWindow timeWindow, List sampledTransactions) { + this.transactionCharts = new HashMap<>(); + List> sampledNewTps = new ArrayList<>(sampledTransactions.size()); + List> sampledContinuationTps = new ArrayList<>(sampledTransactions.size()); + List> unsampledNewTps = new ArrayList<>(sampledTransactions.size()); + List> unsampledContinuationTps = new ArrayList<>(sampledTransactions.size()); + List> totalTps = new ArrayList<>(); + for (SampledTransaction sampledTransaction : sampledTransactions) { + sampledNewTps.add(sampledTransaction.getSampledNew()); + sampledContinuationTps.add(sampledTransaction.getSampledContinuation()); + unsampledNewTps.add(sampledTransaction.getUnsampledNew()); + unsampledContinuationTps.add(sampledTransaction.getUnsampledContinuation()); + totalTps.add(sampledTransaction.getTotal()); + } + transactionCharts.put(TransactionChartType.TPS_SAMPLED_NEW, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_TPS).build(sampledNewTps)); + transactionCharts.put(TransactionChartType.TPS_SAMPLED_CONTINUATION, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_TPS).build(sampledContinuationTps)); + transactionCharts.put(TransactionChartType.TPS_UNSAMPLED_NEW, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_TPS).build(unsampledNewTps)); + transactionCharts.put(TransactionChartType.TPS_UNSAMPLED_CONTINUATION, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_TPS).build(unsampledContinuationTps)); + transactionCharts.put(TransactionChartType.TPS_TOTAL, new TimeSeriesChartBuilder<>(timeWindow, UNCOLLECTED_TPS).build(totalTps)); + } + + @Override + public Map getCharts() { + return this.transactionCharts; + } +} diff --git a/web/src/main/resources-local/log4j.xml b/web/src/main/resources-local/log4j.xml index 04f4aaaa4..8360e12b6 100644 --- a/web/src/main/resources-local/log4j.xml +++ b/web/src/main/resources-local/log4j.xml @@ -49,12 +49,6 @@ - - - - - - diff --git a/web/src/main/resources-release/log4j.xml b/web/src/main/resources-release/log4j.xml index 509e1f479..2550b664f 100644 --- a/web/src/main/resources-release/log4j.xml +++ b/web/src/main/resources-release/log4j.xml @@ -48,12 +48,6 @@ - - - - - - diff --git a/web/src/main/resources/applicationContext-hbase.xml b/web/src/main/resources/applicationContext-hbase.xml index 4cc22ce84..1608a9dcd 100644 --- a/web/src/main/resources/applicationContext-hbase.xml +++ b/web/src/main/resources/applicationContext-hbase.xml @@ -85,12 +85,22 @@ + + + + + + + + + + diff --git a/web/src/main/resources/applicationContext-web.xml b/web/src/main/resources/applicationContext-web.xml index 7e1317bd7..b5a1fe8ba 100644 --- a/web/src/main/resources/applicationContext-web.xml +++ b/web/src/main/resources/applicationContext-web.xml @@ -27,7 +27,8 @@ com.navercorp.pinpoint.web.filter, com.navercorp.pinpoint.web.config, com.navercorp.pinpoint.web.view, - com.navercorp.pinpoint.common.server.bo" /> + com.navercorp.pinpoint.common.server.bo, + com.navercorp.pinpoint.common.server.util" /> diff --git a/web/src/main/resources/pinpoint-web.properties b/web/src/main/resources/pinpoint-web.properties index c5fb27483..b0f34e10b 100644 --- a/web/src/main/resources/pinpoint-web.properties +++ b/web/src/main/resources/pinpoint-web.properties @@ -38,4 +38,8 @@ web.activethread.activeAgent.duration.days=7 # span.binary format compatibility = v1 or v2 (WARNING : experimental feature) # experimental feature span format v2 : https://github.com/naver/pinpoint/issues/1819 -web.experimental.span.format.compatibility.version=v1 \ No newline at end of file +web.experimental.span.format.compatibility.version=v1 + +# stat handling compatibility = v1 or v2 or compatibilityMode (WARNING : experimental feature) +# experimental feature AgentStat data format v1 : https://github.com/naver/pinpoint/issues/1533 +web.experimental.stat.format.compatibility.version=v1 \ No newline at end of file diff --git a/web/src/main/webapp/common/services/agent-dao.service.js b/web/src/main/webapp/common/services/agent-dao.service.js index 1ce02a92c..9ae127cee 100644 --- a/web/src/main/webapp/common/services/agent-dao.service.js +++ b/web/src/main/webapp/common/services/agent-dao.service.js @@ -73,14 +73,14 @@ for (var i = 0; i < pointsCount.length; ++i) { var thisData = { - time: moment(pointsTime[i].timestamp).format( cfg.dateFormat ) + time: moment(pointsTime[i].xVal).format( cfg.dateFormat ) }; for (var k in info.line) { if (info.line[k].isFgc) { var gcCount = 0; var gcTime = 0; - currTime = pointsTime[i].maxVal; - currCount = pointsCount[i].maxVal; + currTime = pointsTime[i].maxYVal; + currCount = pointsCount[i].maxYVal; if (!prevTime || !prevCount) { prevTime = currTime; prevCount = currCount; @@ -107,7 +107,7 @@ thisData[info.line[k].key+"Time"] = gcTime; } } else { - var value = agentStat.charts[info.line[k].id].points[i].maxVal; + var value = agentStat.charts[info.line[k].id].points[i].maxYVal; if ( value >= 0 ) { thisData[info.line[k].key] = value; } @@ -144,15 +144,15 @@ } for (var i = 0; i < pointsJvmCpuLoad.length; ++i) { - if (pointsJvmCpuLoad[i].timestamp !== pointsSystemCpuLoad[i].timestamp) { + if (pointsJvmCpuLoad[i].xVal !== pointsSystemCpuLoad[i].xVal) { throw new Error('assertion error', 'timestamp mismatch between jvmCpuLoad and systemCpuLoad'); } var thisData = { - time: moment(pointsJvmCpuLoad[i].timestamp).format( cfg.dateFormat ), + time: moment(pointsJvmCpuLoad[i].xVal).format( cfg.dateFormat ), maxCpuLoad: 100 }; - var jvmCpuLoad = typeof agentStat.charts['CPU_LOAD_JVM'].points[i].maxVal == "number" ? agentStat.charts['CPU_LOAD_JVM'].points[i].maxVal.toFixed(2) : 0.00; - var systemCpuLoad = typeof agentStat.charts['CPU_LOAD_SYSTEM'].points[i].maxVal == "number" ? agentStat.charts['CPU_LOAD_SYSTEM'].points[i].maxVal.toFixed(2) : 0.00; + var jvmCpuLoad = typeof agentStat.charts['CPU_LOAD_JVM'].points[i].maxYVal == "number" ? agentStat.charts['CPU_LOAD_JVM'].points[i].maxYVal.toFixed(2) : 0.00; + var systemCpuLoad = typeof agentStat.charts['CPU_LOAD_SYSTEM'].points[i].maxYVal == "number" ? agentStat.charts['CPU_LOAD_SYSTEM'].points[i].maxYVal.toFixed(2) : 0.00; if ( jvmCpuLoad >= 0 ) { thisData.jvmCpuLoad = jvmCpuLoad; } @@ -189,13 +189,13 @@ for ( var i = 0 ; i < tpsLength ; i++ ) { var thisData = { - time: moment(aSampledContinuationData[i].timestamp).format( cfg.dateFormat ) + time: moment(aSampledContinuationData[i].xVal).format( cfg.dateFormat ) }; - var sampledContinuationTps = typeof aSampledContinuationData[i].avgVal == "number" ? aSampledContinuationData[i].avgVal.toFixed(2) : 0.00; - var sampledNewTps = typeof aSampledNewData[i].avgVal == "number" ? aSampledNewData[i].avgVal.toFixed(2) : 0.00; - var unsampledContinuationTps = typeof aUnsampledContinuationData[i].avgVal == "number" ? aUnsampledContinuationData[i].avgVal.toFixed(2) : 0.00; - var unsampledNewTps = typeof aUnsampledNewData[i].avgVal == "number" ? aUnsampledNewData[i].avgVal.toFixed(2) : 0.00; - var totalTps = typeof aTotalData[i].avgVal == "number" ? aTotalData[i].avgVal.toFixed(2) : 0.00; + var sampledContinuationTps = typeof aSampledContinuationData[i].avgYVal == "number" ? aSampledContinuationData[i].avgYVal.toFixed(2) : 0.00; + var sampledNewTps = typeof aSampledNewData[i].avgYVal == "number" ? aSampledNewData[i].avgYVal.toFixed(2) : 0.00; + var unsampledContinuationTps = typeof aUnsampledContinuationData[i].avgYVal == "number" ? aUnsampledContinuationData[i].avgYVal.toFixed(2) : 0.00; + var unsampledNewTps = typeof aUnsampledNewData[i].avgYVal == "number" ? aUnsampledNewData[i].avgYVal.toFixed(2) : 0.00; + var totalTps = typeof aTotalData[i].avgYVal == "number" ? aTotalData[i].avgYVal.toFixed(2) : 0.00; if ( sampledContinuationTps != DATA_UNAVAILABLE ) { thisData.sampledContinuationTps = sampledContinuationTps; } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/GcCountCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/GcCountCheckerTest.java index 04842832b..167f187bb 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/GcCountCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/GcCountCheckerTest.java @@ -16,15 +16,17 @@ package com.navercorp.pinpoint.web.alarm.checker; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; import org.junit.BeforeClass; -import com.navercorp.pinpoint.web.dao.AgentStatDao; +import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; -import com.navercorp.pinpoint.web.vo.AgentStat; import com.navercorp.pinpoint.web.vo.Application; import com.navercorp.pinpoint.web.vo.Range; @@ -36,28 +38,25 @@ public class GcCountCheckerTest { private static ApplicationIndexDao applicationIndexDao; - private static AgentStatDao agentStatDao; + private static AgentStatDao jvmGcDao; + + private static AgentStatDao cpuLoadDao; @BeforeClass public static void before() { - agentStatDao = new AgentStatDao() { + jvmGcDao = new AgentStatDao() { @Override - public List getAgentStatList(String agentId, Range range) { - List agentStatList = new LinkedList(); + public List getAgentStatList(String agentId, Range range) { + List jvmGcs = new LinkedList<>(); for (int i = 36; i > 0; i--) { - AgentStat stat = new AgentStat("AGENT_NAME", 1L); - stat.setGcOldCount(i); - agentStatList.add(stat); + JvmGcBo jvmGc = new JvmGcBo(); + jvmGc.setGcOldCount(i); + jvmGcs.add(jvmGc); } - return agentStatList; - } - - @Override - public List getAggregatedAgentStatList(String agentId, Range range) { - return getAgentStatList(agentId, range); + return jvmGcs; } @Override @@ -66,6 +65,19 @@ public class GcCountCheckerTest { } }; + cpuLoadDao = new AgentStatDao() { + + @Override + public List getAgentStatList(String agentId, Range range) { + return Collections.emptyList(); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + return false; + } + }; + applicationIndexDao = new ApplicationIndexDao() { @Override @@ -107,7 +119,7 @@ public class GcCountCheckerTest { // public void checkTest1() { // Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.GC_COUNT.getName(), 35, "testGroup", false, false, ""); // Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); -// AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); +// AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, jvmGcDao, cpuLoadDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); // AgentChecker checker = new GcCountChecker(collector, rule); // // checker.check(); @@ -118,7 +130,7 @@ public class GcCountCheckerTest { // public void checkTest2() { // Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.GC_COUNT.getName(), 36, "testGroup", false, false, ""); // Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); -// AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); +// AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, jvmGcDao, cpuLoadDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); // AgentChecker checker = new GcCountChecker(collector, rule); // // checker.check(); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/HeapUsageRateCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/HeapUsageRateCheckerTest.java index 8c7197b77..b2c4a6b14 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/HeapUsageRateCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/HeapUsageRateCheckerTest.java @@ -19,10 +19,13 @@ package com.navercorp.pinpoint.web.alarm.checker; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; import org.junit.BeforeClass; import org.junit.Test; @@ -32,9 +35,8 @@ import com.navercorp.pinpoint.web.alarm.DataCollectorFactory; import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; import com.navercorp.pinpoint.web.alarm.collector.AgentStatDataCollector; import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.dao.AgentStatDao; +import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; -import com.navercorp.pinpoint.web.vo.AgentStat; import com.navercorp.pinpoint.web.vo.Application; import com.navercorp.pinpoint.web.vo.Range; @@ -45,30 +47,26 @@ public class HeapUsageRateCheckerTest { private static ApplicationIndexDao applicationIndexDao; - private static AgentStatDao agentStatDao; + private static AgentStatDao jvmGcDao; + + private static AgentStatDao cpuLoadDao; @BeforeClass - public static void before() { - agentStatDao = new AgentStatDao() { + public static void before() {jvmGcDao = new AgentStatDao() { @Override - public List getAgentStatList(String agentId, Range range) { - List agentStatList = new LinkedList(); + public List getAgentStatList(String agentId, Range range) { + List jvmGcs = new LinkedList<>(); for (int i = 0; i < 36; i++) { - AgentStat stat = new AgentStat("AGENT_NAME", 1L); - stat.setHeapUsed(70L); - stat.setHeapMax(100L); - - agentStatList.add(stat); + JvmGcBo jvmGcBo = new JvmGcBo(); + jvmGcBo.setHeapUsed(70L); + jvmGcBo.setHeapMax(100L); + + jvmGcs.add(jvmGcBo); } - return agentStatList; - } - - @Override - public List getAggregatedAgentStatList(String agentId, Range range) { - return getAgentStatList(agentId, range); + return jvmGcs; } @Override @@ -76,7 +74,20 @@ public class HeapUsageRateCheckerTest { return true; } }; - + + cpuLoadDao = new AgentStatDao() { + + @Override + public List getAgentStatList(String agentId, Range range) { + return Collections.emptyList(); + } + + @Override + public boolean agentStatExists(String agentId, Range range) { + return false; + } + }; + applicationIndexDao = new ApplicationIndexDao() { @Override @@ -118,7 +129,7 @@ public class HeapUsageRateCheckerTest { public void checkTest1() { Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.HEAP_USAGE_RATE.getName(), 70, "testGroup", false, false, ""); Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, jvmGcDao, cpuLoadDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); AgentChecker checker = new HeapUsageRateChecker(collector, rule); checker.check(); @@ -129,7 +140,7 @@ public class HeapUsageRateCheckerTest { public void checkTest2() { Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.HEAP_USAGE_RATE.getName(), 71, "testGroup", false, false, ""); Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, jvmGcDao, cpuLoadDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); AgentChecker checker = new HeapUsageRateChecker(collector, rule); checker.check(); @@ -147,7 +158,7 @@ public class HeapUsageRateCheckerTest { // 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.STAND_ALONE); -// AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, hbaseAgentStatDao, applicationIndexDao, System.currentTimeMillis(), (long)300000); +// AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, jvmGcDao, cpuLoadDao, applicationIndexDao, System.currentTimeMillis(), (long)300000); // AgentChecker checker = new HeapUsageRateChecker(collector, rule); // // checker.check(); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/JvmCpuUsageRateCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/JvmCpuUsageRateCheckerTest.java index 1caab0787..233c8c15e 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/JvmCpuUsageRateCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/JvmCpuUsageRateCheckerTest.java @@ -18,10 +18,13 @@ package com.navercorp.pinpoint.web.alarm.checker; import static org.junit.Assert.*; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; +import com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo; import org.junit.BeforeClass; import org.junit.Test; @@ -31,9 +34,8 @@ import com.navercorp.pinpoint.web.alarm.DataCollectorFactory; import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; import com.navercorp.pinpoint.web.alarm.collector.AgentStatDataCollector; import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.dao.AgentStatDao; +import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; -import com.navercorp.pinpoint.web.vo.AgentStat; import com.navercorp.pinpoint.web.vo.Application; import com.navercorp.pinpoint.web.vo.Range; @@ -43,29 +45,38 @@ public class JvmCpuUsageRateCheckerTest { private static final String SERVICE_TYPE = "tomcat"; private static ApplicationIndexDao applicationIndexDao; - - private static AgentStatDao agentStatDao; + + private static AgentStatDao jvmGcDao; + + private static AgentStatDao cpuLoadDao; @BeforeClass public static void before() { - agentStatDao = new AgentStatDao() { + jvmGcDao = new AgentStatDao() { @Override - public List getAgentStatList(String agentId, Range range) { - List agentStatList = new LinkedList(); - - for (int i = 0; i < 36; i++) { - AgentStat stat = new AgentStat("AGENT_NAME", 1L); - stat.setJvmCpuUsage(0.6); - agentStatList.add(stat); - } - - return agentStatList; + public List getAgentStatList(String agentId, Range range) { + return Collections.emptyList(); } @Override - public List getAggregatedAgentStatList(String agentId, Range range) { - return getAgentStatList(agentId, range); + public boolean agentStatExists(String agentId, Range range) { + return false; + } + }; + + cpuLoadDao = new AgentStatDao() { + + public List getAgentStatList(String agentId, Range range) { + List cpuLoads = new LinkedList<>(); + + for (int i = 0; i < 36; i++) { + CpuLoadBo cpuLoad = new CpuLoadBo(); + cpuLoad.setJvmCpuLoad(0.6); + cpuLoads.add(cpuLoad); + } + + return cpuLoads; } @Override @@ -115,7 +126,7 @@ public class JvmCpuUsageRateCheckerTest { public void checkTest1() { Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.JVM_CPU_USAGE_RATE.getName(), 60, "testGroup", false, false, ""); Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, jvmGcDao, cpuLoadDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); AgentChecker checker = new JvmCpuUsageRateChecker(collector, rule); checker.check(); @@ -126,7 +137,7 @@ public class JvmCpuUsageRateCheckerTest { public void checkTest2() { Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.JVM_CPU_USAGE_RATE.getName(), 61, "testGroup", false, false, ""); Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, jvmGcDao, cpuLoadDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); AgentChecker checker = new JvmCpuUsageRateChecker(collector, rule); checker.check(); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/mapper/AgentStatMapperTest.java b/web/src/test/java/com/navercorp/pinpoint/web/mapper/LegacyAgentStatMapperTest.java similarity index 96% rename from web/src/test/java/com/navercorp/pinpoint/web/mapper/AgentStatMapperTest.java rename to web/src/test/java/com/navercorp/pinpoint/web/mapper/LegacyAgentStatMapperTest.java index e40ddbf34..f220fc5bb 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/mapper/AgentStatMapperTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/mapper/LegacyAgentStatMapperTest.java @@ -1,239 +1,240 @@ -/* - * Copyright 2015 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.mapper; - -import static org.hamcrest.core.Is.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import static com.navercorp.pinpoint.common.hbase.HBaseTables.*; - -import java.util.Arrays; -import java.util.List; - -import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.thrift.TException; -import org.apache.thrift.TSerializer; -import org.apache.thrift.protocol.TCompactProtocol; -import org.apache.thrift.protocol.TProtocolFactory; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import com.navercorp.pinpoint.common.server.bo.AgentStatCpuLoadBo; -import com.navercorp.pinpoint.common.server.bo.AgentStatMemoryGcBo; -import com.navercorp.pinpoint.common.util.BytesUtils; -import com.navercorp.pinpoint.common.server.util.RowKeyUtils; -import com.navercorp.pinpoint.common.util.TimeUtils; -import com.navercorp.pinpoint.thrift.dto.TAgentStat; -import com.navercorp.pinpoint.thrift.dto.TJvmGc; -import com.navercorp.pinpoint.thrift.dto.TJvmGcType; -import com.navercorp.pinpoint.web.vo.AgentStat; -import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix; - -/** - * @author HyunGil Jeong - */ -public class AgentStatMapperTest { - - // for comparing CPU Usage up to 2 decimal places - private static final double DELTA = 1e-4; - - private static final String AGENT_ID = "agentId"; - private static final long TIMESTAMP = System.currentTimeMillis(); - private static final byte[] ROW_KEY = RowKeyUtils.concatFixedByteAndLong(BytesUtils.toBytes(AGENT_ID), AGENT_NAME_MAX_LEN, TimeUtils.reverseTimeMillis(TIMESTAMP)); - - private static final long COLLECT_INTERVAL = 5000L; - - private static final TJvmGcType GC_TYPE = TJvmGcType.G1; - private static final long GC_OLD_COUNT = 0L; - private static final long GC_OLD_TIME = Long.MAX_VALUE; - private static final long HEAP_USED = 1024L; - private static final long HEAP_MAX = 4096L; - private static final long NON_HEAP_USED = 52L; - private static final long NON_HEAP_MAX = -1L; - - private static final double JVM_CPU_USAGE = 10; - private static final double SYS_CPU_USAGE = 20; - - private static final long SAMPLED_NEW_COUNT = 100L; - private static final long SAMPLED_CONTINUATION_COUNT = 200L; - private static final long UNSAMPLED_NEW_COUNT = 50L; - private static final long UNSAMPLED_CONTINUATION_COUNT = 150L; - - @Mock - private RowKeyDistributorByHashPrefix rowKeyDistributorByHashPrefix; - - @InjectMocks - private AgentStatMapper mapper = new AgentStatMapper(); - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - when(this.rowKeyDistributorByHashPrefix.getOriginalKey(any(byte[].class))).thenReturn(ROW_KEY); - } - - @Test - public void test_current() throws Exception { - // Given - final Result result = Result.create(Arrays.asList( - createCell(AGENT_STAT_COL_INTERVAL, Bytes.toBytes(COLLECT_INTERVAL)), - createCell(AGENT_STAT_COL_GC_TYPE, Bytes.toBytes(GC_TYPE.name())), - createCell(AGENT_STAT_COL_GC_OLD_COUNT, Bytes.toBytes(GC_OLD_COUNT)), - createCell(AGENT_STAT_COL_GC_OLD_TIME, Bytes.toBytes(GC_OLD_TIME)), - createCell(AGENT_STAT_COL_HEAP_USED, Bytes.toBytes(HEAP_USED)), - createCell(AGENT_STAT_COL_HEAP_MAX, Bytes.toBytes(HEAP_MAX)), - createCell(AGENT_STAT_COL_NON_HEAP_USED, Bytes.toBytes(NON_HEAP_USED)), - createCell(AGENT_STAT_COL_NON_HEAP_MAX, Bytes.toBytes(NON_HEAP_MAX)), - createCell(AGENT_STAT_COL_JVM_CPU, Bytes.toBytes(JVM_CPU_USAGE)), - createCell(AGENT_STAT_COL_SYS_CPU, Bytes.toBytes(SYS_CPU_USAGE)), - createCell(AGENT_STAT_COL_TRANSACTION_SAMPLED_NEW, Bytes.toBytes(SAMPLED_NEW_COUNT)), - createCell(AGENT_STAT_COL_TRANSACTION_SAMPLED_CONTINUATION, Bytes.toBytes(SAMPLED_CONTINUATION_COUNT)), - createCell(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_NEW, Bytes.toBytes(UNSAMPLED_NEW_COUNT)), - createCell(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_CONTINUATION, Bytes.toBytes(UNSAMPLED_CONTINUATION_COUNT)) - )); - // When - List agentStats = this.mapper.mapRow(result, 0); - // Then - assertNotNull(agentStats); - assertThat(agentStats.size(), is(1)); - AgentStat agentStat = agentStats.get(0); - - assertEquals(COLLECT_INTERVAL, agentStat.getCollectInterval()); - assertJvmGc(agentStat); - assertCpuUsage(agentStat); - assertTransaction(agentStat); - } - - @Test - public void test_legacy_with_AGENT_STAT_CF_STATISTICS_V1() throws Exception { - // Given - final Result result = createResultForLegacyWith_AGENT_STAT_CF_STATISTICS_V1(); - // When - List agentStats = this.mapper.mapRow(result, 0); - // Then - assertNotNull(agentStats); - assertThat(agentStats.size(), is(1)); - AgentStat agentStat = agentStats.get(0); - - assertEquals(0, agentStat.getCollectInterval()); - assertJvmGc(agentStat); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getJvmCpuUsage(), DELTA); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSystemCpuUsage(), DELTA); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledNewCount()); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledContinuationCount()); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledNewCount()); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledContinuationCount()); - } - - @Test - public void test_legacy_serialized_BOs() throws Exception { - // Given - final Result result = createResultForLegacy_serialized_BOs(); - // When - List agentStats = this.mapper.mapRow(result, 0); - // Then - assertNotNull(agentStats); - assertThat(agentStats.size(), is(1)); - AgentStat agentStat = agentStats.get(0); - - assertEquals(0, agentStat.getCollectInterval()); - assertJvmGc(agentStat); - assertCpuUsage(agentStat); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledNewCount()); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledContinuationCount()); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledNewCount()); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledContinuationCount()); - } - - private void assertJvmGc(AgentStat agentStat) { - assertEquals(AGENT_ID, agentStat.getAgentId()); - assertEquals(TIMESTAMP, agentStat.getTimestamp()); - assertEquals(GC_TYPE.name(), agentStat.getGcType()); - assertEquals(GC_OLD_COUNT, agentStat.getGcOldCount()); - assertEquals(GC_OLD_TIME, agentStat.getGcOldTime()); - assertEquals(HEAP_USED, agentStat.getHeapUsed()); - assertEquals(HEAP_MAX, agentStat.getHeapMax()); - assertEquals(NON_HEAP_USED, agentStat.getNonHeapUsed()); - assertEquals(NON_HEAP_MAX, agentStat.getNonHeapMax()); - } - - private void assertCpuUsage(AgentStat agentStat) { - assertEquals(JVM_CPU_USAGE, agentStat.getJvmCpuUsage(), DELTA); - assertEquals(SYS_CPU_USAGE, agentStat.getSystemCpuUsage(), DELTA); - } - - private void assertTransaction(AgentStat agentStat) { - assertEquals(SAMPLED_NEW_COUNT, agentStat.getSampledNewCount()); - assertEquals(SAMPLED_CONTINUATION_COUNT, agentStat.getSampledContinuationCount()); - assertEquals(UNSAMPLED_NEW_COUNT, agentStat.getUnsampledNewCount()); - assertEquals(UNSAMPLED_CONTINUATION_COUNT, agentStat.getUnsampledContinuationCount()); - } - - private Result createResultForLegacyWith_AGENT_STAT_CF_STATISTICS_V1() throws TException { - final TAgentStat agentStat = new TAgentStat(); - final TJvmGc gc = new TJvmGc(); - gc.setType(GC_TYPE); - gc.setJvmGcOldCount(GC_OLD_COUNT); - gc.setJvmGcOldTime(GC_OLD_TIME); - gc.setJvmMemoryHeapUsed(HEAP_USED); - gc.setJvmMemoryHeapMax(HEAP_MAX); - gc.setJvmMemoryNonHeapUsed(NON_HEAP_USED); - gc.setJvmMemoryNonHeapMax(NON_HEAP_MAX); - agentStat.setGc(gc); - - final TProtocolFactory factory = new TCompactProtocol.Factory(); - final TSerializer serializer = new TSerializer(factory); - final byte[] qualifier = AGENT_STAT_CF_STATISTICS_V1; - final byte[] value = serializer.serialize(agentStat); - return Result.create(Arrays.asList(createCell(qualifier, value))); - } - - private Result createResultForLegacy_serialized_BOs() { - final AgentStatMemoryGcBo.Builder jvmGcBuilder = new AgentStatMemoryGcBo.Builder(AGENT_ID, 0L, TIMESTAMP); - jvmGcBuilder.gcType(GC_TYPE.name()); - jvmGcBuilder.jvmGcOldCount(GC_OLD_COUNT); - jvmGcBuilder.jvmGcOldTime(GC_OLD_TIME); - jvmGcBuilder.jvmMemoryHeapUsed(HEAP_USED); - jvmGcBuilder.jvmMemoryHeapMax(HEAP_MAX); - jvmGcBuilder.jvmMemoryNonHeapUsed(NON_HEAP_USED); - jvmGcBuilder.jvmMemoryNonHeapMax(NON_HEAP_MAX); - final AgentStatCpuLoadBo.Builder cpuLoadBuilder = new AgentStatCpuLoadBo.Builder(AGENT_ID, 0L, TIMESTAMP); - cpuLoadBuilder.jvmCpuLoad(JVM_CPU_USAGE); - cpuLoadBuilder.systemCpuLoad(SYS_CPU_USAGE); - final AgentStatMemoryGcBo jvmGc = jvmGcBuilder.build(); - final AgentStatCpuLoadBo cpuLoad = cpuLoadBuilder.build(); - - final Cell jvmGcCell = createCell(AGENT_STAT_CF_STATISTICS_MEMORY_GC, jvmGc.writeValue()); - final Cell cpuLoadCell = createCell(AGENT_STAT_CF_STATISTICS_CPU_LOAD, cpuLoad.writeValue()); - - return Result.create(Arrays.asList(jvmGcCell, cpuLoadCell)); - - } - - private Cell createCell(byte[] qualifier, byte[] value) { - return CellUtil.createCell(ROW_KEY, AGENT_STAT_CF_STATISTICS, qualifier, HConstants.LATEST_TIMESTAMP, - KeyValue.Type.Maximum.getCode(), value); - } - -} +/* + * Copyright 2015 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper; + +import com.navercorp.pinpoint.common.hbase.RowMapper; +import com.navercorp.pinpoint.common.server.bo.AgentStatCpuLoadBo; +import com.navercorp.pinpoint.common.server.bo.AgentStatMemoryGcBo; +import com.navercorp.pinpoint.common.server.util.RowKeyUtils; +import com.navercorp.pinpoint.common.util.BytesUtils; +import com.navercorp.pinpoint.common.util.TimeUtils; +import com.navercorp.pinpoint.thrift.dto.TAgentStat; +import com.navercorp.pinpoint.thrift.dto.TJvmGc; +import com.navercorp.pinpoint.thrift.dto.TJvmGcType; +import com.navercorp.pinpoint.web.mapper.stat.LegacyAgentStatMapper; +import com.navercorp.pinpoint.web.vo.AgentStat; +import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix; +import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.CellUtil; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.thrift.TException; +import org.apache.thrift.TSerializer; +import org.apache.thrift.protocol.TCompactProtocol; +import org.apache.thrift.protocol.TProtocolFactory; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.Arrays; +import java.util.List; + +import static com.navercorp.pinpoint.common.hbase.HBaseTables.*; +import static org.hamcrest.core.Is.*; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +/** + * @author HyunGil Jeong + */ +public class LegacyAgentStatMapperTest { + + // for comparing CPU Usage up to 2 decimal places + private static final double DELTA = 1e-4; + + private static final String AGENT_ID = "agentId"; + private static final long TIMESTAMP = System.currentTimeMillis(); + private static final byte[] ROW_KEY = RowKeyUtils.concatFixedByteAndLong(BytesUtils.toBytes(AGENT_ID), AGENT_NAME_MAX_LEN, TimeUtils.reverseTimeMillis(TIMESTAMP)); + + private static final long COLLECT_INTERVAL = 5000L; + + private static final TJvmGcType GC_TYPE = TJvmGcType.G1; + private static final long GC_OLD_COUNT = 0L; + private static final long GC_OLD_TIME = Long.MAX_VALUE; + private static final long HEAP_USED = 1024L; + private static final long HEAP_MAX = 4096L; + private static final long NON_HEAP_USED = 52L; + private static final long NON_HEAP_MAX = -1L; + + private static final double JVM_CPU_USAGE = 10; + private static final double SYS_CPU_USAGE = 20; + + private static final long SAMPLED_NEW_COUNT = 100L; + private static final long SAMPLED_CONTINUATION_COUNT = 200L; + private static final long UNSAMPLED_NEW_COUNT = 50L; + private static final long UNSAMPLED_CONTINUATION_COUNT = 150L; + + @Mock + private RowKeyDistributorByHashPrefix rowKeyDistributorByHashPrefix; + + @InjectMocks + private RowMapper> mapper = new LegacyAgentStatMapper(); + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + when(this.rowKeyDistributorByHashPrefix.getOriginalKey(any(byte[].class))).thenReturn(ROW_KEY); + } + + @Test + public void test_legacy_column_storage() throws Exception { + // Given + final Result result = Result.create(Arrays.asList( + createCell(AGENT_STAT_COL_INTERVAL, Bytes.toBytes(COLLECT_INTERVAL)), + createCell(AGENT_STAT_COL_GC_TYPE, Bytes.toBytes(GC_TYPE.name())), + createCell(AGENT_STAT_COL_GC_OLD_COUNT, Bytes.toBytes(GC_OLD_COUNT)), + createCell(AGENT_STAT_COL_GC_OLD_TIME, Bytes.toBytes(GC_OLD_TIME)), + createCell(AGENT_STAT_COL_HEAP_USED, Bytes.toBytes(HEAP_USED)), + createCell(AGENT_STAT_COL_HEAP_MAX, Bytes.toBytes(HEAP_MAX)), + createCell(AGENT_STAT_COL_NON_HEAP_USED, Bytes.toBytes(NON_HEAP_USED)), + createCell(AGENT_STAT_COL_NON_HEAP_MAX, Bytes.toBytes(NON_HEAP_MAX)), + createCell(AGENT_STAT_COL_JVM_CPU, Bytes.toBytes(JVM_CPU_USAGE)), + createCell(AGENT_STAT_COL_SYS_CPU, Bytes.toBytes(SYS_CPU_USAGE)), + createCell(AGENT_STAT_COL_TRANSACTION_SAMPLED_NEW, Bytes.toBytes(SAMPLED_NEW_COUNT)), + createCell(AGENT_STAT_COL_TRANSACTION_SAMPLED_CONTINUATION, Bytes.toBytes(SAMPLED_CONTINUATION_COUNT)), + createCell(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_NEW, Bytes.toBytes(UNSAMPLED_NEW_COUNT)), + createCell(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_CONTINUATION, Bytes.toBytes(UNSAMPLED_CONTINUATION_COUNT)) + )); + // When + List agentStats = this.mapper.mapRow(result, 0); + // Then + assertNotNull(agentStats); + assertThat(agentStats.size(), is(1)); + AgentStat agentStat = agentStats.get(0); + + assertEquals(COLLECT_INTERVAL, agentStat.getCollectInterval()); + assertJvmGc(agentStat); + assertCpuUsage(agentStat); + assertTransaction(agentStat); + } + + @Test + public void test_legacy_with_AGENT_STAT_CF_STATISTICS_V1() throws Exception { + // Given + final Result result = createResultForLegacyWith_AGENT_STAT_CF_STATISTICS_V1(); + // When + List agentStats = this.mapper.mapRow(result, 0); + // Then + assertNotNull(agentStats); + assertThat(agentStats.size(), is(1)); + AgentStat agentStat = agentStats.get(0); + + assertEquals(0, agentStat.getCollectInterval()); + assertJvmGc(agentStat); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getJvmCpuUsage(), DELTA); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSystemCpuUsage(), DELTA); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledNewCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledContinuationCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledNewCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledContinuationCount()); + } + + @Test + public void test_legacy_serialized_BOs() throws Exception { + // Given + final Result result = createResultForLegacy_serialized_BOs(); + // When + List agentStats = this.mapper.mapRow(result, 0); + // Then + assertNotNull(agentStats); + assertThat(agentStats.size(), is(1)); + AgentStat agentStat = agentStats.get(0); + + assertEquals(0, agentStat.getCollectInterval()); + assertJvmGc(agentStat); + assertCpuUsage(agentStat); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledNewCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledContinuationCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledNewCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledContinuationCount()); + } + + private void assertJvmGc(AgentStat agentStat) { + assertEquals(AGENT_ID, agentStat.getAgentId()); + assertEquals(TIMESTAMP, agentStat.getTimestamp()); + assertEquals(GC_TYPE.name(), agentStat.getGcType()); + assertEquals(GC_OLD_COUNT, agentStat.getGcOldCount()); + assertEquals(GC_OLD_TIME, agentStat.getGcOldTime()); + assertEquals(HEAP_USED, agentStat.getHeapUsed()); + assertEquals(HEAP_MAX, agentStat.getHeapMax()); + assertEquals(NON_HEAP_USED, agentStat.getNonHeapUsed()); + assertEquals(NON_HEAP_MAX, agentStat.getNonHeapMax()); + } + + private void assertCpuUsage(AgentStat agentStat) { + assertEquals(JVM_CPU_USAGE, agentStat.getJvmCpuUsage(), DELTA); + assertEquals(SYS_CPU_USAGE, agentStat.getSystemCpuUsage(), DELTA); + } + + private void assertTransaction(AgentStat agentStat) { + assertEquals(SAMPLED_NEW_COUNT, agentStat.getSampledNewCount()); + assertEquals(SAMPLED_CONTINUATION_COUNT, agentStat.getSampledContinuationCount()); + assertEquals(UNSAMPLED_NEW_COUNT, agentStat.getUnsampledNewCount()); + assertEquals(UNSAMPLED_CONTINUATION_COUNT, agentStat.getUnsampledContinuationCount()); + } + + private Result createResultForLegacyWith_AGENT_STAT_CF_STATISTICS_V1() throws TException { + final TAgentStat agentStat = new TAgentStat(); + final TJvmGc gc = new TJvmGc(); + gc.setType(GC_TYPE); + gc.setJvmGcOldCount(GC_OLD_COUNT); + gc.setJvmGcOldTime(GC_OLD_TIME); + gc.setJvmMemoryHeapUsed(HEAP_USED); + gc.setJvmMemoryHeapMax(HEAP_MAX); + gc.setJvmMemoryNonHeapUsed(NON_HEAP_USED); + gc.setJvmMemoryNonHeapMax(NON_HEAP_MAX); + agentStat.setGc(gc); + + final TProtocolFactory factory = new TCompactProtocol.Factory(); + final TSerializer serializer = new TSerializer(factory); + final byte[] qualifier = AGENT_STAT_CF_STATISTICS_V1; + final byte[] value = serializer.serialize(agentStat); + return Result.create(Arrays.asList(createCell(qualifier, value))); + } + + private Result createResultForLegacy_serialized_BOs() { + final AgentStatMemoryGcBo.Builder jvmGcBuilder = new AgentStatMemoryGcBo.Builder(AGENT_ID, 0L, TIMESTAMP); + jvmGcBuilder.gcType(GC_TYPE.name()); + jvmGcBuilder.jvmGcOldCount(GC_OLD_COUNT); + jvmGcBuilder.jvmGcOldTime(GC_OLD_TIME); + jvmGcBuilder.jvmMemoryHeapUsed(HEAP_USED); + jvmGcBuilder.jvmMemoryHeapMax(HEAP_MAX); + jvmGcBuilder.jvmMemoryNonHeapUsed(NON_HEAP_USED); + jvmGcBuilder.jvmMemoryNonHeapMax(NON_HEAP_MAX); + final AgentStatCpuLoadBo.Builder cpuLoadBuilder = new AgentStatCpuLoadBo.Builder(AGENT_ID, 0L, TIMESTAMP); + cpuLoadBuilder.jvmCpuLoad(JVM_CPU_USAGE); + cpuLoadBuilder.systemCpuLoad(SYS_CPU_USAGE); + final AgentStatMemoryGcBo jvmGc = jvmGcBuilder.build(); + final AgentStatCpuLoadBo cpuLoad = cpuLoadBuilder.build(); + + final Cell jvmGcCell = createCell(AGENT_STAT_CF_STATISTICS_MEMORY_GC, jvmGc.writeValue()); + final Cell cpuLoadCell = createCell(AGENT_STAT_CF_STATISTICS_CPU_LOAD, cpuLoad.writeValue()); + + return Result.create(Arrays.asList(jvmGcCell, cpuLoadCell)); + + } + + private Cell createCell(byte[] qualifier, byte[] value) { + return CellUtil.createCell(ROW_KEY, AGENT_STAT_CF_STATISTICS, qualifier, HConstants.LATEST_TIMESTAMP, + KeyValue.Type.Maximum.getCode(), value); + } + +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2Test.java b/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2Test.java new file mode 100644 index 000000000..542d455ee --- /dev/null +++ b/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/AgentStatMapperV2Test.java @@ -0,0 +1,230 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper.stat; + +import com.navercorp.pinpoint.common.buffer.Buffer; +import com.navercorp.pinpoint.common.hbase.HBaseTables; +import com.navercorp.pinpoint.common.hbase.distributor.RangeOneByteSimpleHash; +import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatCodec; +import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDecoder; +import com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatEncoder; +import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatHbaseOperationFactory; +import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatRowKeyDecoder; +import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatRowKeyEncoder; +import com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatSerializer; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.web.mapper.TimestampFilter; +import com.sematext.hbase.wd.AbstractRowKeyDistributor; +import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix; +import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.client.Result; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +/** + * @author HyunGil Jeong + */ +public class AgentStatMapperV2Test { + + private static final String AGENT_ID = "testAgent"; + private static final AgentStatType AGENT_STAT_TYPE = AgentStatType.UNKNOWN; + private static final long COLLECT_INVERVAL = 5000L; + private static final Random RANDOM = new Random(); + private static final TimestampFilter TEST_FILTER = new TimestampFilter() { + @Override + public boolean filter(long timestamp) { + return false; + } + }; + + private final AgentStatRowKeyEncoder rowKeyEncoder = new AgentStatRowKeyEncoder(); + + private final AgentStatRowKeyDecoder rowKeyDecoder = new AgentStatRowKeyDecoder(); + + private final AbstractRowKeyDistributor rowKeyDistributor = new RowKeyDistributorByHashPrefix( + new RangeOneByteSimpleHash(0, 33, 64)); + + private final AgentStatHbaseOperationFactory hbaseOperationFactory = new AgentStatHbaseOperationFactory( + this.rowKeyEncoder, this.rowKeyDecoder, this.rowKeyDistributor); + + private final AgentStatCodec codec = new TestAgentStatCodec(); + + private final AgentStatEncoder encoder = new TestAgentStatEncoder(this.codec); + + private final AgentStatDecoder decoder = new TestAgentStatDecoder(this.codec); + + private final AgentStatSerializer serializer = new TestAgentStatSerializer(this.encoder); + + @Test + public void mapperTest() throws Exception { + // Given + List givenAgentStats = new ArrayList<>(); + List puts = new ArrayList<>(); + long initialTimestamp = System.currentTimeMillis(); + int numBatch = RANDOM.nextInt(10) + 1; + for (int i = 0; i < numBatch; ++i) { + int batchSize = RANDOM.nextInt(10) + 1; + List agentStatBatch = createAgentStats(initialTimestamp, COLLECT_INVERVAL, batchSize); + givenAgentStats.addAll(agentStatBatch); + puts.addAll(this.hbaseOperationFactory.createPuts(AGENT_ID, AGENT_STAT_TYPE, agentStatBatch, this.serializer)); + initialTimestamp += batchSize * COLLECT_INVERVAL; + } + List cellsToPut = new ArrayList<>(); + for (Put put : puts) { + List cells = put.getFamilyCellMap().get(HBaseTables.AGENT_STAT_CF_STATISTICS); + cellsToPut.addAll(cells); + } + Result result = Result.create(cellsToPut); + + // When + AgentStatMapperV2 mapper = new AgentStatMapperV2<>(this.hbaseOperationFactory, this.decoder, TEST_FILTER); + List mappedAgentStats = mapper.mapRow(result, 0); + + // Then + Collections.sort(givenAgentStats, AgentStatMapperV2.REVERSE_TIMESTAMP_COMPARATOR); + Assert.assertEquals(givenAgentStats, mappedAgentStats); + } + + private List createAgentStats(long initialTimestamp, long interval, int batchSize) { + List agentStats = new ArrayList<>(batchSize); + for (int i = 0; i < batchSize; ++i) { + long timestamp = initialTimestamp + (interval * i); + TestAgentStat agentStat = new TestAgentStat(); + agentStat.setAgentId(AGENT_ID); + agentStat.setTimestamp(timestamp); + agentStat.setValue(RANDOM.nextLong()); + agentStats.add(agentStat); + } + return agentStats; + } + + private static class TestAgentStatCodec implements AgentStatCodec { + + @Override + public byte getVersion() { + return 0; + } + + @Override + public void encodeValues(Buffer valueBuffer, List agentStats) { + valueBuffer.putInt(agentStats.size()); + for (TestAgentStat agentStat : agentStats) { + valueBuffer.putLong(agentStat.getTimestamp()); + valueBuffer.putLong(agentStat.getValue()); + } + } + + @Override + public List decodeValues(Buffer valueBuffer, long initialTimestamp) { + int size = valueBuffer.readInt(); + List agentStats = new ArrayList<>(size); + for (int i = 0; i < size; ++i) { + TestAgentStat agentStat = new TestAgentStat(); + agentStat.setTimestamp(valueBuffer.readLong()); + agentStat.setValue(valueBuffer.readLong()); + agentStats.add(agentStat); + } + return agentStats; + } + } + + private static class TestAgentStatEncoder extends AgentStatEncoder { + protected TestAgentStatEncoder(AgentStatCodec codec) { + super(codec); + } + } + + private static class TestAgentStatDecoder extends AgentStatDecoder { + protected TestAgentStatDecoder(AgentStatCodec codec) { + super(Arrays.asList(codec)); + } + } + + private static class TestAgentStatSerializer extends AgentStatSerializer { + protected TestAgentStatSerializer(AgentStatEncoder encoder) { + super(encoder); + } + } + + private static class TestAgentStat implements AgentStatDataPoint { + + private String agentId; + private long timestamp; + private long value; + + @Override + public String getAgentId() { + return this.agentId; + } + + @Override + public void setAgentId(String agentId) { + this.agentId = agentId; + } + + @Override + public long getTimestamp() { + return this.timestamp; + } + + @Override + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getValue() { + return this.value; + } + + public void setValue(long value) { + this.value = value; + } + + @Override + public AgentStatType getAgentStatType() { + return AGENT_STAT_TYPE; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TestAgentStat that = (TestAgentStat) o; + + if (timestamp != that.timestamp) return false; + if (value != that.value) return false; + return agentId != null ? agentId.equals(that.agentId) : that.agentId == null; + } + + @Override + public int hashCode() { + int result = agentId != null ? agentId.hashCode() : 0; + result = 31 * result + (int) (timestamp ^ (timestamp >>> 32)); + result = 31 * result + (int) (value ^ (value >>> 32)); + return result; + } + } +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractorTest.java b/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractorTest.java new file mode 100644 index 000000000..bc462796e --- /dev/null +++ b/web/src/test/java/com/navercorp/pinpoint/web/mapper/stat/SampledAgentStatResultExtractorTest.java @@ -0,0 +1,277 @@ +/* + * Copyright 2016 Naver Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.mapper.stat; + +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint; +import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType; +import com.navercorp.pinpoint.web.util.TimeWindow; +import com.navercorp.pinpoint.web.util.TimeWindowSampler; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.mockito.Mockito.when; + +/** + * @author HyunGil Jeong + */ +@RunWith(MockitoJUnitRunner.class) +public class SampledAgentStatResultExtractorTest { + + private static final long DEFAULT_TIME_INTERVAL = 5 * 1000L; + + private static final TimeWindowSampler ONE_TO_ONE_SAMPLER = new TimeWindowSampler() { + @Override + public long getWindowSize(Range range) { + return DEFAULT_TIME_INTERVAL; + } + }; + + private static final TimeWindowSampler TWO_TO_ONE_SAMPLER = new TimeWindowSampler() { + @Override + public long getWindowSize(Range range) { + return DEFAULT_TIME_INTERVAL * 2; + } + }; + + private static final TimeWindowSampler TEN_TO_ONE_SAMPLER = new TimeWindowSampler() { + @Override + public long getWindowSize(Range range) { + return DEFAULT_TIME_INTERVAL * 10; + } + }; + + @Mock + private ResultScanner resultScanner; + + @Mock + private Result result; + + @Mock + private AgentStatMapperV2 rowMapper; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this.getClass()); + when(this.resultScanner.iterator()).thenReturn(Arrays.asList(this.result).iterator()); + } + + @Test + public void one_to_one_sampler_should_not_down_sample_data_points() throws Exception { + // Given + final int numValues = 10; + final long initialTimestamp = System.currentTimeMillis(); + final long finalTimestamp = initialTimestamp + (DEFAULT_TIME_INTERVAL * numValues); + final TimeWindow timeWindow = new TimeWindow(new Range(initialTimestamp, finalTimestamp), ONE_TO_ONE_SAMPLER); + final List dataPoints = createDataPoints(finalTimestamp, DEFAULT_TIME_INTERVAL, numValues); + final Map> expectedDataPointSlotMap = getExpectedDataPointSlotMap(timeWindow, dataPoints); + when(this.rowMapper.mapRow(this.result, 0)).thenReturn(dataPoints); + + TestResultExtractor resultExtractor = new TestResultExtractor(timeWindow, this.rowMapper); + // When + List sampledDataPoints = resultExtractor.extractData(this.resultScanner); + // Then + for (TestSampledAgentStatDataPoint sampledDataPoint : sampledDataPoints) { + List expectedSampledDataPoints = expectedDataPointSlotMap.get(sampledDataPoint.getBaseTimestamp()); + Assert.assertEquals(expectedSampledDataPoints, sampledDataPoint.getDataPointsToSample()); + } + } + + @Test + public void two_to_one_sample_should_down_sample_correctly() throws Exception { + // Given + final int numValues = 20; + final long initialTimestamp = System.currentTimeMillis(); + final long finalTimestamp = initialTimestamp + (DEFAULT_TIME_INTERVAL * numValues); + final TimeWindow timeWindow = new TimeWindow(new Range(initialTimestamp, finalTimestamp), TWO_TO_ONE_SAMPLER); + final List dataPoints = createDataPoints(finalTimestamp, DEFAULT_TIME_INTERVAL, numValues); + final Map> expectedDataPointSlotMap = getExpectedDataPointSlotMap(timeWindow, dataPoints); + when(this.rowMapper.mapRow(this.result, 0)).thenReturn(dataPoints); + + TestResultExtractor resultExtractor = new TestResultExtractor(timeWindow, this.rowMapper); + // When + List sampledDataPoints = resultExtractor.extractData(this.resultScanner); + // Then + for (TestSampledAgentStatDataPoint sampledDataPoint : sampledDataPoints) { + List expectedSampledDataPoints = expectedDataPointSlotMap.get(sampledDataPoint.getBaseTimestamp()); + Assert.assertEquals(expectedSampledDataPoints, sampledDataPoint.getDataPointsToSample()); + } + } + + @Test + public void ten_to_one_sample_should_down_sample_correctly() throws Exception { + // Given + final int numValues = 100; + final long initialTimestamp = System.currentTimeMillis(); + final long finalTimestamp = initialTimestamp + (DEFAULT_TIME_INTERVAL * numValues); + final TimeWindow timeWindow = new TimeWindow(new Range(initialTimestamp, finalTimestamp), TEN_TO_ONE_SAMPLER); + final List dataPoints = createDataPoints(finalTimestamp, DEFAULT_TIME_INTERVAL, numValues); + final Map> expectedDataPointSlotMap = getExpectedDataPointSlotMap(timeWindow, dataPoints); + when(this.rowMapper.mapRow(this.result, 0)).thenReturn(dataPoints); + + TestResultExtractor resultExtractor = new TestResultExtractor(timeWindow, this.rowMapper); + // When + List sampledDataPoints = resultExtractor.extractData(this.resultScanner); + // Then + for (TestSampledAgentStatDataPoint sampledDataPoint : sampledDataPoints) { + List expectedSampledDataPoints = expectedDataPointSlotMap.get(sampledDataPoint.getBaseTimestamp()); + Assert.assertEquals(expectedSampledDataPoints, sampledDataPoint.getDataPointsToSample()); + } + } + + private Map> getExpectedDataPointSlotMap(TimeWindow timeWindow, List dataPoints) { + Map> slotMap = new HashMap<>(); + for (long timeslotTimestamp : timeWindow) { + slotMap.put(timeslotTimestamp, new ArrayList()); + } + for (TestAgentStatDataPoint dataPoint : dataPoints) { + slotMap.get(timeWindow.refineTimestamp(dataPoint.getTimestamp())).add(dataPoint); + } + return slotMap; + } + + private List createDataPoints(long finalTimestamp, long timeInterval, int numDataPoints) { + List dataPoints = new ArrayList<>(numDataPoints); + for (int i = 0; i < numDataPoints; ++i) { + TestAgentStatDataPoint dataPoint = new TestAgentStatDataPoint(); + dataPoint.setTimestamp(finalTimestamp - (timeInterval * i)); + dataPoint.setValue(i); + dataPoints.add(dataPoint); + } + return dataPoints; + } + + private static class TestResultExtractor extends SampledAgentStatResultExtractor { + + public TestResultExtractor(TimeWindow timeWindow, AgentStatMapperV2 rowMapper) { + super(timeWindow, rowMapper); + } + + @Override + protected TestSampledAgentStatDataPoint sampleCurrentBatch(long timestamp, List dataPointsToSample) { + return new TestSampledAgentStatDataPoint(timestamp, dataPointsToSample); + } + } + + private static class TestAgentStatDataPoint implements AgentStatDataPoint { + private String agentId; + private long timestamp; + private int value; + + @Override + public String getAgentId() { + return agentId; + } + + @Override + public void setAgentId(String agentId) { + this.agentId = agentId; + } + + @Override + public long getTimestamp() { + return timestamp; + } + + @Override + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + @Override + public AgentStatType getAgentStatType() { + return AgentStatType.UNKNOWN; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TestAgentStatDataPoint that = (TestAgentStatDataPoint) o; + + if (timestamp != that.timestamp) return false; + if (value != that.value) return false; + return agentId != null ? agentId.equals(that.agentId) : that.agentId == null; + } + + @Override + public int hashCode() { + int result = agentId != null ? agentId.hashCode() : 0; + result = 31 * result + (int) (timestamp ^ (timestamp >>> 32)); + result = 31 * result + value; + return result; + } + + @Override + public String toString() { + return "TestAgentStatDataPoint{" + + "agentId='" + agentId + '\'' + + ", timestamp=" + timestamp + + ", value=" + value + + '}'; + } + } + + private static class TestSampledAgentStatDataPoint implements SampledAgentStatDataPoint { + private final long baseTimestamp; + private final List dataPointsToSample; + + private TestSampledAgentStatDataPoint(long baseTimestamp, List dataPointsToSample) { + this.baseTimestamp = baseTimestamp; + this.dataPointsToSample = dataPointsToSample; + } + + public long getBaseTimestamp() { + return baseTimestamp; + } + + public List getDataPointsToSample() { + return dataPointsToSample; + } + + @Override + public String toString() { + return "TestSampledAgentStatDataPoint{" + + "baseTimestamp=" + baseTimestamp + + ", dataPointsToSample=" + dataPointsToSample + + '}'; + } + } +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataChartBuilderTest.java b/web/src/test/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataChartBuilderTest.java deleted file mode 100644 index 6ed3410f5..000000000 --- a/web/src/test/java/com/navercorp/pinpoint/web/vo/linechart/SampledDataChartBuilderTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.vo.linechart; - -import static org.junit.Assert.assertTrue; - -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.navercorp.pinpoint.web.vo.linechart.Chart.ChartBuilder; - -public class SampledDataChartBuilderTest { - - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Test - public void testSampledLongDataChart() throws Exception { - // Given - final long defaultValue = 0L; - final int sampleRate = 60; - final int totalPoints = 10000; - final int expectedNumPoints = getExpectedNumPoints(sampleRate, totalPoints); - // When - ChartBuilder longDataChartBuilder = new SampledDataLongChartBuilder(DownSamplers.getLongDownSampler(defaultValue), sampleRate); - for (long i = 0; i < totalPoints; ++i) { - longDataChartBuilder.addDataPoint(new DataPoint<>(i, i)); - } - Chart lineChart = longDataChartBuilder.buildChart(); - // Then - assertTrue(lineChart.getPoints().size() == expectedNumPoints); - ObjectMapper mapper = new ObjectMapper(); - String result = mapper.writeValueAsString(lineChart); - logger.debug(result); - } - - @Test - public void testSampledDoubleLineChart() throws Exception { - // Given - final double defaultValue = 0D; - int sampleRate = 60; - int totalPoints = 10000; - final int expectedNumPoints = getExpectedNumPoints(sampleRate, totalPoints); - // When - ChartBuilder doubleLineChartBuilder = new SampledDataDoubleChartBuilder(DownSamplers.getDoubleDownSampler(defaultValue, 1), sampleRate); - for (long i = 0; i < totalPoints; ++i) { - doubleLineChartBuilder.addDataPoint(new DataPoint<>(i, (double)i)); - } - Chart lineChart = doubleLineChartBuilder.buildChart(); - // Then - assertTrue(lineChart.getPoints().size() == expectedNumPoints); - ObjectMapper mapper = new ObjectMapper(); - String result = mapper.writeValueAsString(lineChart); - logger.debug(result); - } - - private int getExpectedNumPoints(int sampleRate, int totalPoints) { - return totalPoints % sampleRate == 0 ? totalPoints / sampleRate : totalPoints / sampleRate + 1; - } - -}