All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cloud.cf.monitoring.java.converter.MetricConverter Maven / Gradle / Ivy

package com.sap.cloud.cf.monitoring.java.converter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import com.sap.cloud.cf.monitoring.client.model.Metric;

public abstract class MetricConverter {
    private static final String KEY_TYPE = "type";

    public enum MetricType {
                            TIMER("timer"), HISTOGRAM("histogram"), GAUGE("gauge"), METER("meter"), COUNTER("counter");

        private final String metricTypeName;

        String getMetricTypeName() {
            return metricTypeName;
        }

        private MetricType(String metricTypeName) {
            this.metricTypeName = metricTypeName;
        }
    }

    public List convert(Map metrics, long timestamp) {
        return metrics.entrySet()
                .stream()
                .map(entry -> convertMetricEntry(entry, timestamp))
                .flatMap(List::stream)
                .collect(Collectors.toList());
    }

    protected abstract List convertMetricEntry(Entry metricEntry, long timestamp);

    protected Metric buildCustomMetric(String name, double value, MetricType type, long timestamp) {
        Map tags = new HashMap<>();
        tags.put(KEY_TYPE, type.getMetricTypeName());
        return new Metric(name, value, timestamp, tags);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy