private void completeNodeAttributes(ProtobufSystemInfo.Section.Builder protobuf) { NodesStatsResponse nodesStats = esClient.prepareNodesStats() .setFs(true) .setProcess(true) .setJvm(true) .setIndices(true) .setBreaker(true) .get(); if (!nodesStats.getNodes().isEmpty()) { NodeStats stats = nodesStats.getNodes().get(0); toProtobuf(stats, protobuf); } }
private boolean isBulkProcessorAvailable() { NodesStatsResponse response = client.admin().cluster().prepareNodesStats().setThreadPool(true).get(); for (NodeStats nodeStats : response.getNodes()) { Iterator<Stats> iterator = nodeStats.getThreadPool().iterator(); while (iterator.hasNext()) { Stats stats = iterator.next(); if ("bulk".equals(stats.getName())) { int queue = stats.getQueue(); logger.trace("bulkQueueSize [{}] - queue [{}] - availability [{}]", bulkQueueSize, queue, 1 - (queue / bulkQueueSize)); return 1 - (queue / bulkQueueSize) > 0.1; } } } return true; }
public static void toProtobuf(NodeStats stats, ProtobufSystemInfo.Section.Builder protobuf) { setAttribute(protobuf, "CPU Usage (%)", stats.getProcess().getCpu().getPercent()); setAttribute(protobuf, "Disk Available", byteCountToDisplaySize(stats.getFs().getTotal().getAvailable().getBytes())); setAttribute(protobuf, "Store Size", byteCountToDisplaySize(stats.getIndices().getStore().getSizeInBytes())); setAttribute(protobuf, "Open File Descriptors", stats.getProcess().getOpenFileDescriptors()); setAttribute(protobuf, "Max File Descriptors", stats.getProcess().getMaxFileDescriptors()); setAttribute(protobuf, "Spinning", stats.getFs().getTotal().getSpins()); setAttribute(protobuf, "JVM Heap Usage", formatPercent(stats.getJvm().getMem().getHeapUsedPercent())); setAttribute(protobuf, "JVM Heap Used", byteCountToDisplaySize(stats.getJvm().getMem().getHeapUsed().getBytes())); setAttribute(protobuf, "JVM Heap Max", byteCountToDisplaySize(stats.getJvm().getMem().getHeapMax().getBytes())); setAttribute(protobuf, "JVM Non Heap Used", byteCountToDisplaySize(stats.getJvm().getMem().getNonHeapUsed().getBytes())); setAttribute(protobuf, "JVM Threads", stats.getJvm().getThreads().getCount()); setAttribute(protobuf, "Field Data Memory", byteCountToDisplaySize(stats.getIndices().getFieldData().getMemorySizeInBytes())); setAttribute(protobuf, "Field Data Circuit Breaker Limit", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getLimit())); setAttribute(protobuf, "Field Data Circuit Breaker Estimation", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getEstimated())); setAttribute(protobuf, "Request Circuit Breaker Limit", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.REQUEST).getLimit())); setAttribute(protobuf, "Request Circuit Breaker Estimation", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.REQUEST).getEstimated())); setAttribute(protobuf, "Query Cache Memory", byteCountToDisplaySize(stats.getIndices().getQueryCache().getMemorySizeInBytes())); setAttribute(protobuf, "Request Cache Memory", byteCountToDisplaySize(stats.getIndices().getRequestCache().getMemorySizeInBytes())); }
@Test public void stats() { es.client().prepareNodesStats().get(); }
private static NodeInfo toNodeInfo(NodeStats stat) { String nodeName = stat.getNode().getName(); NodeInfo info = new NodeInfo(nodeName); info.setHost(stat.getHostname()); ProtobufSystemInfo.Section.Builder section = ProtobufSystemInfo.Section.newBuilder(); section.setName("Search State"); EsStateSection.toProtobuf(stat, section); info.addSection(section.build()); return info; }
@Override public NodesStatsResponse get() { Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start(); try { return super.execute().actionGet(); } catch (Exception e) { throw new IllegalStateException(String.format("Fail to execute %s", toString()), e); } finally { if (profiler.isTraceEnabled()) { profiler.stopTrace(toString()); } } }
NodesStatsResponse nir = tc.admin().cluster().nodesStats(new NodesStatsRequest()).actionGet(); sb.append(Strings.toString(nir,true, true)); } catch (Exception e1) {
/** * Should the node indices stats be returned. */ public NodesStatsRequestBuilder setIndices(boolean indices) { request.indices(indices); return this; }
/** * Should the node OS stats be returned. */ public NodesStatsRequestBuilder setOs(boolean os) { request.os(os); return this; }
/** * Should the node Transport stats be returned. */ public NodesStatsRequestBuilder setTransport(boolean transport) { request.transport(transport); return this; }
/** * Should the node JVM stats be returned. */ public NodesStatsRequestBuilder setJvm(boolean jvm) { request.jvm(jvm); return this; }
@Test public void to_string() { assertThat(es.client().prepareNodesStats().setNodesIds("node1").toString()).isEqualTo("ES nodes stats request on nodes 'node1'"); assertThat(es.client().prepareNodesStats().toString()).isEqualTo("ES nodes stats request"); }
@Override public NodesStatsRequestBuilder newRequestBuilder(ElasticsearchClient client) { return new NodesStatsRequestBuilder(client, this); } }
public Collection<NodeInfo> load() { NodesStatsResponse nodesStats = esClient.prepareNodesStats() .setFs(true) .setProcess(true) .setJvm(true) .setIndices(true) .setBreaker(true) .get(); List<NodeInfo> result = new ArrayList<>(); nodesStats.getNodes().forEach(nodeStat -> result.add(toNodeInfo(nodeStat))); return result; }
@Test public void trace_logs() { logTester.setLevel(LoggerLevel.TRACE); es.client().prepareNodesStats().get(); assertThat(logTester.logs()).hasSize(1); }
@Test public void execute_should_throw_an_unsupported_operation_exception() { thrown.expect(UnsupportedOperationException.class); thrown.expectMessage("execute() should not be called as it's used for asynchronous"); es.client().prepareNodesStats(FakeIndexDefinition.INDEX).execute(); }
@Test public void get_with_string_timeout_is_not_yet_implemented() { thrown.expect(IllegalStateException.class); thrown.expectMessage("Not yet implemented"); es.client().prepareNodesStats(FakeIndexDefinition.INDEX).get("1"); }
@Test public void get_with_time_value_timeout_is_not_yet_implemented() { thrown.expect(IllegalStateException.class); thrown.expectMessage("Not yet implemented"); es.client().prepareNodesStats(FakeIndexDefinition.INDEX).get(TimeValue.timeValueMinutes(1)); }