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

com.springframework.boxes.jmetric.starter.pipeline.LoggerPipeline Maven / Gradle / Ivy

There is a newer version: 2.0.9
Show newest version
package com.springframework.boxes.jmetric.starter.pipeline;

import com.google.common.collect.Maps;
import com.springframework.boxes.jmetric.starter.BoxesMetricCollector;
import com.springframework.boxes.jmetric.starter.BoxesMetricPipeline;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetAddress;
import java.util.Map;
import java.util.Optional;

@Slf4j
public class LoggerPipeline implements BoxesMetricPipeline {

    /**
     * 日志标记监控名称:jmetric
     */
    public static final Logger LOG = LoggerFactory.getLogger("jmetric");


    @Override
    public void pipeline(BoxesMetricCollector collector, String key, Object value, long milliseconds) {
        if (null == collector || StringUtils.isBlank(key) || null == value) {
            return;
        }
        LOG.info("host_name:{}, metric_key:{}, metric_val:{}, time:{}", InetAddress.getLoopbackAddress().getHostAddress(), key, String.valueOf(value), milliseconds);
    }

    @Override
    public void pipeline(BoxesMetricCollector collector, Map metrics, long milliseconds) {
        if (null == collector) {
            return;
        }
        Optional.ofNullable(metrics).orElse(Maps.newHashMap()).forEach((k, v) -> {
            this.pipeline(collector, k, v, milliseconds);
        });
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy