use of org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore in project spf4j by zolyfarkas.
the class RecorderFactory method buildStoreFromConfig.
/**
* Configuration is a coma separated list of stores:
* TSDB@/path/to/file.tsdb,TSDB_TXT@/path/to/file.tsdbtxt,GRAPHITE_UDP@1.1.1.1:8080,GRAPHITE_TCP@1.1.1.1:8080
*
* @param configuration
* @return a measurement store.
*/
@Nonnull
// the config is not supplied by a user.
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
private static MeasurementStore buildStoreFromConfig(@Nullable final String configuration) throws IOException, ObjectCreationException {
if (configuration == null || configuration.trim().isEmpty()) {
return new TSDBMeasurementStore(new File(System.getProperty("spf4j.perf.ms.defaultTsdbFolderPath", System.getProperty("java.io.tmpdir")) + File.separator + CharSequences.validatedFileName(System.getProperty("spf4j.perf.ms.defaultTsdbFileNamePrefix", ManagementFactory.getRuntimeMXBean().getName() + ".tsdb2"))));
}
List<String> stores;
try {
stores = Csv.readRow(new StringReader(configuration));
} catch (CsvParseException ex) {
throw new IllegalArgumentException("Invalid configuration " + configuration, ex);
}
final int size = stores.size();
if (size == 1) {
return fromString(stores.get(0));
} else {
MeasurementStore[] mstores = new MeasurementStore[size];
int i = 0;
for (String config : stores) {
mstores[i] = fromString(config);
i++;
}
return new MultiStore(mstores);
}
}
use of org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore 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);
}
}
TSDBWriter dbWriter = ((TSDBMeasurementStore) RecorderFactory.MEASUREMENT_STORE).getDBWriter();
dbWriter.flush();
final File file = dbWriter.getFile();
ListMultimap<String, TableDefEx> allTables = TSDBQuery.getAllTablesWithDataRanges(file);
LOG.debug("Tables {}", allTables);
Map<String, Collection<TableDefEx>> asMap = allTables.asMap();
Assert.assertThat(asMap, (Matcher) Matchers.hasKey("file-write,org.spf4j.perf.aspects.FileMonitorAspectTest"));
Assert.assertThat(asMap, (Matcher) Matchers.hasKey("file-read,org.spf4j.perf.aspects.FileMonitorAspectTest"));
List<TableDefEx> get = allTables.get("file-write,org.spf4j.perf.aspects.FileMonitorAspectTest");
Assert.assertTrue(get.get(0).getStartTime() != 0);
Assert.assertTrue(OperatingSystem.getOpenFileDescriptorCount() > 0);
}
use of org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore in project spf4j by zolyfarkas.
the class RecorderFactoryTest method assertData.
@SuppressFBWarnings("CLI_CONSTANT_LIST_INDEX")
public static void assertData(final String forWhat, final long expectedValue) throws IOException {
TSDBWriter dbWriter = ((TSDBMeasurementStore) RecorderFactory.MEASUREMENT_STORE).getDBWriter();
dbWriter.flush();
final File file = dbWriter.getFile();
List<TableDef> tableDefs = TSDBQuery.getTableDef(file, forWhat);
TableDef tableDef = tableDefs.get(0);
TimeSeries timeSeries = TSDBQuery.getTimeSeries(file, new long[] { tableDef.id }, 0, Long.MAX_VALUE);
long sum = 0;
long[][] values = timeSeries.getValues();
for (long[] row : values) {
sum += row[0];
}
Assert.assertEquals(expectedValue, sum);
}
use of org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore 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();
final TSDBWriter dbWriter = ((TSDBMeasurementStore) RecorderFactory.MEASUREMENT_STORE).getDBWriter();
dbWriter.flush();
File file = dbWriter.getFile();
List<TableDef> tableDef = TSDBQuery.getTableDef(file, "heap-used");
Assert.assertFalse(tableDef.isEmpty());
MemoryUsageSampler.stop();
OpenFilesSampler.stop();
}
Aggregations