org.elasticsearch.monitor.os.OsProbe Java Examples

The following examples show how to use org.elasticsearch.monitor.os.OsProbe. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystemHelper.java    From fess with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: SystemMonitorTarget.java    From fess with Apache License 2.0 6 votes vote down vote up
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("},");
}
 
Example #3
Source File: MonitorModule.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    // bind default implementations
    bind(ProcessProbe.class).toInstance(ProcessProbe.getInstance());
    bind(OsProbe.class).toInstance(OsProbe.getInstance());
    bind(FsProbe.class).asEagerSingleton();

    // bind other services
    bind(ProcessService.class).asEagerSingleton();
    bind(OsService.class).asEagerSingleton();
    bind(JvmService.class).asEagerSingleton();
    bind(FsService.class).asEagerSingleton();

    bind(JvmMonitorService.class).asEagerSingleton();
}
 
Example #4
Source File: ExtendedNodeInfo.java    From crate with Apache License 2.0 5 votes vote down vote up
private ExtendedOsStats osStatsProbe() {
    OsStats osStats = OsProbe.getInstance().osStats();
    OsStats.Cpu cpuProbe = osStats.getCpu();
    ExtendedOsStats.Cpu cpu = new ExtendedOsStats.Cpu(cpuProbe.getPercent());
    return new ExtendedOsStats(
        System.currentTimeMillis(),
        cpu,
        cpuProbe.getLoadAverage() == null ? NA_LOAD : cpuProbe.getLoadAverage(),
        SysInfo.getSystemUptime(),
        osStats);
}
 
Example #5
Source File: BootstrapProxy.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
static void initializeProbes() {
    // Force probes to be loaded
    ProcessProbe.getInstance();
    OsProbe.getInstance();
}
 
Example #6
Source File: Bootstrap.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
static void initializeProbes() {
    // Force probes to be loaded
    ProcessProbe.getInstance();
    OsProbe.getInstance();
}
 
Example #7
Source File: ThumbnailGenerator.java    From fess with Apache License 2.0 4 votes vote down vote up
static void initializeProbes() {
    // Force probes to be loaded
    ProcessProbe.getInstance();
    OsProbe.getInstance();
    JvmInfo.jvmInfo();
}
 
Example #8
Source File: SuggestCreator.java    From fess with Apache License 2.0 4 votes vote down vote up
static void initializeProbes() {
    // Force probes to be loaded
    ProcessProbe.getInstance();
    OsProbe.getInstance();
    JvmInfo.jvmInfo();
}
 
Example #9
Source File: Crawler.java    From fess with Apache License 2.0 4 votes vote down vote up
static void initializeProbes() {
    // Force probes to be loaded
    ProcessProbe.getInstance();
    OsProbe.getInstance();
    JvmInfo.jvmInfo();
}
 
Example #10
Source File: BootstrapProxy.java    From crate with Apache License 2.0 4 votes vote down vote up
static void initializeProbes() {
    // Force probes to be loaded
    ProcessProbe.getInstance();
    OsProbe.getInstance();
    JvmInfo.jvmInfo();
}
 
Example #11
Source File: NodeStatsContextTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testStreamContext() throws Exception {
    NodeStatsContext ctx1 = new NodeStatsContext(true);
    ctx1.id("93c7ff92-52fa-11e6-aad8-3c15c2d3ad18");
    ctx1.name("crate1");
    ctx1.hostname("crate1.example.com");
    ctx1.timestamp(100L);
    ctx1.version(Version.CURRENT);
    ctx1.build(Build.CURRENT);
    ctx1.httpPort(4200);
    ctx1.transportPort(4300);
    ctx1.restUrl("10.0.0.1:4200");
    ctx1.jvmStats(JvmStats.jvmStats());
    ctx1.osInfo(DummyOsInfo.INSTANCE);
    ProcessProbe processProbe = ProcessProbe.getInstance();
    ctx1.processStats(processProbe.processStats());
    OsProbe osProbe = OsProbe.getInstance();
    ctx1.osStats(osProbe.osStats());
    ctx1.extendedOsStats(extendedNodeInfo.osStats());
    ctx1.threadPools(threadPool.stats());
    ctx1.clusterStateVersion(10L);

    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    StreamOutput out = new OutputStreamStreamOutput(outBuffer);
    ctx1.writeTo(out);

    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput in = new InputStreamStreamInput(inBuffer);
    NodeStatsContext ctx2 = new NodeStatsContext(in, true);

    assertThat(ctx1.id(), is(ctx2.id()));
    assertThat(ctx1.name(), is(ctx2.name()));
    assertThat(ctx1.hostname(), is(ctx2.hostname()));
    assertThat(ctx1.timestamp(), is(100L));
    assertThat(ctx1.version(), is(ctx2.version()));
    assertThat(ctx1.build().hash(), is(ctx2.build().hash()));
    assertThat(ctx1.restUrl(), is(ctx2.restUrl()));
    assertThat(ctx1.httpPort(), is(ctx2.httpPort()));
    assertThat(ctx1.transportPort(), is(ctx2.transportPort()));
    assertThat(ctx1.pgPort(), is(ctx2.pgPort()));
    assertThat(ctx1.jvmStats().getTimestamp(), is(ctx2.jvmStats().getTimestamp()));
    assertThat(ctx1.osInfo().getArch(), is(ctx2.osInfo().getArch()));
    assertThat(ctx1.processStats().getTimestamp(), is(ctx2.processStats().getTimestamp()));
    assertThat(ctx1.osStats().getTimestamp(), is(ctx2.osStats().getTimestamp()));
    assertThat(ctx1.extendedOsStats().uptime(), is(ctx2.extendedOsStats().uptime()));
    assertThat(ctx1.threadPools().iterator().next().getActive(), is(ctx2.threadPools().iterator().next().getActive()));
    assertThat(ctx1.clusterStateVersion(), is(ctx2.clusterStateVersion()));
}