Search in sources :

Example 1 with TSDBMeasurementStore

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);
    }
}
Also used : CsvParseException(org.spf4j.io.csv.CsvParseException) StringReader(java.io.StringReader) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) MeasurementStore(org.spf4j.perf.MeasurementStore) MultiStore(org.spf4j.perf.impl.ms.MultiStore) File(java.io.File) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) Nonnull(javax.annotation.Nonnull) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with TSDBMeasurementStore

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);
}
Also used : InputStreamReader(java.io.InputStreamReader) TableDefEx(org.spf4j.tsdb2.TSDBQuery.TableDefEx) TSDBWriter(org.spf4j.tsdb2.TSDBWriter) BufferedReader(java.io.BufferedReader) Collection(java.util.Collection) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) TSDBWriter(org.spf4j.tsdb2.TSDBWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) Test(org.junit.Test)

Example 3 with TSDBMeasurementStore

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);
}
Also used : TSDBWriter(org.spf4j.tsdb2.TSDBWriter) TimeSeries(org.spf4j.tsdb2.TimeSeries) File(java.io.File) TableDef(org.spf4j.tsdb2.avro.TableDef) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with TSDBMeasurementStore

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();
}
Also used : TSDBWriter(org.spf4j.tsdb2.TSDBWriter) File(java.io.File) TableDef(org.spf4j.tsdb2.avro.TableDef) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) Test(org.junit.Test)

Aggregations

File (java.io.File)4 TSDBMeasurementStore (org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore)4 TSDBWriter (org.spf4j.tsdb2.TSDBWriter)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Test (org.junit.Test)2 TableDef (org.spf4j.tsdb2.avro.TableDef)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 Collection (java.util.Collection)1 Nonnull (javax.annotation.Nonnull)1 CsvParseException (org.spf4j.io.csv.CsvParseException)1 MeasurementStore (org.spf4j.perf.MeasurementStore)1 MultiStore (org.spf4j.perf.impl.ms.MultiStore)1 TableDefEx (org.spf4j.tsdb2.TSDBQuery.TableDefEx)1 TimeSeries (org.spf4j.tsdb2.TimeSeries)1