Search in sources :

Example 1 with OsInfo

use of org.elasticsearch.monitor.os.OsInfo in project elasticsearch by elastic.

the class NodeInfoStreamingTests method createNodeInfo.

private static NodeInfo createNodeInfo() {
    Build build = Build.CURRENT;
    DiscoveryNode node = new DiscoveryNode("test_node", buildNewFakeTransportAddress(), emptyMap(), emptySet(), VersionUtils.randomVersion(random()));
    Settings settings = randomBoolean() ? null : Settings.builder().put("test", "setting").build();
    OsInfo osInfo = null;
    if (randomBoolean()) {
        int availableProcessors = randomIntBetween(1, 64);
        int allocatedProcessors = randomIntBetween(1, availableProcessors);
        long refreshInterval = randomBoolean() ? -1 : randomNonNegativeLong();
        String name = randomAsciiOfLengthBetween(3, 10);
        String arch = randomAsciiOfLengthBetween(3, 10);
        String version = randomAsciiOfLengthBetween(3, 10);
        osInfo = new OsInfo(refreshInterval, availableProcessors, allocatedProcessors, name, arch, version);
    }
    ProcessInfo process = randomBoolean() ? null : new ProcessInfo(randomInt(), randomBoolean(), randomNonNegativeLong());
    JvmInfo jvm = randomBoolean() ? null : JvmInfo.jvmInfo();
    ThreadPoolInfo threadPoolInfo = null;
    if (randomBoolean()) {
        int numThreadPools = randomIntBetween(1, 10);
        List<ThreadPool.Info> threadPoolInfos = new ArrayList<>(numThreadPools);
        for (int i = 0; i < numThreadPools; i++) {
            threadPoolInfos.add(new ThreadPool.Info(randomAsciiOfLengthBetween(3, 10), randomFrom(ThreadPool.ThreadPoolType.values()), randomInt()));
        }
        threadPoolInfo = new ThreadPoolInfo(threadPoolInfos);
    }
    Map<String, BoundTransportAddress> profileAddresses = new HashMap<>();
    BoundTransportAddress dummyBoundTransportAddress = new BoundTransportAddress(new TransportAddress[] { buildNewFakeTransportAddress() }, buildNewFakeTransportAddress());
    profileAddresses.put("test_address", dummyBoundTransportAddress);
    TransportInfo transport = randomBoolean() ? null : new TransportInfo(dummyBoundTransportAddress, profileAddresses);
    HttpInfo httpInfo = randomBoolean() ? null : new HttpInfo(dummyBoundTransportAddress, randomLong());
    PluginsAndModules pluginsAndModules = null;
    if (randomBoolean()) {
        int numPlugins = randomIntBetween(0, 5);
        List<PluginInfo> plugins = new ArrayList<>();
        for (int i = 0; i < numPlugins; i++) {
            plugins.add(new PluginInfo(randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10)));
        }
        int numModules = randomIntBetween(0, 5);
        List<PluginInfo> modules = new ArrayList<>();
        for (int i = 0; i < numModules; i++) {
            modules.add(new PluginInfo(randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10), randomAsciiOfLengthBetween(3, 10)));
        }
        pluginsAndModules = new PluginsAndModules(plugins, modules);
    }
    IngestInfo ingestInfo = null;
    if (randomBoolean()) {
        int numProcessors = randomIntBetween(0, 5);
        List<ProcessorInfo> processors = new ArrayList<>(numProcessors);
        for (int i = 0; i < numProcessors; i++) {
            processors.add(new ProcessorInfo(randomAsciiOfLengthBetween(3, 10)));
        }
        ingestInfo = new IngestInfo(processors);
    }
    ByteSizeValue indexingBuffer = null;
    if (randomBoolean()) {
        // pick a random long that sometimes exceeds an int:
        indexingBuffer = new ByteSizeValue(random().nextLong() & ((1L << 40) - 1));
    }
    return new NodeInfo(VersionUtils.randomVersion(random()), build, node, settings, osInfo, process, jvm, threadPoolInfo, transport, httpInfo, pluginsAndModules, ingestInfo, indexingBuffer);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) JvmInfo(org.elasticsearch.monitor.jvm.JvmInfo) ProcessorInfo(org.elasticsearch.ingest.ProcessorInfo) HashMap(java.util.HashMap) PluginsAndModules(org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules) ArrayList(java.util.ArrayList) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) HttpInfo(org.elasticsearch.http.HttpInfo) OsInfo(org.elasticsearch.monitor.os.OsInfo) Build(org.elasticsearch.Build) IngestInfo(org.elasticsearch.ingest.IngestInfo) PluginInfo(org.elasticsearch.plugins.PluginInfo) Settings(org.elasticsearch.common.settings.Settings) ThreadPoolInfo(org.elasticsearch.threadpool.ThreadPoolInfo) TransportInfo(org.elasticsearch.transport.TransportInfo) ProcessInfo(org.elasticsearch.monitor.process.ProcessInfo) PluginInfo(org.elasticsearch.plugins.PluginInfo) OsInfo(org.elasticsearch.monitor.os.OsInfo) ThreadPoolInfo(org.elasticsearch.threadpool.ThreadPoolInfo) ProcessInfo(org.elasticsearch.monitor.process.ProcessInfo) IngestInfo(org.elasticsearch.ingest.IngestInfo) JvmInfo(org.elasticsearch.monitor.jvm.JvmInfo) ProcessorInfo(org.elasticsearch.ingest.ProcessorInfo) HttpInfo(org.elasticsearch.http.HttpInfo) TransportInfo(org.elasticsearch.transport.TransportInfo) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress)

Example 2 with OsInfo

use of org.elasticsearch.monitor.os.OsInfo 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)

Aggregations

ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)2 OsInfo (org.elasticsearch.monitor.os.OsInfo)2 DummyExtendedNodeInfo (io.crate.monitor.DummyExtendedNodeInfo)1 ExtendedNodeInfo (io.crate.monitor.ExtendedNodeInfo)1 TestingHelpers.mapToSortedString (io.crate.testing.TestingHelpers.mapToSortedString)1 File (java.io.File)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Build (org.elasticsearch.Build)1 NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)1 PluginsAndModules (org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 Settings (org.elasticsearch.common.settings.Settings)1 BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)1 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)1 HttpInfo (org.elasticsearch.http.HttpInfo)1 IngestInfo (org.elasticsearch.ingest.IngestInfo)1 ProcessorInfo (org.elasticsearch.ingest.ProcessorInfo)1 JvmInfo (org.elasticsearch.monitor.jvm.JvmInfo)1