Search in sources :

Example 1 with OsProbe

use of org.opensearch.monitor.os.OsProbe in project fess by codelibs.

the class SystemHelper method getSystemCpuPercent.

protected short getSystemCpuPercent() {
    final long now = System.currentTimeMillis();
    if (now - systemCpuCheckTime > systemCpuCheckInterval) {
        synchronized (this) {
            if (now - systemCpuCheckTime > systemCpuCheckInterval) {
                try {
                    final OsProbe osProbe = OsProbe.getInstance();
                    systemCpuPercent = osProbe.getSystemCpuPercent();
                    if (logger.isDebugEnabled()) {
                        logger.debug("Updated System Cpu {}%", systemCpuPercent);
                    }
                } catch (final Exception e) {
                    logger.warn("Failed to get SystemCpuPercent.", e);
                    return 0;
                }
                systemCpuCheckTime = now;
            }
        }
    }
    return systemCpuPercent;
}
Also used : OsProbe(org.opensearch.monitor.os.OsProbe) IORuntimeException(org.codelibs.core.exception.IORuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FessSystemException(org.codelibs.fess.exception.FessSystemException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with OsProbe

use of org.opensearch.monitor.os.OsProbe in project fess by codelibs.

the class SystemMonitorTarget method appendOsStats.

private void appendOsStats(final StringBuilder buf) {
    buf.append("\"os\":{");
    final OsProbe osProbe = OsProbe.getInstance();
    buf.append("\"memory\":{");
    buf.append("\"physical\":{");
    append(buf, "free", () -> osProbe.getFreePhysicalMemorySize()).append(',');
    append(buf, "total", () -> osProbe.getTotalPhysicalMemorySize());
    buf.append("},");
    buf.append("\"swap_space\":{");
    append(buf, "free", () -> osProbe.getFreeSwapSpaceSize()).append(',');
    append(buf, "total", () -> osProbe.getTotalSwapSpaceSize());
    buf.append('}');
    buf.append("},");
    buf.append("\"cpu\":{");
    append(buf, "percent", () -> osProbe.getSystemCpuPercent());
    final OsStats osStats = osProbe.osStats();
    buf.append("},");
    append(buf, "load_averages", () -> osStats.getCpu().getLoadAverage());
    buf.append("},");
}
Also used : OsProbe(org.opensearch.monitor.os.OsProbe) OsStats(org.opensearch.monitor.os.OsStats)

Aggregations

OsProbe (org.opensearch.monitor.os.OsProbe)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 IORuntimeException (org.codelibs.core.exception.IORuntimeException)1 FessSystemException (org.codelibs.fess.exception.FessSystemException)1 OsStats (org.opensearch.monitor.os.OsStats)1