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

com.springframework.boxes.jmetric.starter.BoxesMetricPipeline Maven / Gradle / Ivy

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


import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.Map;

public interface BoxesMetricPipeline {

    /**
     * 管道推送行为
     *
     * @param collector    采集管道
     * @param key          监控项-类目
     * @param value        监控项-数值
     * @param milliseconds 上报时间
     */
    public void pipeline(BoxesMetricCollector collector, String key, Object value, long milliseconds);

    /**
     * 管道推送行为
     *
     * @param collector    采集管道
     * @param metrics      监控项(类目,数值)
     * @param milliseconds 上报时间
     */
    public void pipeline(BoxesMetricCollector collector, Map metrics, long milliseconds);


    public default String getHostIP() {
        try {
            Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces();
            InetAddress localAddress = null;

            while (networkInterfaces.hasMoreElements()) {
                NetworkInterface networkInterface = (NetworkInterface) networkInterfaces.nextElement();
                Enumeration inetAddresses = networkInterface.getInetAddresses();

                while (inetAddresses.hasMoreElements()) {
                    InetAddress address = (InetAddress) inetAddresses.nextElement();
                    if (!address.isLoopbackAddress() && !Inet6Address.class.isInstance(address)) {
                        return address.getHostAddress();
                    }

                    if (!address.isLoopbackAddress()) {
                        localAddress = address;
                    }
                }
            }
            return localAddress.getHostAddress();
        } catch (Exception e) {
            e.getLocalizedMessage();
        }
        return "";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy