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());
}
}
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"));
}
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);
}
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) {
}
}
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);
}
Aggregations