use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class CpuUsageSampler method start.
@JmxExport
public static synchronized void start(@JmxExport("sampleTimeMillis") final int sampleTime) {
if (samplingFuture == null) {
final MeasurementRecorder cpuUsage = RecorderFactory.createDirectRecorder("cpu-time", "ns", sampleTime);
samplingFuture = DefaultScheduler.INSTANCE.scheduleWithFixedDelay(new AbstractRunnable() {
private long lastValue = 0;
@Override
public void doRun() {
long currTime = getProcessCpuTimeNanos();
cpuUsage.record(currTime - lastValue);
lastValue = currTime;
}
}, sampleTime, sampleTime, TimeUnit.MILLISECONDS);
} else {
throw new IllegalStateException("Cpu time Sampling already started " + samplingFuture);
}
}
use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class ThreadUsageSampler method getPeakThreadInfo.
@JmxExport
@SuppressFBWarnings({ "DM_DEFAULT_ENCODING", "NP_LOAD_OF_KNOWN_NULL_VALUE" })
public static String getPeakThreadInfo() {
try (ByteArrayBuilder bab = new ByteArrayBuilder()) {
PrintStream ps = new PrintStream(bab);
writePeakThreadInfo(ps);
return bab.toString(Charset.defaultCharset());
}
}
use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class GCUsageSampler method start.
@JmxExport
public static synchronized void start(@JmxExport("sampleTimeMillis") final int sampleTime) {
if (samplingFuture == null) {
final MeasurementRecorder gcUsage = RecorderFactory.createDirectRecorder("gc-time", "ms", sampleTime);
samplingFuture = DefaultScheduler.INSTANCE.scheduleWithFixedDelay(new AbstractRunnable() {
private final TObjectLongMap lastValues = new TObjectLongHashMap();
@Override
public void doRun() {
synchronized (lastValues) {
gcUsage.record(getGCTimeDiff(MBEANS, lastValues));
}
}
}, sampleTime, sampleTime, TimeUnit.MILLISECONDS);
} else {
throw new IllegalStateException("GC usage sampling already started " + samplingFuture);
}
}
use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class JdbcSemaphore method totalPermits.
@JmxExport(description = "Get the total permits this semaphore can hand out")
public int totalPermits() throws SQLException, InterruptedException {
return jdbc.transactOnConnection((final Connection conn, final long deadlineNanos) -> {
try (PreparedStatement stmt = conn.prepareStatement(totalPermitsSql)) {
stmt.setNString(1, semName);
stmt.setQueryTimeout(JdbcTemplate.getTimeoutToDeadlineSeconds(deadlineNanos));
try (ResultSet rs = stmt.executeQuery()) {
if (!rs.next()) {
throw new IllegalStateException();
} else {
return rs.getInt(1);
}
}
}
}, jdbcTimeoutSeconds, TimeUnit.SECONDS);
}
use of org.spf4j.jmx.JmxExport in project spf4j by zolyfarkas.
the class JdbcSemaphore method permitsOwned.
@JmxExport(description = "get the number of permits owned by this process")
public int permitsOwned() throws SQLException, InterruptedException {
return jdbc.transactOnConnection((final Connection conn, final long deadlineNanos) -> {
try (PreparedStatement stmt = conn.prepareStatement(ownedPermitsSql)) {
stmt.setNString(1, org.spf4j.base.Runtime.PROCESS_ID);
stmt.setNString(2, semName);
stmt.setQueryTimeout(JdbcTemplate.getTimeoutToDeadlineSeconds(deadlineNanos));
try (ResultSet rs = stmt.executeQuery()) {
if (!rs.next()) {
throw new IllegalStateException();
} else {
int result = rs.getInt(1);
if (rs.next()) {
throw new IllegalStateException();
}
return result;
}
}
}
}, jdbcTimeoutSeconds, TimeUnit.SECONDS);
}
Aggregations