Search in sources :

Example 6 with JmxExport

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);
    }
}
Also used : AbstractRunnable(org.spf4j.base.AbstractRunnable) MeasurementRecorder(org.spf4j.perf.MeasurementRecorder) JmxExport(org.spf4j.jmx.JmxExport)

Example 7 with JmxExport

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());
    }
}
Also used : PrintStream(java.io.PrintStream) ByteArrayBuilder(org.spf4j.io.ByteArrayBuilder) JmxExport(org.spf4j.jmx.JmxExport) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with JmxExport

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);
    }
}
Also used : AbstractRunnable(org.spf4j.base.AbstractRunnable) TObjectLongHashMap(gnu.trove.map.hash.TObjectLongHashMap) MeasurementRecorder(org.spf4j.perf.MeasurementRecorder) TObjectLongMap(gnu.trove.map.TObjectLongMap) JmxExport(org.spf4j.jmx.JmxExport)

Example 9 with JmxExport

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);
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JmxExport(org.spf4j.jmx.JmxExport)

Example 10 with JmxExport

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);
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JmxExport(org.spf4j.jmx.JmxExport)

Aggregations

JmxExport (org.spf4j.jmx.JmxExport)14 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)4 AbstractRunnable (org.spf4j.base.AbstractRunnable)4 IOException (java.io.IOException)3 MeasurementRecorder (org.spf4j.perf.MeasurementRecorder)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 TObjectLongMap (gnu.trove.map.TObjectLongMap)2 TObjectLongHashMap (gnu.trove.map.hash.TObjectLongHashMap)2 StringWriter (java.io.StringWriter)2 UncheckedIOException (java.io.UncheckedIOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MeasurementsInfo (org.spf4j.perf.MeasurementsInfo)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1