mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Some renaming to put stats in the name of things + added shard stats export
This commit is contained in:
parent
8bce30d892
commit
4d921448fe
4 changed files with 56 additions and 29 deletions
|
@ -23,8 +23,6 @@ import com.google.common.collect.ImmutableList;
|
|||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.ESLoggerFactory;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.plugins.AbstractPlugin;
|
||||
|
||||
|
@ -52,7 +50,7 @@ public class Plugin extends AbstractPlugin {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ExportersService.class).asEagerSingleton();
|
||||
bind(StatsExportersService.class).asEagerSingleton();
|
||||
}
|
||||
};
|
||||
return ImmutableList.of(m);
|
||||
|
@ -61,7 +59,7 @@ public class Plugin extends AbstractPlugin {
|
|||
@Override
|
||||
public Collection<Class<? extends LifecycleComponent>> services() {
|
||||
Collection<Class<? extends LifecycleComponent>> l = new ArrayList<Class<? extends LifecycleComponent>>();
|
||||
l.add(ExportersService.class);
|
||||
l.add(StatsExportersService.class);
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,15 @@ package com.elasticsearch.dash;
|
|||
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||
import org.elasticsearch.action.admin.indices.stats.ShardStats;
|
||||
import org.elasticsearch.common.component.CloseableComponent;
|
||||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
|
||||
public interface Exporter<T> extends LifecycleComponent<T> {
|
||||
public interface StatsExporter<T> extends LifecycleComponent<T> {
|
||||
|
||||
String name();
|
||||
|
||||
void exportNodeStats(NodeStats nodeStats);
|
||||
|
||||
void exportShardStats(ShardStats shardStats);
|
||||
}
|
|
@ -19,46 +19,49 @@ package com.elasticsearch.dash;/*
|
|||
|
||||
|
||||
import com.elasticsearch.dash.exporters.ESExporter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags;
|
||||
import org.elasticsearch.action.admin.indices.stats.ShardStats;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.concurrent.EsExecutors;
|
||||
import org.elasticsearch.indices.IndicesService;
|
||||
import org.elasticsearch.indices.InternalIndicesService;
|
||||
import org.elasticsearch.node.service.NodeService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ExportersService extends AbstractLifecycleComponent<ExportersService> {
|
||||
public class StatsExportersService extends AbstractLifecycleComponent<StatsExportersService> {
|
||||
|
||||
private final IndicesService indicesService;
|
||||
private final InternalIndicesService indicesService;
|
||||
private final NodeService nodeService;
|
||||
|
||||
private volatile ExportingWorker exp;
|
||||
private volatile Thread thread;
|
||||
private final TimeValue interval;
|
||||
|
||||
private Collection<Exporter> exporters;
|
||||
private Collection<StatsExporter> exporters;
|
||||
|
||||
@Inject
|
||||
public ExportersService(Settings settings, IndicesService indicesService,ClusterName clusterName, NodeService nodeService) {
|
||||
public StatsExportersService(Settings settings, IndicesService indicesService, ClusterName clusterName, NodeService nodeService) {
|
||||
super(settings);
|
||||
this.indicesService = indicesService;
|
||||
this.indicesService = (InternalIndicesService) indicesService;
|
||||
this.nodeService = nodeService;
|
||||
this.interval = componentSettings.getAsTime("interval", TimeValue.timeValueSeconds(5));
|
||||
|
||||
Exporter esExporter = new ESExporter(settings.getComponentSettings(ESExporter.class), clusterName );
|
||||
StatsExporter esExporter = new ESExporter(settings.getComponentSettings(ESExporter.class), clusterName);
|
||||
this.exporters = ImmutableSet.of(esExporter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws ElasticSearchException {
|
||||
for (Exporter e: exporters)
|
||||
for (StatsExporter e : exporters)
|
||||
e.start();
|
||||
|
||||
this.exp = new ExportingWorker();
|
||||
|
@ -71,13 +74,13 @@ public class ExportersService extends AbstractLifecycleComponent<ExportersServic
|
|||
protected void doStop() throws ElasticSearchException {
|
||||
this.exp.closed = true;
|
||||
this.thread.interrupt();
|
||||
for (Exporter e: exporters)
|
||||
for (StatsExporter e : exporters)
|
||||
e.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() throws ElasticSearchException {
|
||||
for (Exporter e: exporters)
|
||||
for (StatsExporter e : exporters)
|
||||
e.close();
|
||||
}
|
||||
|
||||
|
@ -94,19 +97,34 @@ public class ExportersService extends AbstractLifecycleComponent<ExportersServic
|
|||
NodeStats nodeStats = nodeService.stats();
|
||||
|
||||
logger.debug("Exporting node stats");
|
||||
for (Exporter e: exporters) {
|
||||
for (StatsExporter e : exporters) {
|
||||
try {
|
||||
e.exportNodeStats(nodeStats);
|
||||
}
|
||||
catch (Throwable t){
|
||||
logger.error("Exporter {} has thrown an exception:", t, e.name());
|
||||
} catch (Throwable t) {
|
||||
logger.error("StatsExporter {} has thrown an exception:", t, e.name());
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Collecting shard stats");
|
||||
List<ShardStats> shardStatsList = indicesService.shardLevelStats(CommonStatsFlags.ALL);
|
||||
|
||||
logger.debug("Exporting shards stats");
|
||||
for (StatsExporter e : exporters) {
|
||||
try {
|
||||
for (ShardStats shardStats : shardStatsList)
|
||||
e.exportShardStats(shardStats);
|
||||
} catch (Throwable t) {
|
||||
logger.error("StatsExporter {} has thrown an exception:", t, e.name());
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
logger.error("Background thread had an uncaught exception:", t);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(interval.millis());
|
||||
} catch (InterruptedException e) {
|
||||
// ignore, if closed, good....
|
||||
} catch (Throwable t) {
|
||||
logger.error("Background thread had an uncaught exception:", t);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,11 +19,12 @@ package com.elasticsearch.dash.exporters;
|
|||
*/
|
||||
|
||||
|
||||
import com.elasticsearch.dash.Exporter;
|
||||
import com.elasticsearch.dash.StatsExporter;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||
import org.elasticsearch.action.admin.indices.stats.ShardStats;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
|
@ -43,7 +44,7 @@ import java.net.URL;
|
|||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
|
||||
public class ESExporter extends AbstractLifecycleComponent<ESExporter> implements Exporter<ESExporter> {
|
||||
public class ESExporter extends AbstractLifecycleComponent<ESExporter> implements StatsExporter<ESExporter> {
|
||||
|
||||
final String targetHost;
|
||||
final int targetPort;
|
||||
|
@ -102,8 +103,17 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
|
|||
|
||||
@Override
|
||||
public void exportNodeStats(NodeStats nodeStats) {
|
||||
URL url = getTargetURL("nodestats");
|
||||
logger.debug("Exporting node stats to {}", url);
|
||||
exportXContent("nodestats", nodeStats);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportShardStats(ShardStats shardStats) {
|
||||
exportXContent("shardstats", shardStats);
|
||||
}
|
||||
|
||||
private void exportXContent(String type,ToXContent xContent) {
|
||||
URL url = getTargetURL(type);
|
||||
logger.debug("Exporting {} to {}", type, url);
|
||||
HttpURLConnection conn;
|
||||
try {
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
|
@ -114,7 +124,7 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
|
|||
XContentBuilder builder = XContentFactory.smileBuilder(os);
|
||||
|
||||
builder.startObject();
|
||||
nodeStats.toXContent(builder, xContentParams);
|
||||
xContent.toXContent(builder, xContentParams);
|
||||
builder.endObject();
|
||||
|
||||
builder.close();
|
||||
|
@ -128,10 +138,8 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doStart() throws ElasticSearchException {
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue