我是micrometer和netflix/atlas的新手。
我正在尝试创建一个非常基本的千分尺示例,并将Counter
注册到AtlasMeterRegistry
。但是我得到java.net.ConnectException
。深入研究代码后,我发现atlas
后端的默认URI是http://localhost:7101/api/v1/publish
。我什至可以在日志中看到
09:13:44.578 [main] INFO c.n.spectator.atlas.AtlasRegistry - started collecting metrics every PT10S reporting to http://localhost:7101/api/v1/publish
表示默认的URI用于atlas
后端。
我不确定我缺少什么。我想我缺少明显的东西。
我正在使用JDK11。以下是我遇到的异常的堆栈跟踪:
09:13:49.215 [spectator-spectator-reg-atlas-0] WARN c.n.spectator.atlas.AtlasRegistry - failed to send metrics
java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.Socket.connect(Socket.java:591)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:177)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569)
at java.base/sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:341)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:362)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1242)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1181)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1075)
at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:1009)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1356)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1331)
at com.netflix.spectator.ipc.http.HttpRequestBuilder.sendImpl(HttpRequestBuilder.java:288)
at com.netflix.spectator.ipc.http.HttpRequestBuilder.send(HttpRequestBuilder.java:218)
at com.netflix.spectator.atlas.AtlasRegistry.collectData(AtlasRegistry.java:207)
at com.netflix.spectator.impl.Scheduler$DelayedTask.runAndReschedule(Scheduler.java:401)
at com.netflix.spectator.impl.Scheduler$Worker.lambda$run$0(Scheduler.java:475)
at com.netflix.spectator.api.SwapTimer.record(SwapTimer.java:52)
at com.netflix.spectator.impl.Scheduler$Worker.run(Scheduler.java:475)
at java.base/java.lang.Thread.run(Thread.java:834)
我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>micrometer_test</groupId>
<artifactId>micrometer_test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<slf4j.version>1.7.25</slf4j.version>
<logback.version>1.2.3</logback.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-core -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-jmx -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-jmx</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-atlas -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-atlas</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
我的Main
班:
import io.micrometer.atlas.AtlasMeterRegistry;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import io.micrometer.core.instrument.logging.LoggingMeterRegistry;
import io.micrometer.jmx.JmxMeterRegistry;
import java.util.Random;
public class Main {
public static void main(String[] args) throws InterruptedException {
CompositeMeterRegistry compositeMeterRegistry = new CompositeMeterRegistry();
LoggingMeterRegistry loggingMeterRegistry = SampleMeterRegistries.loggingMeterRegistry();
JmxMeterRegistry jmxMeterRegistry = SampleMeterRegistries.jmxMeterRegistry();
AtlasMeterRegistry atlasMeterRegistry = SampleMeterRegistries.atlasMeterRegistry();
compositeMeterRegistry.add(loggingMeterRegistry);
compositeMeterRegistry.add(jmxMeterRegistry);
compositeMeterRegistry.add(atlasMeterRegistry);
Counter counter = Counter
.builder("instance")
.description("some description")
.tags("dev", "performance")
.register(compositeMeterRegistry);
Random random = new Random();
while (true) {
Thread.sleep(random.nextInt(100));
counter.increment();
}
}
}
SampleMeterRegistries
我正在使用:
import com.netflix.spectator.atlas.AtlasConfig;
import io.micrometer.atlas.AtlasMeterRegistry;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.logging.LoggingMeterRegistry;
import io.micrometer.core.instrument.logging.LoggingRegistryConfig;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.micrometer.core.lang.Nullable;
import io.micrometer.jmx.JmxConfig;
import io.micrometer.jmx.JmxMeterRegistry;
import java.time.Duration;
public class SampleMeterRegistries {
private static final long DEFAULT_STEP_SIZE = 10; // in seconds
private SampleMeterRegistries() {
}
public static LoggingMeterRegistry loggingMeterRegistry() {
return new LoggingMeterRegistry(new LoggingRegistryConfig() {
@Override
public String get(String key) {
return null;
}
@Override
public Duration step() {
return Duration.ofSeconds(DEFAULT_STEP_SIZE);
}
}, Clock.SYSTEM);
}
public static JmxMeterRegistry jmxMeterRegistry() {
return new JmxMeterRegistry(new JmxConfig() {
@Override
public String get(String key) {
return null;
}
@Override
public Duration step() {
return Duration.ofSeconds(DEFAULT_STEP_SIZE);
}
}, Clock.SYSTEM);
}
public static AtlasMeterRegistry atlasMeterRegistry() {
return new AtlasMeterRegistry(new AtlasConfig() {
@Override
public Duration step() {
return Duration.ofSeconds(DEFAULT_STEP_SIZE);
}
@SuppressWarnings("ConstantConditions")
@Override
@Nullable
public String get(String k) {
return null;
}
}, Clock.SYSTEM);
}
public static SimpleMeterRegistry simpleMeterRegistry() {
return new SimpleMeterRegistry();
}
}
有人可以指出我在这里不见的明显事情吗?任何初学者指南的指针也将有所帮助。谢谢。
更新:我在JDK 1.8.0_191上进行了尝试,但仍然遇到相同的异常。