Search in sources :

Example 1 with Metrics

use of org.terasology.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.context.Context) Metrics(org.terasology.telemetry.Metrics) Metric(org.terasology.telemetry.metrics.Metric) ModulesMetric(org.terasology.telemetry.metrics.ModulesMetric)

Example 2 with Metrics

use of org.terasology.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.context.Context) Metrics(org.terasology.telemetry.Metrics) Metric(org.terasology.telemetry.metrics.Metric) SystemContextMetric(org.terasology.telemetry.metrics.SystemContextMetric)

Example 3 with Metrics

use of org.terasology.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.telemetry.Metrics)

Aggregations

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