Search in sources :

Example 1 with SystemContextMetric

use of org.terasology.engine.telemetry.metrics.SystemContextMetric 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)

Aggregations

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