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);
}
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());
}
Aggregations