com.springframework.boxes.jmetric.starter.BoxesMetricPipeline Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-boxes-metric-starter Show documentation
Show all versions of spring-boxes-metric-starter Show documentation
spring-metric-boxes-boot-starter
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