Search in sources :

Example 1 with OsService

use of org.elasticsearch.monitor.os.OsService in project crate by crate.

the class SysNodesExpressionsOnHandlerTest method setup.

@BeforeClass
public static void setup() throws IOException {
    // jvm
    JvmStats jvmStats = mock(JvmStats.class);
    JvmStats.Mem jvmStatsMem = mock(JvmStats.Mem.class);
    ByteSizeValue heapByteSizeValueMax = new ByteSizeValue(123456L);
    when(jvmStatsMem.getHeapMax()).thenReturn(heapByteSizeValueMax);
    when(jvmStatsMem.getHeapUsed()).thenReturn(heapByteSizeValueMax);
    when(jvmStats.getMem()).thenReturn(jvmStatsMem);
    // mem
    ByteSizeValue byteSizeValue = new ByteSizeValue(12345342234L);
    // os service
    OsService osService = mock(OsService.class);
    OsStats osStats = mock(OsStats.class);
    when(osService.stats()).thenReturn(osStats);
    OsStats.Mem mem = mock(OsStats.Mem.class);
    when(osStats.getMem()).thenReturn(mem);
    when(mem.getFree()).thenReturn(byteSizeValue);
    when(mem.getUsed()).thenReturn(byteSizeValue);
    when(mem.getUsedPercent()).thenReturn((short) 22);
    when(mem.getFreePercent()).thenReturn((short) 78);
    // os info
    OsInfo osInfo = mock(OsInfo.class);
    when(osService.info()).thenReturn(osInfo);
    when(osInfo.getAvailableProcessors()).thenReturn(4);
    // node info
    NodeEnvironment nodeEnv = mock(NodeEnvironment.class);
    Path[] dataLocations = new Path[] { new File("/foo").toPath(), new File("/bar").toPath() };
    when(nodeEnv.hasNodeFile()).then(invocation -> true);
    when(nodeEnv.nodeDataPaths()).thenReturn(dataLocations);
    ExtendedNodeInfo extendedNodeInfo = new DummyExtendedNodeInfo(nodeEnv);
    // process stats
    ProcessStats processStats = mock(ProcessStats.class);
    when(processStats.getOpenFileDescriptors()).thenReturn(42L);
    when(processStats.getMaxFileDescriptors()).thenReturn(1000L);
    CONTEXT.id(BytesRefs.toBytesRef("93c7ff92-52fa-11e6-aad8-3c15c2d3ad18"));
    CONTEXT.name(BytesRefs.toBytesRef("crate1"));
    CONTEXT.hostname(BytesRefs.toBytesRef("crate1.example.com"));
    CONTEXT.version(Version.CURRENT);
    CONTEXT.build(Build.CURRENT);
    CONTEXT.timestamp(100L);
    CONTEXT.restUrl(BytesRefs.toBytesRef("10.0.0.1:4200"));
    CONTEXT.port(new HashMap<String, Integer>(2) {

        {
            put("http", 4200);
            put("transport", 4300);
        }
    });
    CONTEXT.jvmStats(jvmStats);
    CONTEXT.osInfo(osInfo);
    CONTEXT.processStats(processStats);
    CONTEXT.osStats(osStats);
    CONTEXT.extendedOsStats(extendedNodeInfo.osStats());
    CONTEXT.networkStats(extendedNodeInfo.networkStats());
    CONTEXT.extendedProcessCpuStats(extendedNodeInfo.processCpuStats());
    CONTEXT.extendedFsStats(extendedNodeInfo.fsStats());
}
Also used : JvmStats(org.elasticsearch.monitor.jvm.JvmStats) Path(java.nio.file.Path) ProcessStats(org.elasticsearch.monitor.process.ProcessStats) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) DummyExtendedNodeInfo(io.crate.monitor.DummyExtendedNodeInfo) ExtendedNodeInfo(io.crate.monitor.ExtendedNodeInfo) OsStats(org.elasticsearch.monitor.os.OsStats) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) OsService(org.elasticsearch.monitor.os.OsService) OsInfo(org.elasticsearch.monitor.os.OsInfo) File(java.io.File) DummyExtendedNodeInfo(io.crate.monitor.DummyExtendedNodeInfo) BeforeClass(org.junit.BeforeClass)

Example 2 with OsService

use of org.elasticsearch.monitor.os.OsService in project crate by crate.

the class NodeStatsContextFieldResolverTest method setup.

@Before
public void setup() throws UnknownHostException {
    final OsService osService = mock(OsService.class);
    final OsStats osStats = mock(OsStats.class);
    final MonitorService monitorService = mock(MonitorService.class);
    when(monitorService.osService()).thenReturn(osService);
    when(osService.stats()).thenReturn(osStats);
    DiscoveryNode discoveryNode = newNode("node_name", "node_id");
    postgresAddress = new TransportAddress(Inet4Address.getLocalHost(), 5432);
    resolver = new NodeStatsContextFieldResolver(() -> discoveryNode, monitorService, () -> null, () -> new HttpStats(20L, 30L), mock(ThreadPool.class), new ExtendedNodeInfo(), () -> new ConnectionStats(2L, 4L), () -> postgresAddress, () -> 12L, () -> 1L);
}
Also used : OsService(org.elasticsearch.monitor.os.OsService) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MonitorService(org.elasticsearch.monitor.MonitorService) TransportAddress(org.elasticsearch.common.transport.TransportAddress) HttpStats(org.elasticsearch.http.HttpStats) ExtendedNodeInfo(io.crate.monitor.ExtendedNodeInfo) ConnectionStats(io.crate.protocols.ConnectionStats) OsStats(org.elasticsearch.monitor.os.OsStats) Before(org.junit.Before)

Aggregations

ExtendedNodeInfo (io.crate.monitor.ExtendedNodeInfo)2 OsService (org.elasticsearch.monitor.os.OsService)2 OsStats (org.elasticsearch.monitor.os.OsStats)2 DummyExtendedNodeInfo (io.crate.monitor.DummyExtendedNodeInfo)1 ConnectionStats (io.crate.protocols.ConnectionStats)1 TestingHelpers.mapToSortedString (io.crate.testing.TestingHelpers.mapToSortedString)1 File (java.io.File)1 Path (java.nio.file.Path)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 TransportAddress (org.elasticsearch.common.transport.TransportAddress)1 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)1 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)1 HttpStats (org.elasticsearch.http.HttpStats)1 MonitorService (org.elasticsearch.monitor.MonitorService)1 JvmStats (org.elasticsearch.monitor.jvm.JvmStats)1 OsInfo (org.elasticsearch.monitor.os.OsInfo)1 ProcessStats (org.elasticsearch.monitor.process.ProcessStats)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1