Search in sources :

Example 1 with ProcessProbe

use of org.elasticsearch.monitor.process.ProcessProbe in project crate by crate.

the class NodeStatsContextTest method testStreamContext.

@Test
public void testStreamContext() throws Exception {
    NodeStatsContext ctx1 = new NodeStatsContext(true);
    ctx1.id(BytesRefs.toBytesRef("93c7ff92-52fa-11e6-aad8-3c15c2d3ad18"));
    ctx1.name(BytesRefs.toBytesRef("crate1"));
    ctx1.hostname(BytesRefs.toBytesRef("crate1.example.com"));
    ctx1.timestamp(100L);
    ctx1.version(Version.CURRENT);
    ctx1.build(Build.CURRENT);
    ctx1.restUrl(BytesRefs.toBytesRef("10.0.0.1:4200"));
    ctx1.port(new HashMap<String, Integer>(2) {

        {
            put("http", 4200);
            put("transport", 4300);
        }
    });
    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.networkStats(extendedNodeInfo.networkStats());
    ctx1.extendedProcessCpuStats(extendedNodeInfo.processCpuStats());
    ctx1.extendedFsStats(extendedNodeInfo.fsStats());
    ctx1.threadPools(ThreadPools.newInstance(threadPool));
    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(true);
    ctx2.readFrom(in);
    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.port(), is(ctx2.port()));
    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.networkStats().timestamp(), is(ctx2.networkStats().timestamp()));
    assertThat(ctx1.extendedProcessCpuStats().percent(), is(ctx2.extendedProcessCpuStats().percent()));
    assertThat(ctx1.extendedFsStats().size(), is(ctx2.extendedFsStats().size()));
    assertThat(ctx1.threadPools(), is(ctx2.threadPools()));
}
Also used : OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessProbe(org.elasticsearch.monitor.process.ProcessProbe) OsProbe(org.elasticsearch.monitor.os.OsProbe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with ProcessProbe

use of org.elasticsearch.monitor.process.ProcessProbe in project crate by crate.

the class NodeStatsContextTest method testStreamContext.

@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()));
}
Also used : OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessProbe(org.elasticsearch.monitor.process.ProcessProbe) OsProbe(org.elasticsearch.monitor.os.OsProbe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStreamStreamInput (org.elasticsearch.common.io.stream.InputStreamStreamInput)2 OutputStreamStreamOutput (org.elasticsearch.common.io.stream.OutputStreamStreamOutput)2 StreamOutput (org.elasticsearch.common.io.stream.StreamOutput)2 OsProbe (org.elasticsearch.monitor.os.OsProbe)2 ProcessProbe (org.elasticsearch.monitor.process.ProcessProbe)2 Test (org.junit.Test)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)1 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1