Search in sources :

Example 6 with Metric

use of org.terasology.engine.telemetry.metrics.Metric in project Terasology by MovingBlocks.

the class SystemContextJsonProvider method writeTo.

public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException {
    TelemetryLogstashAppender appender = TelemetryUtils.fetchTelemetryLogstashAppender();
    Context context = appender.getGameContext();
    if (context != null) {
        Metrics metrics = context.get(Metrics.class);
        Optional<Metric> optional = metrics.getMetric(SystemContextMetric.class);
        if (optional.isPresent()) {
            Metric systemContextMetric = optional.get();
            Map<String, ?> map = systemContextMetric.createTelemetryFieldToValue();
            Map<String, String> stringMap = TelemetryUtils.toStringMap(map);
            JsonWritingUtils.writeMapStringFields(generator, getFieldName(), stringMap);
        }
    }
}
Also used : Context(org.terasology.engine.context.Context) Metrics(org.terasology.engine.telemetry.Metrics) SystemContextMetric(org.terasology.engine.telemetry.metrics.SystemContextMetric) Metric(org.terasology.engine.telemetry.metrics.Metric)

Example 7 with Metric

use of org.terasology.engine.telemetry.metrics.Metric in project Terasology by MovingBlocks.

the class TelemetryUtils method fetchMetricAndSend.

/**
 * fetch metric in {@link org.terasology.engine.telemetry.Metrics} and send to the server.
 * @param metrics Metrics class in the game context.
 * @param metricClass The class of metric.
 * @param emitter Emitter sending telemetry to the server.
 * @param nameSpace The name the class tracking this metric.
 * @param bindingMap the binding map contains fields who has user's permission.
 */
public static void fetchMetricAndSend(Metrics metrics, Class metricClass, Emitter emitter, String nameSpace, Map<String, Boolean> bindingMap) {
    Optional<Metric> optional = metrics.getMetric(metricClass);
    if (optional.isPresent()) {
        Metric metric = optional.get();
        Optional<Unstructured> unstructuredOptional = metric.getUnstructuredMetric();
        if (unstructuredOptional.isPresent()) {
            Unstructured unstructured = unstructuredOptional.get();
            trackMetric(emitter, nameSpace, unstructured, metric, bindingMap);
        }
    }
}
Also used : Unstructured(com.snowplowanalytics.snowplow.tracker.events.Unstructured) Metric(org.terasology.engine.telemetry.metrics.Metric)

Aggregations

Metric (org.terasology.engine.telemetry.metrics.Metric)7 Unstructured (com.snowplowanalytics.snowplow.tracker.events.Unstructured)2 Context (org.terasology.engine.context.Context)2 Metrics (org.terasology.engine.telemetry.Metrics)2 ModulesMetric (org.terasology.engine.telemetry.metrics.ModulesMetric)2 SystemContextMetric (org.terasology.engine.telemetry.metrics.SystemContextMetric)2 Emitter (com.snowplowanalytics.snowplow.tracker.emitter.Emitter)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 TelemetryConfiguration (org.terasology.engine.config.facade.TelemetryConfiguration)1 BlockDestroyedMetric (org.terasology.engine.telemetry.metrics.BlockDestroyedMetric)1 BlockPlacedMetric (org.terasology.engine.telemetry.metrics.BlockPlacedMetric)1 CreatureKilledMetric (org.terasology.engine.telemetry.metrics.CreatureKilledMetric)1 GameConfigurationMetric (org.terasology.engine.telemetry.metrics.GameConfigurationMetric)1 GamePlayMetric (org.terasology.engine.telemetry.metrics.GamePlayMetric)1 ColumnLayout (org.terasology.nui.layouts.ColumnLayout)1 ScrollableArea (org.terasology.nui.layouts.ScrollableArea)1