Search in sources :

Example 1 with TelemetryConfiguration

use of org.terasology.config.facade.TelemetryConfiguration in project Terasology by MovingBlocks.

the class TelemetryUtils method fetchMetricAndSend.

/**
 * Fetch metric in {@link org.terasology.context.Context} and send to the server.
 * This method could be used in the modules.
 * @param context The game context
 * @param metricClass The class of the metric which we want to track
 * @param nameSpace The name the class tracking this metric.
 */
public static void fetchMetricAndSend(Context context, Class metricClass, String nameSpace) {
    Emitter emitter = context.get(Emitter.class);
    Metrics metrics = context.get(Metrics.class);
    TelemetryConfiguration telemetryConfiguration = context.get(TelemetryConfiguration.class);
    if (emitter != null && metrics != null && telemetryConfiguration != null) {
        Optional<Metric> metricOptional = metrics.getMetric(metricClass);
        if (metricOptional.isPresent()) {
            Metric metric = metricOptional.get();
            Optional<Unstructured> unstructuredOptional = metric.getUnstructuredMetric();
            if (unstructuredOptional.isPresent()) {
                Unstructured unstructured = unstructuredOptional.get();
                trackMetric(emitter, nameSpace, unstructured, metric, telemetryConfiguration);
            }
        }
    } else {
        logger.error("Emitter or metrics or telemetryConfiguration is not in context");
    }
}
Also used : Emitter(com.snowplowanalytics.snowplow.tracker.emitter.Emitter) TelemetryConfiguration(org.terasology.config.facade.TelemetryConfiguration) Unstructured(com.snowplowanalytics.snowplow.tracker.events.Unstructured) Metric(org.terasology.telemetry.metrics.Metric)

Example 2 with TelemetryConfiguration

use of org.terasology.config.facade.TelemetryConfiguration 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);
}
Also used : TelemetryConfiguration(org.terasology.config.facade.TelemetryConfiguration) Config(org.terasology.config.Config) TelemetryConfig(org.terasology.config.TelemetryConfig) TelemetryConfigurationImpl(org.terasology.config.facade.TelemetryConfigurationImpl) TelemetryConfig(org.terasology.config.TelemetryConfig)

Aggregations

TelemetryConfiguration (org.terasology.config.facade.TelemetryConfiguration)2 Emitter (com.snowplowanalytics.snowplow.tracker.emitter.Emitter)1 Unstructured (com.snowplowanalytics.snowplow.tracker.events.Unstructured)1 Config (org.terasology.config.Config)1 TelemetryConfig (org.terasology.config.TelemetryConfig)1 TelemetryConfigurationImpl (org.terasology.config.facade.TelemetryConfigurationImpl)1 Metric (org.terasology.telemetry.metrics.Metric)1