java.net.ConnectException: Connection refused when using micrometer's AtlasMeterRegistry












0















I'm new to micrometer and netflix/atlas.



I'm trying to create a very basic example of micrometer and registering a Counter to the AtlasMeterRegistry. But I'm getting java.net.ConnectException. After digging the code a bit, I found that the default URI for atlas backend is http://localhost:7101/api/v1/publish. I can even see in the logs something like



09:13:44.578 [main] INFO  c.n.spectator.atlas.AtlasRegistry - started collecting metrics every PT10S reporting to http://localhost:7101/api/v1/publish


which conforms that the default URI is used for the atlas backend.



I'm not sure what I'm missing. I think I'm missing something obvious.



I'm using JDK 11. The following is the stacktrace for the exception that I'm getting:



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)


my 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>


My Main class:



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 that I'm using:



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();
}

}


Can someone please point out the obvious thing(s) that I'm missing here? Any pointers to beginners guide will also help. Thanks.



Update: I tried it with JDK 1.8.0_191 but still getting the same exception.










share|improve this question





























    0















    I'm new to micrometer and netflix/atlas.



    I'm trying to create a very basic example of micrometer and registering a Counter to the AtlasMeterRegistry. But I'm getting java.net.ConnectException. After digging the code a bit, I found that the default URI for atlas backend is http://localhost:7101/api/v1/publish. I can even see in the logs something like



    09:13:44.578 [main] INFO  c.n.spectator.atlas.AtlasRegistry - started collecting metrics every PT10S reporting to http://localhost:7101/api/v1/publish


    which conforms that the default URI is used for the atlas backend.



    I'm not sure what I'm missing. I think I'm missing something obvious.



    I'm using JDK 11. The following is the stacktrace for the exception that I'm getting:



    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)


    my 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>


    My Main class:



    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 that I'm using:



    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();
    }

    }


    Can someone please point out the obvious thing(s) that I'm missing here? Any pointers to beginners guide will also help. Thanks.



    Update: I tried it with JDK 1.8.0_191 but still getting the same exception.










    share|improve this question



























      0












      0








      0








      I'm new to micrometer and netflix/atlas.



      I'm trying to create a very basic example of micrometer and registering a Counter to the AtlasMeterRegistry. But I'm getting java.net.ConnectException. After digging the code a bit, I found that the default URI for atlas backend is http://localhost:7101/api/v1/publish. I can even see in the logs something like



      09:13:44.578 [main] INFO  c.n.spectator.atlas.AtlasRegistry - started collecting metrics every PT10S reporting to http://localhost:7101/api/v1/publish


      which conforms that the default URI is used for the atlas backend.



      I'm not sure what I'm missing. I think I'm missing something obvious.



      I'm using JDK 11. The following is the stacktrace for the exception that I'm getting:



      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)


      my 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>


      My Main class:



      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 that I'm using:



      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();
      }

      }


      Can someone please point out the obvious thing(s) that I'm missing here? Any pointers to beginners guide will also help. Thanks.



      Update: I tried it with JDK 1.8.0_191 but still getting the same exception.










      share|improve this question
















      I'm new to micrometer and netflix/atlas.



      I'm trying to create a very basic example of micrometer and registering a Counter to the AtlasMeterRegistry. But I'm getting java.net.ConnectException. After digging the code a bit, I found that the default URI for atlas backend is http://localhost:7101/api/v1/publish. I can even see in the logs something like



      09:13:44.578 [main] INFO  c.n.spectator.atlas.AtlasRegistry - started collecting metrics every PT10S reporting to http://localhost:7101/api/v1/publish


      which conforms that the default URI is used for the atlas backend.



      I'm not sure what I'm missing. I think I'm missing something obvious.



      I'm using JDK 11. The following is the stacktrace for the exception that I'm getting:



      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)


      my 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>


      My Main class:



      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 that I'm using:



      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();
      }

      }


      Can someone please point out the obvious thing(s) that I'm missing here? Any pointers to beginners guide will also help. Thanks.



      Update: I tried it with JDK 1.8.0_191 but still getting the same exception.







      java netflix micrometer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 6:23







      Lavish Kothari

















      asked Jan 1 at 4:09









      Lavish KothariLavish Kothari

      791615




      791615
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992952%2fjava-net-connectexception-connection-refused-when-using-micrometers-atlasmeter%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992952%2fjava-net-connectexception-connection-refused-when-using-micrometers-atlasmeter%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]