Search in sources :

Example 1 with XContentBuilder

use of org.opensearch.common.xcontent.XContentBuilder in project fess by codelibs.

the class SystemMonitorTarget method appendFesenStats.

private void appendFesenStats(final StringBuilder buf) {
    String stats = null;
    try {
        final SearchEngineClient esClient = ComponentUtil.getSearchEngineClient();
        final NodesStatsResponse response = esClient.admin().cluster().prepareNodesStats().all().execute().actionGet(10000L);
        final XContentBuilder builder = XContentFactory.jsonBuilder();
        builder.startObject();
        response.toXContent(builder, ToXContent.EMPTY_PARAMS);
        builder.endObject();
        builder.flush();
        try (OutputStream out = builder.getOutputStream()) {
            stats = ((ByteArrayOutputStream) out).toString(Constants.UTF_8);
        }
    } catch (final Exception e) {
        logger.debug("Failed to access Fesen stats.", e);
    }
    buf.append("\"elasticsearch\":").append(stats).append(',');
}
Also used : NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 SearchEngineClient (org.codelibs.fess.es.client.SearchEngineClient)1 NodesStatsResponse (org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1