Search in sources :

Example 31 with TimeSeries

use of org.spf4j.tsdb2.TimeSeries in project spf4j by zolyfarkas.

the class Charts method createHeatJFreeChart.

public static JFreeChart createHeatJFreeChart(final TimeSeries data, final TableDef info) {
    Pair<long[], double[][]> mData = fillGaps(data.getTimeStamps(), data.getValues(), info.getSampleTime(), info.getColumns().size());
    ColumnDef columnDef = TSDBQuery.getColumnDef(info, "total");
    return org.spf4j.perf.impl.chart.Charts.createHeatJFreeChart(TSDBQuery.getColumnNames(info), mData.getSecond(), data.getTimeStamps()[0], info.getSampleTime(), columnDef.getUnitOfMeasurement(), "Measurements distribution for " + info.getName() + ", sampleTime " + info.getSampleTime() + "ms, generated by spf4j");
}
Also used : ColumnDef(org.spf4j.tsdb2.avro.ColumnDef)

Example 32 with TimeSeries

use of org.spf4j.tsdb2.TimeSeries in project spf4j by zolyfarkas.

the class Charts method createJFreeCharts.

public static List<JFreeChart> createJFreeCharts(final TimeSeries data, final TableDef info) {
    long[][] vals = data.getValues();
    Map<String, Pair<List<String>, List<double[]>>> measurementsByUom = new HashMap<>();
    // String[] columnMetaData = TSDBQuery.getColumnUnitsOfMeasurement(info);
    int i = 0;
    for (ColumnDef colDef : info.getColumns()) {
        String uom = colDef.getUnitOfMeasurement();
        Pair<List<String>, List<double[]>> meas = measurementsByUom.get(uom);
        if (meas == null) {
            meas = Pair.of((List<String>) new ArrayList<String>(), (List<double[]>) new ArrayList<double[]>());
            measurementsByUom.put(uom, meas);
        }
        meas.getFirst().add(colDef.getName());
        meas.getSecond().add(Arrays.getColumnAsDoubles(vals, i));
        i++;
    }
    long[] timestamps = data.getTimeStamps();
    List<JFreeChart> result = new ArrayList<>(measurementsByUom.size());
    for (Map.Entry<String, Pair<List<String>, List<double[]>>> entry : measurementsByUom.entrySet()) {
        Pair<List<String>, List<double[]>> p = entry.getValue();
        final List<String> measurementNames = p.getFirst();
        final List<double[]> measurements = p.getSecond();
        result.add(org.spf4j.perf.impl.chart.Charts.createTimeSeriesJFreeChart("chart for " + info.getName() + ", sampleTime " + info.getSampleTime() + " ms, generated by spf4j", timestamps, measurementNames.toArray(new String[measurementNames.size()]), entry.getKey(), measurements.toArray(new double[measurements.size()][])));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ColumnDef(org.spf4j.tsdb2.avro.ColumnDef) JFreeChart(org.jfree.chart.JFreeChart) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Pair(org.spf4j.base.Pair)

Example 33 with TimeSeries

use of org.spf4j.tsdb2.TimeSeries in project spf4j by zolyfarkas.

the class TimeSeriesDatabase method tail.

@SuppressFBWarnings("MDM_THREAD_YIELD")
public void tail(final long pollMillis, final long from, final TSDataHandler handler) throws IOException {
    Map<String, TSTable> lastState = new HashMap<>();
    long lastSize = 0;
    while (!Thread.currentThread().isInterrupted() && !handler.finish()) {
        long currSize = this.file.length();
        if (currSize > lastSize) {
            // see if we have new Tables;
            reReadTableInfos();
            Map<String, TSTable> currState = getTsTables();
            for (String tableName : Sets.difference(currState.keySet(), lastState.keySet())) {
                handler.newTable(tableName, currState.get(tableName).getColumnNames());
            }
            for (TSTable table : currState.values()) {
                final String tableName = table.getTableName();
                TSTable prevTableState = lastState.get(tableName);
                final long currLastDataFragment = table.getLastDataFragment();
                if (prevTableState == null) {
                    long lastDataFragment = table.getFirstDataFragment();
                    if (lastDataFragment > 0) {
                        TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, false);
                        handler.newData(tableName, data);
                    }
                } else {
                    long lastDataFragment = prevTableState.getLastDataFragment();
                    if (lastDataFragment == 0) {
                        lastDataFragment = table.getFirstDataFragment();
                        if (lastDataFragment > 0) {
                            TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, false);
                            handler.newData(tableName, data);
                        }
                    } else if (currLastDataFragment > lastDataFragment) {
                        TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, true);
                        handler.newData(tableName, data);
                    }
                }
            }
            lastState = currState;
        }
        lastSize = currSize;
        try {
            Thread.sleep(pollMillis);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
            break;
        }
    }
}
Also used : TimeSeries(org.spf4j.tsdb2.TimeSeries) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 34 with TimeSeries

use of org.spf4j.tsdb2.TimeSeries in project spf4j by zolyfarkas.

the class TimeSeriesDatabase method createHeatJFreeChart.

public JFreeChart createHeatJFreeChart(final String tableName, final long startTime, final long endTime) throws IOException {
    TSTable info = this.getTSTable(tableName);
    TimeSeries data = this.read(tableName, startTime, endTime);
    return createHeatJFreeChart(data, info);
}
Also used : TimeSeries(org.spf4j.tsdb2.TimeSeries)

Example 35 with TimeSeries

use of org.spf4j.tsdb2.TimeSeries in project spf4j by zolyfarkas.

the class TimeSeriesDatabase method createCountJFreeChart.

public JFreeChart createCountJFreeChart(final String tableName, final long startTime, final long endTime) throws IOException {
    TSTable info = this.getTSTable(tableName);
    TimeSeries data = this.read(tableName, startTime, endTime);
    return createCountJFreeChart(data, info);
}
Also used : TimeSeries(org.spf4j.tsdb2.TimeSeries)

Aggregations

TimeSeries (com.google.monitoring.v3.TimeSeries)17 TimeSeries (org.spf4j.tsdb2.TimeSeries)11 ArrayList (java.util.ArrayList)10 ProjectName (com.google.monitoring.v3.ProjectName)9 Test (org.junit.Test)9 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)6 TimeInterval (com.google.monitoring.v3.TimeInterval)6 ListTimeSeriesPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse)5 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)5 ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)5 HashMap (java.util.HashMap)5 MonitoredResource (com.google.api.MonitoredResource)3 Map (java.util.Map)3 ColumnDef (org.spf4j.tsdb2.avro.ColumnDef)3 Metric (com.google.api.Metric)2 Aggregation (com.google.monitoring.v3.Aggregation)2 Point (com.google.monitoring.v3.Point)2 TypedValue (com.google.monitoring.v3.TypedValue)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 TLongArrayList (gnu.trove.list.array.TLongArrayList)2