diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..1c983a1
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b83d222
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/.project b/.project
new file mode 100644
index 0000000..80b2fb2
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ olp_exporter
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..365bbd6
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
+encoding//src/test/java=UTF-8
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..087f3ac
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..14b697b
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..5202d7b
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,94 @@
+
+
+ 4.0.0
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.3.3.RELEASE
+
+
+
+ com.nis
+ olp_exporter
+ 1.0
+ jar
+
+ olp_exporter
+ olp_exporter
+
+
+ 8
+ UTF-8
+ 1.8
+ 1.8
+ UTF-8
+ UTF-8
+
+
+
+
+ aliyun
+ Aliyun Central Repository
+ default
+ http://maven.aliyun.com/nexus/content/groups/public
+
+
+ unidal-nexus-repo
+ dianping
+ http://unidal.org/nexus/content/repositories/releases
+
+ true
+
+
+ false
+
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+ io.micrometer
+ micrometer-registry-prometheus
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ com.google.guava
+ guava
+ 23.6-jre
+
+
+
+
+ ${project.artifactId}
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/nis/CounterService.java b/src/main/java/com/nis/CounterService.java
new file mode 100644
index 0000000..95342ae
--- /dev/null
+++ b/src/main/java/com/nis/CounterService.java
@@ -0,0 +1,25 @@
+package com.nis;
+
+import com.google.common.util.concurrent.AtomicDouble;
+import io.micrometer.prometheus.PrometheusMeterRegistry;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+/**
+ * created by bailong001 on 2019/07/16 14:49
+ */
+@Service
+public class CounterService {
+
+ @Resource
+ private PrometheusMeterRegistry appleMeterRegistry;
+
+ public Object incrCount(String type, String value) {
+ String name = "user.counter." + type;
+ if ("Olp".equals(type)) {
+ return appleMeterRegistry.gauge(name, new AtomicDouble(Double.parseDouble(value))).get();
+ }
+ return "null";
+ }
+}
diff --git a/src/main/java/com/nis/OlpExporterApplication.java b/src/main/java/com/nis/OlpExporterApplication.java
new file mode 100644
index 0000000..d094e02
--- /dev/null
+++ b/src/main/java/com/nis/OlpExporterApplication.java
@@ -0,0 +1,17 @@
+package com.nis;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.actuate.autoconfigure.metrics.JvmMetricsAutoConfiguration;
+import org.springframework.boot.actuate.autoconfigure.metrics.LogbackMetricsAutoConfiguration;
+import org.springframework.boot.actuate.autoconfigure.metrics.SystemMetricsAutoConfiguration;
+import org.springframework.boot.actuate.autoconfigure.metrics.web.tomcat.TomcatMetricsAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication(exclude = {JvmMetricsAutoConfiguration.class,SystemMetricsAutoConfiguration.class,TomcatMetricsAutoConfiguration.class,LogbackMetricsAutoConfiguration.class})
+public class OlpExporterApplication {
+
+ public static void main(String[] args) throws Exception {
+ SpringApplication.run(OlpExporterApplication.class, args);
+ }
+
+}
diff --git a/src/main/java/com/nis/config/MetricConfig.java b/src/main/java/com/nis/config/MetricConfig.java
new file mode 100644
index 0000000..c65f323
--- /dev/null
+++ b/src/main/java/com/nis/config/MetricConfig.java
@@ -0,0 +1,22 @@
+//package com.nis.config;
+//
+//import io.prometheus.client.CollectorRegistry;
+//import io.prometheus.client.Gauge;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//
+//@Configuration
+//public class MetricConfig {
+//// @Autowired
+// public CollectorRegistry collectorRegistry = new CollectorRegistry();
+//
+// @Bean
+// Gauge processorNatGatewayMonitorSnat(){
+// return Gauge.build().name("processorNatGatewayMonitor_snat")
+// .labelNames("natgatewayid")
+// .help("processorNatGatewayMonitorSnat:record by gatewayid and nodeip")
+// .register(collectorRegistry);
+// }
+//
+//}
diff --git a/src/main/java/com/nis/controller/OlpDataCollectController.java b/src/main/java/com/nis/controller/OlpDataCollectController.java
new file mode 100644
index 0000000..5093aaf
--- /dev/null
+++ b/src/main/java/com/nis/controller/OlpDataCollectController.java
@@ -0,0 +1,116 @@
+package com.nis.controller;
+
+import io.prometheus.client.CollectorRegistry;
+import io.prometheus.client.Gauge;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.nis.util.UdpUtils;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@RestController
+public class OlpDataCollectController {
+
+ private static final Logger logger = LoggerFactory.getLogger(OlpDataCollectController.class);
+
+ @Autowired
+ private CollectorRegistry olpCollectorRegistry;
+
+ @GetMapping("/probe")
+ public void endpointOlp(HttpServletRequest request,HttpServletResponse response,@RequestParam(required = true) String target,@RequestParam(required = true) Integer[] slot,@RequestParam(required = false) Integer timeout) throws IOException {
+ if(timeout==null) {
+ timeout = 5000;//默认5秒
+ }
+ logger.info(target);
+ logger.info(Arrays.deepToString(slot));
+ logger.info(timeout+"");
+
+ olpCollectorRegistry.clear();
+
+ Gauge labeledDurationSecondsGauge = Gauge.build().name("probe_duration_seconds")
+ .labelNames("slot")
+ .help("Check device status response time")
+ .register(olpCollectorRegistry);
+
+ Gauge labeledBypassGauge = Gauge.build().name("probe_bypass")
+ .labelNames("slot")
+ .help("Return bypass status")
+ .register(olpCollectorRegistry);
+
+ Gauge labeledSuccessGauge = Gauge.build().name("probe_success")
+ .labelNames("slot")
+ .help("Displays whether or not the probe was a success")
+ .register(olpCollectorRegistry);
+
+ for(Integer oneSlot:slot) {
+ double start = System.currentTimeMillis();
+ String rlt = UdpUtils.send(target, oneSlot,timeout);
+ double end = System.currentTimeMillis();
+ double durationSeconds = (end-start)/1000;
+ String slotStr = oneSlot+"";
+ long bypass = rlt.endsWith("03")?0:(rlt.endsWith("0c")?1:-1);
+ long success = (rlt.endsWith("03")||rlt.endsWith("0c"))?1:0;
+
+ labeledDurationSecondsGauge.labels(slotStr).set(durationSeconds);
+ labeledBypassGauge.labels(slotStr).set(bypass);
+ labeledSuccessGauge.labels(slotStr).set(success);
+
+ }
+
+ response.sendRedirect("/probePrometheus");
+
+ }
+
+
+// @GetMapping("/probe2")
+// public Object endpointOlp2(@RequestParam(required = true) String target,@RequestParam(required = true) Integer[] slot,@RequestParam(required = false) Integer timeout) {
+// if(timeout==null) {
+// timeout = 5000;//默认5秒
+// }
+// logger.info(target);
+// logger.info(Arrays.deepToString(slot));
+// logger.info(timeout+"");
+//
+// List mfs = new ArrayList();
+//
+// GaugeMetricFamily labeledDurationSecondsGauge = new GaugeMetricFamily("probe_duration_seconds", "Check device status response time", Arrays.asList("slot"));
+// mfs.add(labeledDurationSecondsGauge);
+//
+// GaugeMetricFamily labeledBypassGauge = new GaugeMetricFamily("probe_bypass", "Return bypass status", Arrays.asList("slot"));
+// mfs.add(labeledBypassGauge);
+//
+// GaugeMetricFamily labeledSuccessGauge = new GaugeMetricFamily("probe_success", "Displays whether or not the probe was a success", Arrays.asList("slot"));
+// mfs.add(labeledSuccessGauge);
+//
+// for(Integer oneSlot:slot) {
+// double start = System.currentTimeMillis();
+// String rlt = UdpUtils.send(target, oneSlot,timeout);
+// double end = System.currentTimeMillis();
+// double durationSeconds = (end-start)/1000;
+// String slotStr = oneSlot+"";
+// long bypass = rlt.endsWith("03")?0:(rlt.endsWith("0c")?1:-1);
+// long success = (rlt.endsWith("03")||rlt.endsWith("0c"))?1:0;
+//
+// labeledDurationSecondsGauge.addMetric(Arrays.asList(slotStr), durationSeconds);
+// labeledBypassGauge.addMetric(Arrays.asList(slotStr), bypass);
+// labeledSuccessGauge.addMetric(Arrays.asList(slotStr),success);
+// }
+//
+// Writer writer = new StringWriter();
+// TextFormatUtils.write004(writer, mfs);
+//
+//// return ""+writer.toString()+"
";
+// return writer.toString();
+// }
+
+}
diff --git a/src/main/java/com/nis/endpoint/OlpEndPoint.java b/src/main/java/com/nis/endpoint/OlpEndPoint.java
new file mode 100644
index 0000000..aa5b0cb
--- /dev/null
+++ b/src/main/java/com/nis/endpoint/OlpEndPoint.java
@@ -0,0 +1,45 @@
+package com.nis.endpoint;
+
+import io.prometheus.client.CollectorRegistry;
+import io.prometheus.client.Gauge;
+import io.prometheus.client.exporter.common.TextFormat;
+import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
+import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpoint;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+/**
+ * created by bailong001 on 2019/08/12 16:47
+ */
+@WebEndpoint(id = "probePrometheus")
+public class OlpEndPoint {
+
+ private final CollectorRegistry collectorRegistry;
+
+ public OlpEndPoint(CollectorRegistry collectorRegistry) {
+ this.collectorRegistry = collectorRegistry;
+// Gauge g = Gauge.build().name("gauge").help("blah").register();
+// g.set(1);
+// Gauge processorNatGatewayMonitorSnat =
+// processorNatGatewayMonitorSnat.labels("id-123145","192.168.1.1").set(123);
+// this.collectorRegistry.clear();
+ }
+
+ @ReadOperation(produces = TextFormat.CONTENT_TYPE_004)
+ public String scrape() {
+ try {
+ Writer writer = new StringWriter();
+ TextFormat.write004(writer, this.collectorRegistry.metricFamilySamples());
+ return writer.toString();
+ } catch (IOException ex) {
+ // This actually never happens since StringWriter::write() doesn't throw any
+ // IOException
+ throw new RuntimeException("Writing metrics failed", ex);
+ }
+ }
+}
diff --git a/src/main/java/com/nis/endpoint/OlpPrometheusAutoConfiguration.java b/src/main/java/com/nis/endpoint/OlpPrometheusAutoConfiguration.java
new file mode 100644
index 0000000..0e07276
--- /dev/null
+++ b/src/main/java/com/nis/endpoint/OlpPrometheusAutoConfiguration.java
@@ -0,0 +1,94 @@
+package com.nis.endpoint;
+
+import io.micrometer.core.instrument.Clock;
+import io.micrometer.prometheus.PrometheusConfig;
+import io.micrometer.prometheus.PrometheusMeterRegistry;
+import io.prometheus.client.CollectorRegistry;
+import io.prometheus.client.Gauge;
+
+//import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
+import org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration;
+import org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusProperties;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.annotation.Resource;
+
+/**
+ * created by bailong001 on 2019/08/12 16:30
+ */
+@Configuration
+@AutoConfigureAfter(value = {PrometheusMetricsExportAutoConfiguration.class})
+@ConditionalOnClass(value = {PrometheusMeterRegistry.class})
+@ConditionalOnProperty(prefix = "management.metrics.export.olp", name = "enabled", havingValue = "true",
+ matchIfMissing = true)
+public class OlpPrometheusAutoConfiguration {
+
+ CollectorRegistry collectorRegistry = new CollectorRegistry();
+
+ @Bean(name = "olpPrometheusProperties")
+ @ConfigurationProperties(prefix = "management.metrics.export.olp")
+ public PrometheusProperties olpPrometheusProperties() {
+ return new PrometheusProperties();
+ }
+
+ @Bean(name = "olpPrometheusConfig")
+ public PrometheusConfig olpPrometheusConfig() {
+ return new OlpPropertiesConfigAdapter(olpPrometheusProperties());
+ }
+
+ @Bean(name = "olpMeterRegistry")
+ public PrometheusMeterRegistry olpMeterRegistry(Clock clock) {
+ return new PrometheusMeterRegistry(olpPrometheusConfig(), olpCollectorRegistry(), clock);
+ }
+
+// @Bean(name = "labeledDurationSecondsGauge")
+// public Gauge labeledDurationSecondsGauge() {
+// return Gauge.build().name("probe_duration_seconds")
+// .labelNames("slot")
+// .help("Check device status response time")
+// .register(collectorRegistry);
+// }
+// @Bean(name = "labeledBypassGauge")
+// public Gauge labeledBypassGauge() {
+// return Gauge.build().name("probe_bypass")
+// .labelNames("slot")
+// .help("Return bypass status")
+// .register(collectorRegistry);
+// }
+// @Bean(name = "labeledSuccessGauge")
+// public Gauge labeledSuccessGauge() {
+// return Gauge.build().name("probe_success")
+// .labelNames("slot")
+// .help("Displays whether or not the probe was a success")
+// .register(collectorRegistry);
+// }
+
+ @Bean(name = "olpCollectorRegistry")
+ public CollectorRegistry olpCollectorRegistry() {
+// CollectorRegistry collectorRegistry = new CollectorRegistry(true);
+// CollectorRegistry collectorRegistry = new CollectorRegistry();
+// collectorRegistry.clear();
+ return collectorRegistry;
+ }
+
+ @Configuration
+ public static class TicketScrapeEndpointConfiguration {
+
+ @Resource
+ private CollectorRegistry olpCollectorRegistry;
+
+ @Bean(name = "olpEndpoint")
+ @ConditionalOnMissingBean
+ public OlpEndPoint olpEndpoint() {
+ return new OlpEndPoint(olpCollectorRegistry);
+ }
+
+ }
+
+}
diff --git a/src/main/java/com/nis/endpoint/OlpPropertiesConfigAdapter.java b/src/main/java/com/nis/endpoint/OlpPropertiesConfigAdapter.java
new file mode 100644
index 0000000..515a154
--- /dev/null
+++ b/src/main/java/com/nis/endpoint/OlpPropertiesConfigAdapter.java
@@ -0,0 +1,34 @@
+package com.nis.endpoint;
+
+import io.micrometer.prometheus.PrometheusConfig;
+import org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusProperties;
+import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PropertiesConfigAdapter;
+
+import java.time.Duration;
+
+/**
+ * created by bailong001 on 2019/08/12 17:56
+ */
+public class OlpPropertiesConfigAdapter extends PropertiesConfigAdapter
+ implements PrometheusConfig {
+
+ OlpPropertiesConfigAdapter(PrometheusProperties properties) {
+ super(properties);
+ }
+
+ @Override
+ public String get(String key) {
+ return null;
+ }
+
+ @Override
+ public boolean descriptions() {
+ return get(PrometheusProperties::isDescriptions, PrometheusConfig.super::descriptions);
+ }
+
+ @Override
+ public Duration step() {
+ return get(PrometheusProperties::getStep, PrometheusConfig.super::step);
+ }
+
+}
diff --git a/src/main/java/com/nis/util/HexUtils.java b/src/main/java/com/nis/util/HexUtils.java
new file mode 100644
index 0000000..12d410b
--- /dev/null
+++ b/src/main/java/com/nis/util/HexUtils.java
@@ -0,0 +1,207 @@
+package com.nis.util;
+
+public class HexUtils {
+
+ /**
+ * 16进制表示的字符串转换为字节数组
+ *
+ * @param hexString 16进制表示的字符串
+ * @return byte[] 字节数组
+ */
+ public static byte[] hexStringToByteArray(String hexString) {
+ hexString = hexString.replaceAll(" ", "");
+ int len = hexString.length();
+ byte[] bytes = new byte[len / 2];
+ for (int i = 0; i < len; i += 2) {
+ // 两位一组,表示一个字节,把这样表示的16进制字符串,还原成一个字节
+ bytes[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character
+ .digit(hexString.charAt(i + 1), 16));
+ }
+ return bytes;
+ }
+
+ /**
+ * 字节转十六进制字符串
+ * @param b 需要进行转换的byte字节
+ * @return 转换后的Hex字符串
+ */
+ public static String byteToHex(byte b){
+ String hex = Integer.toHexString(b & 0xFF);
+ if(hex.length() < 2){
+ hex = "0" + hex;
+ }
+ return hex;
+ }
+
+ /**
+ * byte[]数组转换为16进制的字符串
+ *
+ * @param bytes 要转换的字节数组
+ * @return 转换后的结果
+ */
+ public static String bytesToHexString(byte[] bytes) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < bytes.length; i++) {
+ String hex = Integer.toHexString(0xFF & bytes[i]);
+ if (hex.length() == 1) {
+ sb.append('0');
+ }
+ sb.append(hex);
+ }
+ return sb.toString();
+ }
+
+ /**
+ * 合并字节数组:System.arraycopy()方法
+ * @param bt1
+ * @param bt2
+ * @return
+ */
+ public static byte[] byteMerger(byte[] bt1, byte[] bt2){
+ byte[] bt3 = new byte[bt1.length+bt2.length];
+ System.arraycopy(bt1, 0, bt3, 0, bt1.length);
+ System.arraycopy(bt2, 0, bt3, bt1.length, bt2.length);
+ return bt3;
+ }
+
+
+ /**
+ * 从一个byte[]数组中截取一部分
+ * @param src
+ * @param begin
+ * @param count
+ * @return
+ */
+ public static byte[] subBytes(byte[] src, int begin, int count) {
+ byte[] bs = new byte[count];
+ for (int i=begin;i mfs) {
+ try {
+ String enter = "\n";
+ for(MetricFamilySamples mfSample:mfs) {
+ Collector.MetricFamilySamples metricFamilySamples = mfSample;
+ writer.write("# HELP ");
+ writer.write(metricFamilySamples.name);
+ writer.write(' ');
+ writeEscapedHelp(writer, metricFamilySamples.help);
+ writer.write(enter);
+
+ writer.write("# TYPE ");
+ writer.write(metricFamilySamples.name);
+ writer.write(' ');
+ writer.write(typeString(metricFamilySamples.type));
+ writer.write(enter);
+
+ for (Collector.MetricFamilySamples.Sample sample: metricFamilySamples.samples) {
+ writer.write(sample.name);
+ if (sample.labelNames.size() > 0) {
+ writer.write('{');
+ for (int i = 0; i < sample.labelNames.size(); ++i) {
+ writer.write(sample.labelNames.get(i));
+ writer.write("=\"");
+ writeEscapedLabelValue(writer, sample.labelValues.get(i));
+ writer.write("\",");
+ }
+ writer.write('}');
+ }
+ writer.write(' ');
+ writer.write(Collector.doubleToGoString(sample.value));
+ if (sample.timestampMs != null){
+ writer.write(' ');
+ writer.write(sample.timestampMs.toString());
+ }
+ writer.write(enter);
+ }
+ }
+ }catch (Exception e) {
+ logger.error(e.getMessage());
+ }
+ }
+
+ private static void writeEscapedHelp(Writer writer, String s) throws IOException {
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ switch (c) {
+ case '\\':
+ writer.append("\\\\");
+ break;
+ case '\n':
+ writer.append("\\n");
+ break;
+ default:
+ writer.append(c);
+ }
+ }
+ }
+
+ private static String typeString(Collector.Type t) {
+ switch (t) {
+ case GAUGE:
+ return "gauge";
+ case COUNTER:
+ return "counter";
+ case SUMMARY:
+ return "summary";
+ case HISTOGRAM:
+ return "histogram";
+ default:
+ return "untyped";
+ }
+ }
+
+ private static void writeEscapedLabelValue(Writer writer, String s) throws IOException {
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ switch (c) {
+ case '\\':
+ writer.append("\\\\");
+ break;
+ case '\"':
+ writer.append("\\\"");
+ break;
+ case '\n':
+ writer.append("\\n");
+ break;
+ default:
+ writer.append(c);
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/com/nis/util/UdpUtils.java b/src/main/java/com/nis/util/UdpUtils.java
new file mode 100644
index 0000000..786a802
--- /dev/null
+++ b/src/main/java/com/nis/util/UdpUtils.java
@@ -0,0 +1,48 @@
+package com.nis.util;
+
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UdpUtils {
+
+ private static final Logger logger = LoggerFactory.getLogger(TextFormatUtils.class);
+
+ public static String send(String sendIp,Integer slot,int timeout) {
+ String rlt = "";
+ DatagramSocket ds = null;
+ try {
+ ds = new DatagramSocket();//通过DatagramSocket对象创建udp服务
+ ds.setSoTimeout(timeout);
+ // String line = "00 06 0502 00 00 68c2"; //发送的16进制字符串
+ String slotStr = slot+"";
+ if(slot<10) {
+ slotStr = "0"+slotStr;
+ }
+ String line = "00 "+slotStr+" 0502 00 00"; //发送的16进制字符串
+ byte[] buf = HexUtils.hexStringToByteArray(line);
+ DatagramPacket dp = new DatagramPacket(buf,buf.length,InetAddress.getByName(sendIp),6800);//发送至指定IP,指定端口
+ ds.send(dp);//通过send方法将数据包发送出去
+ //定义数据包,用于存储数据
+ byte[] buf2 = new byte[8];
+ DatagramPacket dp2 = new DatagramPacket(buf2,buf2.length);
+ ds.receive(dp2);//通过服务的receive方法将收到数据存入数据包中,receive()为阻塞式方法
+ //通过数据包的方法获取其中的数据
+ String ip = dp2.getAddress().getHostAddress();
+
+ System.out.println(ip+"::"+HexUtils.bytesToHexString(buf2));
+
+ rlt = HexUtils.bytesToHexString(buf2);
+ }catch (Exception e) {
+ logger.error(sendIp+"::"+slot+">>"+e.getMessage());
+ }finally {
+ if(ds!=null) {
+ ds.close();//关闭资源
+ }
+ }
+ return rlt;
+ }
+}
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
new file mode 100644
index 0000000..cf82061
--- /dev/null
+++ b/src/main/resources/application-dev.yml
@@ -0,0 +1,28 @@
+server:
+ port: 9100
+ servlet:
+ context-path: /
+spring:
+ application:
+ name: olp_exporter
+
+management:
+ metrics:
+ binders:
+ jvm:
+ enabled: false
+ files:
+ enabled: false
+ integration:
+ enabled: false
+ logback:
+ enabled: false
+ processor:
+ enabled: false
+ uptime:
+ enabled: false
+ endpoints:
+ web:
+ base-path: /
+ exposure:
+ include: ['probePrometheus']
diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml
new file mode 100644
index 0000000..cf82061
--- /dev/null
+++ b/src/main/resources/application-prod.yml
@@ -0,0 +1,28 @@
+server:
+ port: 9100
+ servlet:
+ context-path: /
+spring:
+ application:
+ name: olp_exporter
+
+management:
+ metrics:
+ binders:
+ jvm:
+ enabled: false
+ files:
+ enabled: false
+ integration:
+ enabled: false
+ logback:
+ enabled: false
+ processor:
+ enabled: false
+ uptime:
+ enabled: false
+ endpoints:
+ web:
+ base-path: /
+ exposure:
+ include: ['probePrometheus']
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
new file mode 100644
index 0000000..caf4dfc
--- /dev/null
+++ b/src/main/resources/application.yml
@@ -0,0 +1,3 @@
+spring:
+ profiles:
+ active: dev
\ No newline at end of file