Monitoring: Clean log messages in exporters
This commit adds the node name and the exporter name as log message prefixes. Original commit: elastic/x-pack-elasticsearch@085b2ecf3c
This commit is contained in:
parent
926ff76971
commit
2c1dbf3eb6
|
@ -95,7 +95,7 @@ public abstract class Exporter implements AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ESLogger logger(Class clazz) {
|
public ESLogger logger(Class clazz) {
|
||||||
return Loggers.getLogger(clazz, globalSettings);
|
return Loggers.getLogger(clazz, globalSettings, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.settings.SettingsException;
|
import org.elasticsearch.common.settings.SettingsException;
|
||||||
import org.elasticsearch.marvel.MarvelSettings;
|
import org.elasticsearch.marvel.MarvelSettings;
|
||||||
import org.elasticsearch.marvel.agent.exporter.local.LocalExporter;
|
import org.elasticsearch.marvel.agent.exporter.local.LocalExporter;
|
||||||
|
import org.elasticsearch.node.Node;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -116,6 +117,11 @@ public class Exporters extends AbstractLifecycleComponent<Exporters> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Exporter> initExporters(Settings settings) {
|
Map<String, Exporter> initExporters(Settings settings) {
|
||||||
|
Settings globalSettings = Settings.builder()
|
||||||
|
.put(settings)
|
||||||
|
.put(Node.NODE_NAME_SETTING.getKey(), nodeName())
|
||||||
|
.build();
|
||||||
|
|
||||||
Set<String> singletons = new HashSet<>();
|
Set<String> singletons = new HashSet<>();
|
||||||
Map<String, Exporter> exporters = new HashMap<>();
|
Map<String, Exporter> exporters = new HashMap<>();
|
||||||
boolean hasDisabled = false;
|
boolean hasDisabled = false;
|
||||||
|
@ -129,7 +135,7 @@ public class Exporters extends AbstractLifecycleComponent<Exporters> implements
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
throw new SettingsException("unknown exporter type [" + type + "] set for exporter [" + name + "]");
|
throw new SettingsException("unknown exporter type [" + type + "] set for exporter [" + name + "]");
|
||||||
}
|
}
|
||||||
Exporter.Config config = new Exporter.Config(name, settings, exporterSettings);
|
Exporter.Config config = new Exporter.Config(name, globalSettings, exporterSettings);
|
||||||
if (!config.enabled()) {
|
if (!config.enabled()) {
|
||||||
hasDisabled = true;
|
hasDisabled = true;
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
|
@ -155,7 +161,7 @@ public class Exporters extends AbstractLifecycleComponent<Exporters> implements
|
||||||
// fallback on the default
|
// fallback on the default
|
||||||
//
|
//
|
||||||
if (exporters.isEmpty() && !hasDisabled) {
|
if (exporters.isEmpty() && !hasDisabled) {
|
||||||
Exporter.Config config = new Exporter.Config("default_" + LocalExporter.TYPE, settings, Settings.EMPTY);
|
Exporter.Config config = new Exporter.Config("default_" + LocalExporter.TYPE, globalSettings, Settings.EMPTY);
|
||||||
exporters.put(config.name(), factories.get(LocalExporter.TYPE).create(config));
|
exporters.put(config.name(), factories.get(LocalExporter.TYPE).create(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -223,15 +223,14 @@ public class HttpExporter extends Exporter {
|
||||||
out.write(CONTENT_TYPE.xContent().streamSeparator());
|
out.write(CONTENT_TYPE.xContent().streamSeparator());
|
||||||
|
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("http exporter [{}] - added index request [index={}, type={}, id={}]",
|
logger.trace("added index request [index={}, type={}, id={}]", index, type, id);
|
||||||
name(), index, type, id);
|
|
||||||
}
|
}
|
||||||
} else if (logger.isTraceEnabled()) {
|
} else if (logger.isTraceEnabled()) {
|
||||||
logger.trace("http exporter [{}] - no resolver found for monitoring document [class={}, id={}, version={}]",
|
logger.trace("no resolver found for monitoring document [class={}, id={}, version={}]",
|
||||||
name(), doc.getClass().getName(), doc.getMonitoringId(), doc.getMonitoringVersion());
|
doc.getClass().getName(), doc.getMonitoringId(), doc.getMonitoringVersion());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("http exporter [{}] - failed to render document [{}], skipping it", e, name(), doc);
|
logger.warn("failed to render document [{}], skipping it", e, doc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,7 +425,7 @@ public class HttpExporter extends Exporter {
|
||||||
// Works like LocalExporter on master:
|
// Works like LocalExporter on master:
|
||||||
// Install the index template for timestamped indices first, so that other nodes can ship data
|
// Install the index template for timestamped indices first, so that other nodes can ship data
|
||||||
if (!templateInstalled) {
|
if (!templateInstalled) {
|
||||||
logger.debug("http exporter [{}] - could not find existing monitoring template, installing a new one", name());
|
logger.debug("could not find existing monitoring template, installing a new one");
|
||||||
if (!putTemplate(host, templateName, MarvelTemplateUtils.loadTimestampedIndexTemplate())) {
|
if (!putTemplate(host, templateName, MarvelTemplateUtils.loadTimestampedIndexTemplate())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -435,7 +434,7 @@ public class HttpExporter extends Exporter {
|
||||||
// Install the index template for data index
|
// Install the index template for data index
|
||||||
templateName = MarvelTemplateUtils.dataTemplateName(templateVersion);
|
templateName = MarvelTemplateUtils.dataTemplateName(templateVersion);
|
||||||
if (!hasTemplate(templateName, host)) {
|
if (!hasTemplate(templateName, host)) {
|
||||||
logger.debug("http exporter [{}] - could not find existing monitoring template for data index, installing a new one", name());
|
logger.debug("could not find existing monitoring template for data index, installing a new one");
|
||||||
if (!putTemplate(host, templateName, MarvelTemplateUtils.loadDataIndexTemplate())) {
|
if (!putTemplate(host, templateName, MarvelTemplateUtils.loadDataIndexTemplate())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -451,8 +450,7 @@ public class HttpExporter extends Exporter {
|
||||||
|
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
try {
|
try {
|
||||||
logger.debug("http exporter [{}] - checking if monitoring template [{}] exists on the monitoring cluster",
|
logger.debug("checking if monitoring template [{}] exists on the monitoring cluster", templateName);
|
||||||
name(), templateName);
|
|
||||||
connection = openConnection(host, "GET", url, null);
|
connection = openConnection(host, "GET", url, null);
|
||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
throw new IOException("no available connection to check for monitoring template [" + templateName + "] existence");
|
throw new IOException("no available connection to check for monitoring template [" + templateName + "] existence");
|
||||||
|
@ -464,8 +462,7 @@ public class HttpExporter extends Exporter {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("http exporter [{}] - failed to verify the monitoring template [{}] on [{}]:\n{}", name(), templateName, host,
|
logger.error("failed to verify the monitoring template [{}] on [{}]:\n{}", templateName, host, e.getMessage());
|
||||||
e.getMessage());
|
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
|
@ -480,12 +477,12 @@ public class HttpExporter extends Exporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean putTemplate(String host, String template, byte[] source) {
|
boolean putTemplate(String host, String template, byte[] source) {
|
||||||
logger.debug("http exporter [{}] - installing template [{}]", name(), template);
|
logger.debug("installing template [{}]", template);
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
try {
|
try {
|
||||||
connection = openConnection(host, "PUT", "_template/" + template, XContentType.JSON.mediaType());
|
connection = openConnection(host, "PUT", "_template/" + template, XContentType.JSON.mediaType());
|
||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
logger.debug("http exporter [{}] - no available connection to update monitoring template [{}]", name(), template);
|
logger.debug("no available connection to update monitoring template [{}]", template);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,11 +493,10 @@ public class HttpExporter extends Exporter {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("http exporter [{}] - monitoring template [{}] updated to version [{}]", name(), template, templateVersion);
|
logger.info("monitoring template [{}] updated to version [{}]", template, templateVersion);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("http exporter [{}] - failed to update monitoring template [{}] on host [{}]:\n{}", name(), template, host,
|
logger.error("failed to update monitoring template [{}] on host [{}]:\n{}", template, host, e.getMessage());
|
||||||
e.getMessage());
|
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
@Override
|
@Override
|
||||||
public void doClose() {
|
public void doClose() {
|
||||||
if (state.getAndSet(State.TERMINATED) != State.TERMINATED) {
|
if (state.getAndSet(State.TERMINATED) != State.TERMINATED) {
|
||||||
logger.debug("local exporter [{}] - stopped", name());
|
logger.debug("stopped");
|
||||||
clusterService.remove(this);
|
clusterService.remove(this);
|
||||||
cleanerService.remove(this);
|
cleanerService.remove(this);
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
if (clusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
|
if (clusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
|
||||||
// wait until the gateway has recovered from disk, otherwise we think may not have .monitoring-es-
|
// wait until the gateway has recovered from disk, otherwise we think may not have .monitoring-es-
|
||||||
// indices but they may not have been restored from the cluster state on disk
|
// indices but they may not have been restored from the cluster state on disk
|
||||||
logger.debug("local exporter [{}] - waiting until gateway has recovered from disk", name());
|
logger.debug("waiting until gateway has recovered from disk");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,11 +127,11 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
// We only need to check the index template for timestamped indices
|
// We only need to check the index template for timestamped indices
|
||||||
if (templateInstalled == false) {
|
if (templateInstalled == false) {
|
||||||
// the template for timestamped indices is not yet installed in the given cluster state, we'll wait.
|
// the template for timestamped indices is not yet installed in the given cluster state, we'll wait.
|
||||||
logger.debug("local exporter [{}] - monitoring index template does not exist, so service cannot start", name());
|
logger.debug("monitoring index template does not exist, so service cannot start");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("local exporter [{}] - monitoring index template found, service can start", name());
|
logger.debug("monitoring index template found, service can start");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -139,14 +139,13 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
//
|
//
|
||||||
// Check that there is nothing that could block metadata updates
|
// Check that there is nothing that could block metadata updates
|
||||||
if (clusterState.blocks().hasGlobalBlock(ClusterBlockLevel.METADATA_WRITE)) {
|
if (clusterState.blocks().hasGlobalBlock(ClusterBlockLevel.METADATA_WRITE)) {
|
||||||
logger.debug("local exporter [{}] - waiting until metadata writes are unblocked", name());
|
logger.debug("waiting until metadata writes are unblocked");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install the index template for timestamped indices first, so that other nodes can ship data
|
// Install the index template for timestamped indices first, so that other nodes can ship data
|
||||||
if (templateInstalled == false) {
|
if (templateInstalled == false) {
|
||||||
logger.debug("local exporter [{}] - could not find existing monitoring template for timestamped indices, " +
|
logger.debug("could not find existing monitoring template for timestamped indices, installing a new one");
|
||||||
"installing a new one", name());
|
|
||||||
putTemplate(templateName, MarvelTemplateUtils.loadTimestampedIndexTemplate());
|
putTemplate(templateName, MarvelTemplateUtils.loadTimestampedIndexTemplate());
|
||||||
// we'll get that template on the next cluster state update
|
// we'll get that template on the next cluster state update
|
||||||
return null;
|
return null;
|
||||||
|
@ -155,18 +154,17 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
// Install the index template for data index
|
// Install the index template for data index
|
||||||
templateName = MarvelTemplateUtils.dataTemplateName(templateVersion);
|
templateName = MarvelTemplateUtils.dataTemplateName(templateVersion);
|
||||||
if (hasTemplate(templateName, clusterState) == false) {
|
if (hasTemplate(templateName, clusterState) == false) {
|
||||||
logger.debug("local exporter [{}] - could not find existing monitoring template for data index, " +
|
logger.debug("could not find existing monitoring template for data index, installing a new one");
|
||||||
"installing a new one", name());
|
|
||||||
putTemplate(templateName, MarvelTemplateUtils.loadDataIndexTemplate());
|
putTemplate(templateName, MarvelTemplateUtils.loadDataIndexTemplate());
|
||||||
// we'll get that template on the next cluster state update
|
// we'll get that template on the next cluster state update
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("local exporter [{}] - monitoring index template found on master node, service can start", name());
|
logger.debug("monitoring index template found on master node, service can start");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.compareAndSet(State.INITIALIZED, State.RUNNING)) {
|
if (state.compareAndSet(State.INITIALIZED, State.RUNNING)) {
|
||||||
logger.debug("local exporter [{}] - started!", name());
|
logger.debug("started");
|
||||||
}
|
}
|
||||||
return new LocalBulk(name(), logger, client, resolvers);
|
return new LocalBulk(name(), logger, client, resolvers);
|
||||||
}
|
}
|
||||||
|
@ -185,7 +183,7 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
try {
|
try {
|
||||||
Integer version = Integer.parseInt(template.value.substring(templatePattern.length() - 1));
|
Integer version = Integer.parseInt(template.value.substring(templatePattern.length() - 1));
|
||||||
templates.put(template.value, version);
|
templates.put(template.value, version);
|
||||||
logger.debug("found index template [{}] in version [{}]", template, version);
|
logger.debug("found index template [{}] in version [{}]", template.value, version);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
logger.warn("cannot extract version number for template [{}]", template.value);
|
logger.warn("cannot extract version number for template [{}]", template.value);
|
||||||
}
|
}
|
||||||
|
@ -200,7 +198,7 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
}
|
}
|
||||||
|
|
||||||
void putTemplate(String template, byte[] source) {
|
void putTemplate(String template, byte[] source) {
|
||||||
logger.debug("local exporter [{}] - installing template [{}]", name(), template);
|
logger.debug("installing template [{}]",template);
|
||||||
|
|
||||||
PutIndexTemplateRequest request = new PutIndexTemplateRequest(template).source(source);
|
PutIndexTemplateRequest request = new PutIndexTemplateRequest(template).source(source);
|
||||||
assert !Thread.currentThread().isInterrupted() : "current thread has been interrupted before putting index template!!!";
|
assert !Thread.currentThread().isInterrupted() : "current thread has been interrupted before putting index template!!!";
|
||||||
|
@ -210,15 +208,15 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(PutIndexTemplateResponse response) {
|
public void onResponse(PutIndexTemplateResponse response) {
|
||||||
if (response.isAcknowledged()) {
|
if (response.isAcknowledged()) {
|
||||||
logger.trace("local exporter [{}] - successfully installed monitoring template [{}]", name(), template);
|
logger.trace("successfully installed monitoring template [{}]", template);
|
||||||
} else {
|
} else {
|
||||||
logger.error("local exporter [{}] - failed to update monitoring index template [{}]", name(), template);
|
logger.error("failed to update monitoring index template [{}]", template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable throwable) {
|
public void onFailure(Throwable throwable) {
|
||||||
logger.error("local exporter [{}] - failed to update monitoring index template [{}]", throwable, name(), template);
|
logger.error("failed to update monitoring index template [{}]", throwable, template);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -226,7 +224,7 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
@Override
|
@Override
|
||||||
public void onCleanUpIndices(TimeValue retention) {
|
public void onCleanUpIndices(TimeValue retention) {
|
||||||
if (state.get() != State.RUNNING) {
|
if (state.get() != State.RUNNING) {
|
||||||
logger.debug("local exporter [{}] - not ready yet", name());
|
logger.debug("exporter not ready");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +232,7 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
// Reference date time will be compared to index.creation_date settings,
|
// Reference date time will be compared to index.creation_date settings,
|
||||||
// that's why it must be in UTC
|
// that's why it must be in UTC
|
||||||
DateTime expiration = new DateTime(DateTimeZone.UTC).minus(retention.millis());
|
DateTime expiration = new DateTime(DateTimeZone.UTC).minus(retention.millis());
|
||||||
logger.debug("local exporter [{}] - cleaning indices [expiration={}, retention={}]", name(), expiration, retention);
|
logger.debug("cleaning indices [expiration={}, retention={}]", expiration, retention);
|
||||||
|
|
||||||
ClusterState clusterState = clusterService.state();
|
ClusterState clusterState = clusterService.state();
|
||||||
if (clusterState != null) {
|
if (clusterState != null) {
|
||||||
|
@ -268,7 +266,7 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
long creationDate = index.value.getCreationDate();
|
long creationDate = index.value.getCreationDate();
|
||||||
if (creationDate <= expirationTime) {
|
if (creationDate <= expirationTime) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("local exporter [{}] - detected expired index [name={}, created={}, expired={}]", name(),
|
logger.debug("detected expired index [name={}, created={}, expired={}]",
|
||||||
indexName, new DateTime(creationDate, DateTimeZone.UTC), expiration);
|
indexName, new DateTime(creationDate, DateTimeZone.UTC), expiration);
|
||||||
}
|
}
|
||||||
indices.add(indexName);
|
indices.add(indexName);
|
||||||
|
@ -277,31 +275,33 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!indices.isEmpty()) {
|
if (!indices.isEmpty()) {
|
||||||
logger.info("local exporter [{}] - cleaning up [{}] old indices", name(), indices.size());
|
logger.info("cleaning up [{}] old indices", indices.size());
|
||||||
deleteIndices(indices);
|
deleteIndices(indices);
|
||||||
} else {
|
} else {
|
||||||
logger.debug("local exporter [{}] - no old indices found for clean up", name());
|
logger.debug("no old indices found for clean up");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteIndices(Set<String> indices) {
|
private void deleteIndices(Set<String> indices) {
|
||||||
logger.trace("local exporter [{}] - deleting {} indices: {}", name(), indices.size(), collectionToCommaDelimitedString(indices));
|
logger.trace("deleting {} indices: [{}]", indices.size(), collectionToCommaDelimitedString(indices));
|
||||||
client.admin().indices().delete(new DeleteIndexRequest(indices.toArray(new String[indices.size()])),
|
client.admin().indices().delete(new DeleteIndexRequest(indices.toArray(new String[indices.size()])),
|
||||||
new ActionListener<DeleteIndexResponse>() {
|
new ActionListener<DeleteIndexResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(DeleteIndexResponse response) {
|
public void onResponse(DeleteIndexResponse response) {
|
||||||
if (response.isAcknowledged()) {
|
if (response.isAcknowledged()) {
|
||||||
logger.debug("local exporter [{}] - indices deleted", name());
|
logger.debug("{} indices deleted", indices.size());
|
||||||
} else {
|
} else {
|
||||||
logger.warn("local exporter [{}] - unable to delete {} indices", name(), indices.size());
|
// Probably means that the delete request has timed out,
|
||||||
|
// the indices will survive until the next clean up.
|
||||||
|
logger.warn("deletion of {} indices wasn't acknowledged", indices.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable e) {
|
public void onFailure(Throwable e) {
|
||||||
logger.error("local exporter [{}] - failed to delete indices", e, name());
|
logger.error("failed to delete indices", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue