use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class TimeSeriesDatabase method generateCharts.
/**
* Quantized recorders will have min, max avg charts and distribution charts generated. Counting recorders will have
* simple charts generated.
*
* @param startTimeMillis
* @param endTimeMillis
* @param width
* @param height
* @return
* @throws IOException
*/
@JmxExport(value = "generateChartsInterval", description = "generate charts for all measurements in specified interval")
public List<String> generateCharts(final long startTimeMillis, final long endTimeMillis, final int width, final int height) throws IOException {
try {
this.flush();
Collection<TSTable> columnsInfo = this.getTSTables();
List<String> result = new ArrayList<>(16);
for (TSTable info : columnsInfo) {
TimeSeries data = this.read(info.getTableName(), startTimeMillis, endTimeMillis);
if (data.getTimeStamps().length > 0) {
if (canGenerateMinMaxAvgCount(info)) {
result.add(generateMinMaxAvgCountChart(info, data, width, height));
}
if (canGenerateHeatChart(info)) {
result.add(generateHeatChart(info, data, width, height));
}
}
}
Multimap<String, TSTable> counters = getCounters(columnsInfo);
Map<String, Collection<TSTable>> asMap = counters.asMap();
for (Map.Entry<String, Collection<TSTable>> entry : asMap.entrySet()) {
Collection<TSTable> ltables = entry.getValue();
int l = ltables.size();
long[][] timestamps = new long[l][];
double[][] cdata = new double[l][];
double[][] cdata2 = new double[l][];
int i = 0;
String[] measurementNames = new String[cdata.length];
String[] measurementNames2 = new String[cdata2.length];
String uom1 = "count";
String uom2 = "";
for (TSTable colInfo : ltables) {
TimeSeries data = this.read(colInfo.getTableName(), startTimeMillis, endTimeMillis);
timestamps[i] = data.getTimeStamps();
final long[][] values = data.getValues();
cdata[i] = Arrays.getColumnAsDoubles(values, colInfo.getColumnIndex("count"));
cdata2[i] = Arrays.getColumnAsDoubles(values, colInfo.getColumnIndex("total"));
measurementNames[i] = colInfo.getTableName() + ".count";
measurementNames2[i] = colInfo.getTableName() + ".total";
uom2 = new String(colInfo.getTableMetaData(), Charsets.UTF_8);
i++;
}
result.add(generateCountChart(entry.getKey(), timestamps, measurementNames, measurementNames2, uom1, uom2, cdata, cdata2, width, height));
}
return result;
} catch (IOException | RuntimeException ex) {
throw ex;
}
}
use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorder method getMeasurementsAsString.
@JmxExport(description = "measurements as csv")
public String getMeasurementsAsString() {
StringWriter sw = new StringWriter(128);
MeasurementsInfo info = getInfo();
try {
Csv.writeCsvRow(sw, (Object[]) info.getMeasurementNames());
Csv.writeCsvRow(sw, (Object[]) info.getMeasurementUnits());
final long[] values = get();
if (values != null) {
Csv.writeCsvRow(sw, values);
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return sw.toString();
}
use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class Sampler method start.
@JmxExport(description = "start stack sampling")
public synchronized void start() {
if (stopped) {
stopped = false;
final int stNanos = sampleTimeNanos;
samplerFuture = DefaultExecutor.INSTANCE.submit(new AbstractRunnable("SPF4J-Sampling-Thread") {
@SuppressWarnings("SleepWhileInLoop")
@SuppressFBWarnings({ "MDM_THREAD_YIELD", "PREDICTABLE_RANDOM" })
@Override
public void doRun() throws IOException, InterruptedException {
synchronized (sync) {
stackCollector = stackCollectorSupp.get(Thread.currentThread());
}
final ThreadLocalRandom random = ThreadLocalRandom.current();
int dumpCounterNanos = 0;
int coarseCounter = 0;
int coarseCount = STOP_FLAG_READ_MILLIS / stNanos;
boolean lstopped = stopped;
int sleepTimeNanos = 0;
int halfStNanos = stNanos / 2;
if (halfStNanos == 0) {
halfStNanos = 1;
}
int maxSleeepNanos = stNanos + halfStNanos;
while (!lstopped) {
synchronized (sync) {
stackCollector.sample();
}
dumpCounterNanos += sleepTimeNanos;
coarseCounter++;
if (coarseCounter >= coarseCount) {
coarseCounter = 0;
lstopped = stopped;
}
if (dumpCounterNanos >= dumpTimeNanos) {
long nanosSinceLastDump = TimeSource.nanoTime() - lastDumpTimeNanos;
if (nanosSinceLastDump >= dumpTimeNanos) {
dumpCounterNanos = 0;
dumpToFile();
} else {
dumpCounterNanos -= dumpTimeNanos - nanosSinceLastDump;
}
}
sleepTimeNanos = random.nextInt(halfStNanos, maxSleeepNanos);
TimeUnit.NANOSECONDS.sleep(sleepTimeNanos);
}
}
});
} else {
throw new IllegalStateException("Sampling can only be started once for " + this);
}
}
use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class ThreadUsageSampler method start.
@JmxExport
public static synchronized void start(@JmxExport("sampleTimeMillis") final int sampleTime, @JmxExport("withStackTraces") final boolean withStackTraces) {
if (samplingFuture == null) {
final MeasurementRecorder cpuUsage = RecorderFactory.createDirectRecorder("peak-thread-count", "count", sampleTime);
samplingFuture = DefaultScheduler.INSTANCE.scheduleWithFixedDelay(new AbstractRunnable() {
private int maxThreadsNr = 0;
@Override
public void doRun() {
final int peakThreadCount = TH_BEAN.getPeakThreadCount();
cpuUsage.record(peakThreadCount);
if (peakThreadCount > maxThreadsNr) {
Thread[] ths = Threads.getThreads();
if (ths.length > PEAK_THREAD_NAMES.size()) {
if (withStackTraces) {
StackTraceElement[][] stackTraces = Threads.getStackTraces(ths);
PEAK_THREAD_TRACES.clear();
PEAK_THREAD_TRACES.addAll(Arrays.asList(stackTraces));
}
PEAK_THREAD_NAMES.clear();
int i = 0;
for (Thread th : ths) {
PEAK_THREAD_NAMES.add(th.getName());
if (th.isDaemon()) {
PEAK_THREAD_DAEMON.set(i);
} else {
PEAK_THREAD_DAEMON.clear(i);
}
i++;
}
}
maxThreadsNr = peakThreadCount;
}
TH_BEAN.resetPeakThreadCount();
}
}, sampleTime, sampleTime, TimeUnit.MILLISECONDS);
} else {
throw new IllegalStateException("Thread sampling already started " + samplingFuture);
}
}
Aggregations