Search in sources :

Example 1 with Metrics

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

the class ModulesJsonProvider method writeTo.

@Override
public void writeTo(JsonGenerator generator, ILoggingEvent iLoggingEvent) throws IOException {
    TelemetryLogstashAppender appender = TelemetryUtils.fetchTelemetryLogstashAppender();
    Context context = appender.getGameContext();
    if (context != null) {
        Metrics metrics = context.get(Metrics.class);
        Optional<Metric> optional = metrics.getMetric(ModulesMetric.class);
        if (optional.isPresent()) {
            Metric modulesMetric = optional.get();
            Map<String, ?> map = modulesMetric.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) ModulesMetric(org.terasology.engine.telemetry.metrics.ModulesMetric) Metric(org.terasology.engine.telemetry.metrics.Metric)

Example 2 with Metrics

use of org.terasology.engine.telemetry.Metrics 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 3 with Metrics

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

the class TelemetrySubSystem method preInitialise.

@Override
public void preInitialise(Context rootContext) {
    // Add metrics to context, this helps show metric values in ui
    metrics = new Metrics();
    rootContext.put(Metrics.class, metrics);
    // Add snowplow emitter to context, contributors can use this emitter to emit other event
    emitter = TelemetryEmitter.builder().build();
    rootContext.put(Emitter.class, emitter);
}
Also used : Metrics(org.terasology.engine.telemetry.Metrics)

Aggregations

Metrics (org.terasology.engine.telemetry.Metrics)3 Context (org.terasology.engine.context.Context)2 Metric (org.terasology.engine.telemetry.metrics.Metric)2 ModulesMetric (org.terasology.engine.telemetry.metrics.ModulesMetric)1 SystemContextMetric (org.terasology.engine.telemetry.metrics.SystemContextMetric)1