Search in sources :

Example 21 with TimeWindow

use of com.navercorp.pinpoint.web.util.TimeWindow in project pinpoint by naver.

the class TimeSeriesChartBuilderTest method sampled.

@Test
public void sampled() {
    // Given
    int numSlots = 100;
    TimeWindow timeWindow = new TimeWindow(Range.newRange(0, TIME_WINDOW_SIZE * numSlots), TIME_WINDOW_SAMPLER);
    TimeSeriesChartBuilder<TestPoint> builder = new TimeSeriesChartBuilder<>(timeWindow, TestPoint.UNCOLLECTED_POINT_CREATOR);
    List<TestPoint> points = new ArrayList<>(TIME_WINDOW_SIZE * numSlots);
    for (int i = 0; i <= TIME_WINDOW_SIZE * numSlots; i++) {
        points.add(new TestPoint(i, i / TIME_WINDOW_SIZE));
    }
    // When
    Chart<TestPoint> chart = builder.build(points);
    // Then
    List<TestPoint> sampledPoints = chart.getPoints();
    for (int i = 0; i < sampledPoints.size(); i++) {
        Assert.assertEquals(i, sampledPoints.get(i).getYVal());
    }
}
Also used : ArrayList(java.util.ArrayList) TimeWindow(com.navercorp.pinpoint.web.util.TimeWindow) Test(org.junit.Test)

Example 22 with TimeWindow

use of com.navercorp.pinpoint.web.util.TimeWindow in project pinpoint by naver.

the class DataSourceChartGroupSerializerTest method serializeTest.

@Test
public void serializeTest() throws Exception {
    long currentTimeMillis = System.currentTimeMillis();
    TimeWindow timeWindow = new TimeWindow(new Range(currentTimeMillis - 300000, currentTimeMillis));
    List<SampledDataSource> sampledDataSourceList = createSampledDataSourceList(timeWindow);
    DataSourceChartGroup dataSourceChartGroup = new DataSourceChartGroup(timeWindow, sampledDataSourceList, serviceTypeRegistryService);
    String jsonValue = mapper.writeValueAsString(dataSourceChartGroup);
    Map map = mapper.readValue(jsonValue, Map.class);
    Assert.assertTrue(map.containsKey("id"));
    Assert.assertTrue(map.containsKey("jdbcUrl"));
    Assert.assertTrue(map.containsKey("databaseName"));
    Assert.assertTrue(map.containsKey("serviceType"));
    Assert.assertTrue(map.containsKey("charts"));
}
Also used : DataSourceChartGroup(com.navercorp.pinpoint.web.vo.stat.chart.DataSourceChartGroup) SampledDataSource(com.navercorp.pinpoint.web.vo.stat.SampledDataSource) Range(com.navercorp.pinpoint.web.vo.Range) TimeWindow(com.navercorp.pinpoint.web.util.TimeWindow) Map(java.util.Map) Test(org.junit.Test)

Example 23 with TimeWindow

use of com.navercorp.pinpoint.web.util.TimeWindow in project pinpoint by naver.

the class DataSourceChartGroupTest method basicFunctionTest1.

@Test
public void basicFunctionTest1() throws Exception {
    long currentTimeMillis = System.currentTimeMillis();
    TimeWindow timeWindow = new TimeWindow(new Range(currentTimeMillis - 300000, currentTimeMillis));
    List<SampledDataSource> sampledDataSourceList = createSampledDataSourceList(timeWindow);
    DataSourceChartGroup dataSourceChartGroup = new DataSourceChartGroup(timeWindow, sampledDataSourceList, serviceTypeRegistryService);
    assertEquals(sampledDataSourceList, dataSourceChartGroup);
}
Also used : SampledDataSource(com.navercorp.pinpoint.web.vo.stat.SampledDataSource) Range(com.navercorp.pinpoint.web.vo.Range) TimeWindow(com.navercorp.pinpoint.web.util.TimeWindow) Test(org.junit.Test)

Example 24 with TimeWindow

use of com.navercorp.pinpoint.web.util.TimeWindow in project pinpoint by naver.

the class TimeWindowTest method testGetNextWindowFirst.

@Test
public void testGetNextWindowFirst() throws Exception {
    TimeWindow window = new TimeWindow(new Range(0L, 1000));
    logger.debug("{}", window.getWindowRange());
    Iterator<Long> iterator = window.iterator();
    Assert.assertEquals(iterator.next(), (Long) 0L);
    try {
        iterator.next();
        Assert.fail("no more element");
    } catch (Exception ignored) {
    }
    TimeWindow window2 = new TimeWindow(new Range(0L, TimeUnit.MINUTES.toMillis(1)));
    logger.debug("{}", window2.getWindowRange());
    Iterator<Long> iterator2 = window2.iterator();
    Assert.assertEquals(iterator2.next(), (Long) 0L);
    Assert.assertEquals(iterator2.next(), (Long) (1000 * 60L));
    try {
        iterator2.next();
        Assert.fail("no more element");
    } catch (Exception ignored) {
    }
}
Also used : Range(com.navercorp.pinpoint.web.vo.Range) TimeWindow(com.navercorp.pinpoint.web.util.TimeWindow) Test(org.junit.Test)

Example 25 with TimeWindow

use of com.navercorp.pinpoint.web.util.TimeWindow in project pinpoint by naver.

the class AgentStatController method getAgentStatChart.

@PreAuthorize("hasPermission(new com.navercorp.pinpoint.web.vo.AgentParam(#agentId, #to), 'agentParam', 'inspector')")
@RequestMapping(value = "/chart", method = RequestMethod.GET, params = { "interval" })
@ResponseBody
public AgentStatChartGroup getAgentStatChart(@RequestParam("agentId") String agentId, @RequestParam("from") long from, @RequestParam("to") long to, @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);
}
Also used : TimeWindowSampler(com.navercorp.pinpoint.web.util.TimeWindowSampler) Range(com.navercorp.pinpoint.web.vo.Range) TimeWindow(com.navercorp.pinpoint.web.util.TimeWindow) AgentStatDataPoint(com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

TimeWindow (com.navercorp.pinpoint.web.util.TimeWindow)42 Test (org.junit.Test)26 Range (com.navercorp.pinpoint.web.vo.Range)25 ArrayList (java.util.ArrayList)14 StatChartGroup (com.navercorp.pinpoint.web.vo.stat.chart.StatChartGroup)13 Chart (com.navercorp.pinpoint.web.vo.chart.Chart)12 Point (com.navercorp.pinpoint.web.vo.chart.Point)12 TimeWindowSampler (com.navercorp.pinpoint.web.util.TimeWindowSampler)8 TimeWindowSlotCentricSampler (com.navercorp.pinpoint.web.util.TimeWindowSlotCentricSampler)8 AgentStatDataPoint (com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 SampledDataSource (com.navercorp.pinpoint.web.vo.stat.SampledDataSource)6 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 List (java.util.List)4 LinkDataMap (com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataMap)3 SampledAgentStatDataPoint (com.navercorp.pinpoint.web.vo.stat.SampledAgentStatDataPoint)3 LegacyAgentStatChartGroup (com.navercorp.pinpoint.web.vo.stat.chart.LegacyAgentStatChartGroup)3 StopWatch (org.springframework.util.StopWatch)3