use of org.spf4j.perf.MeasurementStoreQuery in project spf4j by zolyfarkas.
the class FileMonitorAspectTest method testFileIOMonitoring.
/**
* Test of nioReadLong method, of class FileMonitorAspect.
*/
@Test
public void testFileIOMonitoring() throws Exception {
System.setProperty("spf4j.perf.file.sampleTimeMillis", "1000");
File tempFile = File.createTempFile("test", ".tmp");
tempFile.deleteOnExit();
try (Writer fw = new OutputStreamWriter(Files.newOutputStream(tempFile.toPath()), StandardCharsets.UTF_8)) {
for (int i = 0; i < 10; i++) {
fw.write("bla bla test\n");
Thread.sleep(500);
}
}
Thread.sleep(1000);
try (BufferedReader fr = new BufferedReader(new InputStreamReader(Files.newInputStream(tempFile.toPath()), StandardCharsets.UTF_8))) {
String line = fr.readLine();
while (line != null) {
LOG.debug("Read: {}", line);
line = fr.readLine();
Thread.sleep(500);
}
}
RecorderFactory.MEASUREMENT_STORE.flush();
MeasurementStoreQuery query = RecorderFactory.MEASUREMENT_STORE.query();
Collection<Schema> measurements = query.getMeasurements((x) -> true);
LOG.debug("Tables {}", measurements);
THashSet<String> collect = measurements.stream().map((x) -> x.getProp(TimeSeriesRecord.RAW_NAME)).collect(Collectors.toCollection(() -> new THashSet<String>(measurements.size())));
Assert.assertThat(collect, (Matcher) Matchers.hasItem("file-write,org.spf4j.perf.aspects.FileMonitorAspectTest"));
Assert.assertThat(collect, (Matcher) Matchers.hasItem("file-read,org.spf4j.perf.aspects.FileMonitorAspectTest"));
Collection<Schema> fmw = query.getMeasurements((x) -> "file_write_org_spf4j_perf_aspects_FileMonitorAspectTest".equals(x));
try (AvroCloseableIterable<Observation> obs = query.getObservations(fmw.iterator().next(), Instant.EPOCH, Instant.now())) {
Assert.assertTrue(obs.iterator().hasNext());
}
Assert.assertTrue(OperatingSystem.getOpenFileDescriptorCount() > 0);
}
use of org.spf4j.perf.MeasurementStoreQuery in project spf4j by zolyfarkas.
the class AvroMeasurementStoreTest method testStore.
@Test
@SuppressFBWarnings({ "PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS", "AFBR_ABNORMAL_FINALLY_BLOCK_RETURN" })
public void testStore() throws IOException {
AvroMeasurementStore store = new AvroMeasurementStore(org.spf4j.base.Runtime.TMP_FOLDER_PATH, "testMetrics", Compressor.ZSTANDARD);
try {
long mid = store.alocateMeasurements(new MeasurementsInfoImpl("test", "test", new String[] { "v1", "v2" }, new String[] { "t1", "t2" }, new Aggregation[] { Aggregation.SUM, Aggregation.LAST }, MeasurementType.GAUGE), 1000);
store.saveMeasurements(mid, 0L, 1, 2);
store.saveMeasurements(mid, 1000L, 3, 4);
store.saveMeasurements(mid, 2000L, 5, 6);
store.saveMeasurements(mid, 2000L, 7, 8);
store.saveMeasurements(mid, 3000L, 9, 10);
store.saveMeasurements(mid, 4000L, 11, 12);
store.flush();
MeasurementStoreQuery query = store.query();
Collection<Schema> measurements = query.getMeasurements((x) -> true);
Schema metric = measurements.iterator().next();
Assert.assertEquals("test", metric.getName());
List<TimeSeriesRecord> results = getMetrics(query, metric, Instant.EPOCH, Instant.now());
Assert.assertEquals(6, results.size());
TimeSeriesRecord rec = results.get(0);
Assert.assertEquals(Instant.ofEpochMilli(0L), rec.getTimeStamp());
Assert.assertEquals(1L, rec.getLongValue("v1"));
Assert.assertEquals(2L, rec.getLongValue("v2"));
rec = results.get(5);
Assert.assertEquals(Instant.ofEpochMilli(4000L), rec.getTimeStamp());
Assert.assertEquals(11L, rec.getLongValue("v1"));
Assert.assertEquals(12L, rec.getLongValue("v2"));
results = getMetrics(query, metric, Instant.ofEpochMilli(2000L), Instant.ofEpochMilli(2000L));
Assert.assertEquals(2, results.size());
rec = results.get(0);
Assert.assertEquals(Instant.ofEpochMilli(2000L), rec.getTimeStamp());
Assert.assertEquals(5L, rec.getLongValue("v1"));
Assert.assertEquals(6L, rec.getLongValue("v2"));
rec = results.get(1);
Assert.assertEquals(Instant.ofEpochMilli(2000L), rec.getTimeStamp());
Assert.assertEquals(7L, rec.getLongValue("v1"));
Assert.assertEquals(8L, rec.getLongValue("v2"));
List<TimeSeriesRecord> aggr = getMetrics(query, metric, Instant.EPOCH, Instant.now(), 1000);
Assert.assertEquals(5, aggr.size());
rec = aggr.get(0);
Assert.assertEquals(Instant.ofEpochMilli(0L), rec.getTimeStamp());
Assert.assertEquals(1L, rec.getLongValue("v1"));
Assert.assertEquals(2L, rec.getLongValue("v2"));
rec = aggr.get(2);
Assert.assertEquals(Instant.ofEpochMilli(2000L), rec.getTimeStamp());
Assert.assertEquals(12L, rec.getLongValue("v1"));
Assert.assertEquals(8L, rec.getLongValue("v2"));
aggr = getMetrics(query, metric, Instant.EPOCH, Instant.now(), 1500);
Assert.assertEquals(5, aggr.size());
aggr = getMetrics(query, metric, Instant.EPOCH, Instant.now(), 0);
Assert.assertEquals(6, aggr.size());
try (AvroCloseableIterable<TimeSeriesRecord> it = query.getAggregatedMeasurementData(metric, Instant.EPOCH, Instant.now(), Duration.between(Instant.EPOCH, Instant.now()).getSeconds(), TimeUnit.SECONDS)) {
Iterator<TimeSeriesRecord> iterator = it.iterator();
TimeSeriesRecord next = iterator.next();
LOG.debug("The aggregate", next);
Assert.assertFalse(iterator.hasNext());
Assert.assertEquals(36L, next.getLongValue("v1"));
Assert.assertEquals(12L, next.getLongValue("v2"));
}
} finally {
store.close();
Files.delete(store.getInfoFile());
Files.delete(store.getDataFile());
}
}
use of org.spf4j.perf.MeasurementStoreQuery in project spf4j by zolyfarkas.
the class AllocationMonitorAspectTest method testAfterAllocation.
/**
* Test of afterAllocation method, of class AllocationMonitorAspect.
*/
@Test
public void testAfterAllocation() throws InterruptedException, IOException {
System.setProperty("spf4j.perf.allocations.sampleTimeMillis", "1000");
MemoryUsageSampler.start(500);
OpenFilesSampler.start(500, 512, 1000, false);
for (int i = 0; i < 1000; i++) {
LOG.debug("T{}", i);
if (i % 100 == 0) {
Thread.sleep(500);
}
}
testAllocInStaticContext();
TestClass.testAllocInStaticContext();
MeasurementStore measurementStore = ProcessMeasurementStore.getMeasurementStore();
measurementStore.flush();
MeasurementStoreQuery query = measurementStore.query();
Collection<Schema> measurements = query.getMeasurements((x) -> "process_heap_used".equals(x));
Assert.assertEquals(1, measurements.size());
MemoryUsageSampler.stop();
OpenFilesSampler.stop();
}
Aggregations