mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Added cluster stats export
This commit is contained in:
parent
7a2d6d840f
commit
8c9cb28dce
3 changed files with 57 additions and 3 deletions
|
@ -21,6 +21,7 @@ package org.elasticsearch.marvel.monitor;
|
|||
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
|
||||
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||
import org.elasticsearch.action.admin.indices.stats.ShardStats;
|
||||
|
@ -165,13 +166,12 @@ public class ExportersService extends AbstractLifecycleComponent<ExportersServic
|
|||
// do the actual export..., go over the actual exporters list and...
|
||||
try {
|
||||
exportNodeStats();
|
||||
|
||||
exportShardStats();
|
||||
|
||||
exportEvents();
|
||||
|
||||
if (clusterService.state().nodes().localNodeMaster()) {
|
||||
exportIndicesStats();
|
||||
exportClusterStats();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
logger.error("Background thread had an uncaught exception:", t);
|
||||
|
@ -186,7 +186,7 @@ public class ExportersService extends AbstractLifecycleComponent<ExportersServic
|
|||
}
|
||||
|
||||
private void exportIndicesStats() {
|
||||
logger.debug("local node is master, exporting aggregated stats");
|
||||
logger.debug("local node is master, exporting indices stats");
|
||||
IndicesStatsResponse indicesStatsResponse = client.admin().indices().prepareStats().all().get();
|
||||
for (StatsExporter e : exporters) {
|
||||
try {
|
||||
|
@ -197,6 +197,18 @@ public class ExportersService extends AbstractLifecycleComponent<ExportersServic
|
|||
}
|
||||
}
|
||||
|
||||
private void exportClusterStats() {
|
||||
logger.debug("local node is master, exporting cluster stats");
|
||||
ClusterStatsResponse stats = client.admin().cluster().prepareClusterStats().get();
|
||||
for (StatsExporter e : exporters) {
|
||||
try {
|
||||
e.exportClusterStats(stats);
|
||||
} catch (Throwable t) {
|
||||
logger.error("StatsExporter [{}] has thrown an exception:", t, e.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void exportEvents() {
|
||||
logger.debug("Exporting events");
|
||||
ArrayList<Event> eventList = new ArrayList<Event>(pendingEventsQueue.size());
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.marvel.monitor.exporter;
|
|||
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
|
||||
import org.elasticsearch.action.admin.indices.stats.CommonStats;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndexStats;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||
|
@ -66,6 +67,7 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
|
|||
final ShardStatsRenderer shardStatsRenderer;
|
||||
final IndexStatsRenderer indexStatsRenderer;
|
||||
final IndicesStatsRenderer indicesStatsRenderer;
|
||||
final ClusterStatsRenderer clusterStatsRenderer;
|
||||
final EventsRenderer eventsRenderer;
|
||||
|
||||
public ESExporter(Settings settings, Discovery discovery) {
|
||||
|
@ -84,6 +86,7 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
|
|||
shardStatsRenderer = new ShardStatsRenderer();
|
||||
indexStatsRenderer = new IndexStatsRenderer();
|
||||
indicesStatsRenderer = new IndicesStatsRenderer();
|
||||
clusterStatsRenderer = new ClusterStatsRenderer();
|
||||
eventsRenderer = new EventsRenderer();
|
||||
|
||||
logger.debug("Initialized with targets: {}, index prefix [{}], index time format [{}]", hosts, indexPrefix, indexTimeFormat);
|
||||
|
@ -133,6 +136,12 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
|
|||
exportXContent(eventsRenderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportClusterStats(ClusterStatsResponse clusterStats) {
|
||||
clusterStatsRenderer.reset(clusterStats);
|
||||
exportXContent(clusterStatsRenderer);
|
||||
}
|
||||
|
||||
|
||||
private HttpURLConnection openExportingConnection() {
|
||||
if (!checkedForIndexTemplate) {
|
||||
|
@ -502,5 +511,35 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
|
|||
}
|
||||
}
|
||||
|
||||
class ClusterStatsRenderer implements MultiXContentRenderer {
|
||||
|
||||
ClusterStatsResponse stats;
|
||||
ToXContent.MapParams xContentParams = new ToXContent.MapParams(
|
||||
ImmutableMap.of("output_uuid", "true"));
|
||||
|
||||
public void reset(ClusterStatsResponse stats) {
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type(int i) {
|
||||
return "cluster_stats";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int index, XContentBuilder builder) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field("@timestamp", defaultDatePrinter.print(stats.getTimestamp()));
|
||||
addNodeInfo(builder);
|
||||
stats.toXContent(builder, xContentParams);
|
||||
builder.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.elasticsearch.marvel.monitor.exporter;
|
|||
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||
import org.elasticsearch.action.admin.indices.stats.ShardStats;
|
||||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
|
@ -36,4 +37,6 @@ public interface StatsExporter<T> extends LifecycleComponent<T> {
|
|||
void exportIndicesStats(IndicesStatsResponse indicesStats);
|
||||
|
||||
void exportEvents(Event[] events);
|
||||
|
||||
void exportClusterStats(ClusterStatsResponse clusterStats);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue