use of org.terasology.engine.config.TelemetryConfig in project Terasology by MovingBlocks.
the class TelemetryScreen method pushAddServerPopupAndStartLogBackAppender.
private void pushAddServerPopupAndStartLogBackAppender() {
AddServerPopup addServerPopup = nuiManager.pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
addServerPopup.removeTip();
ServerInfo serverInfo;
TelemetryConfig telemetryConfig = config.getTelemetryConfig();
if (telemetryConfig.getErrorReportingDestination() != null) {
try {
URL url = new URL("http://" + telemetryConfig.getErrorReportingDestination());
serverInfo = new ServerInfo(telemetryConfig.getErrorReportingServerName(), url.getHost(), url.getPort());
serverInfo.setOwner(telemetryConfig.getErrorReportingServerOwner());
} catch (Exception e) {
logger.error("Exception when get telemetry server information", e);
serverInfo = new ServerInfo(TelemetryLogstashAppender.DEFAULT_LOGSTASH_NAME, TelemetryLogstashAppender.DEFAULT_LOGSTASH_HOST, TelemetryLogstashAppender.DEFAULT_LOGSTASH_PORT);
serverInfo.setOwner(TelemetryLogstashAppender.DEFAULT_LOGSTASH_OWNER);
}
} else {
serverInfo = new ServerInfo(TelemetryLogstashAppender.DEFAULT_LOGSTASH_NAME, TelemetryLogstashAppender.DEFAULT_LOGSTASH_HOST, TelemetryLogstashAppender.DEFAULT_LOGSTASH_PORT);
serverInfo.setOwner(TelemetryLogstashAppender.DEFAULT_LOGSTASH_OWNER);
}
addServerPopup.setServerInfo(serverInfo);
addServerPopup.onSuccess((item) -> {
String destinationLogstash = item.getAddress() + ":" + item.getPort();
TelemetryLogstashAppender telemetryLogstashAppender = TelemetryUtils.fetchTelemetryLogstashAppender();
if (telemetryLogstashAppender != null) {
telemetryLogstashAppender.addDestination(destinationLogstash);
telemetryLogstashAppender.start();
}
// Save the destination
telemetryConfig.setErrorReportingDestination(destinationLogstash);
telemetryConfig.setErrorReportingServerName(item.getName());
telemetryConfig.setErrorReportingServerOwner(item.getOwner());
});
addServerPopup.onCancel((button) -> telemetryConfig.setErrorReportingEnabled(false));
}
use of org.terasology.engine.config.TelemetryConfig in project Terasology by MovingBlocks.
the class TelemetrySubSystem method setTelemetryDestination.
private void setTelemetryDestination(Context rootContext) {
Config config = rootContext.get(Config.class);
TelemetryConfig telemetryConfig = config.getTelemetryConfig();
String telemetryDestination = telemetryConfig.getTelemetryDestination();
if (telemetryDestination != null) {
try {
URL url = new URL(telemetryDestination);
TelemetryEmitter telemetryEmitter = (TelemetryEmitter) emitter;
telemetryEmitter.changeUrl(url);
} catch (MalformedURLException e) {
logger.error("URL malformed", e);
}
} else {
telemetryConfig.setTelemetryDestination(TelemetryEmitter.getDefaultCollectorURL(DEFAULT_COLLECTOR_PROTOCOL, DEFAULT_COLLECTOR_HOST, DEFAULT_COLLECTOR_PORT).toString());
}
}
use of org.terasology.engine.config.TelemetryConfig in project Terasology by MovingBlocks.
the class StateMainMenu method pushLaunchPopup.
private void pushLaunchPopup() {
Config config = context.get(Config.class);
TelemetryConfig telemetryConfig = config.getTelemetryConfig();
TranslationSystem translationSystem = context.get(TranslationSystem.class);
TelemetryLogstashAppender appender = TelemetryUtils.fetchTelemetryLogstashAppender();
if (!telemetryConfig.isLaunchPopupDisabled()) {
String telemetryTitle = translationSystem.translate("${engine:menu#telemetry-launch-popup-title}");
String telemetryMessage = translationSystem.translate("${engine:menu#telemetry-launch-popup-text}");
LaunchPopup telemetryConfirmPopup = nuiManager.pushScreen(LaunchPopup.ASSET_URI, LaunchPopup.class);
telemetryConfirmPopup.setMessage(telemetryTitle, telemetryMessage);
telemetryConfirmPopup.setYesHandler(() -> {
telemetryConfig.setTelemetryAndErrorReportingEnable(true);
// Enable error reporting
appender.start();
});
telemetryConfirmPopup.setNoHandler(() -> {
telemetryConfig.setTelemetryAndErrorReportingEnable(false);
// Disable error reporting
appender.stop();
});
telemetryConfirmPopup.setOptionButtonText(translationSystem.translate("${engine:menu#telemetry-button}"));
telemetryConfirmPopup.setOptionHandler(() -> {
nuiManager.pushScreen(TelemetryScreen.ASSET_URI, TelemetryScreen.class);
});
}
}
use of org.terasology.engine.config.TelemetryConfig in project Terasology by MovingBlocks.
the class TelemetrySubSystem method addTelemetryLogstashAppender.
private void addTelemetryLogstashAppender(Context rootContext) {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
TelemetryLogstashAppender telemetryLogstashAppender = new TelemetryLogstashAppender(rootContext);
lc.getLogger(Logger.ROOT_LOGGER_NAME).addAppender(telemetryLogstashAppender);
Config config = rootContext.get(Config.class);
TelemetryConfig telemetryConfig = config.getTelemetryConfig();
String errorReportingDestination = telemetryConfig.getErrorReportingDestination();
if (errorReportingDestination == null) {
errorReportingDestination = TelemetryLogstashAppender.DEFAULT_LOGSTASH_HOST + ":" + TelemetryLogstashAppender.DEFAULT_LOGSTASH_PORT;
telemetryConfig.setErrorReportingDestination(errorReportingDestination);
}
if (telemetryConfig.isErrorReportingEnabled()) {
telemetryLogstashAppender.addDestination(errorReportingDestination);
telemetryLogstashAppender.start();
}
}
use of org.terasology.engine.config.TelemetryConfig in project Terasology by MovingBlocks.
the class TelemetrySubSystem method postInitialise.
@Override
public void postInitialise(Context rootContext) {
metrics.initialise(rootContext);
// Add the telemetryConfig adapter to context. It could be used in modules.
Config config = rootContext.get(Config.class);
TelemetryConfig telemetryConfig = config.getTelemetryConfig();
TelemetryConfiguration telemetryConfiguration = new TelemetryConfigurationImpl(telemetryConfig);
rootContext.put(TelemetryConfiguration.class, telemetryConfiguration);
addTelemetryLogstashAppender(rootContext);
setTelemetryDestination(rootContext);
}
Aggregations