Error Connecting: java.net.BindException: Can't assign requested address

18 views
Skip to first unread message

Samuel Stanley

unread,
Aug 20, 2020, 12:59:17 PM8/20/20
to Prometheus Users

Hi,

I am trying to send some custom metrics to Prometheus using the java client. Below is my code. However, when I run the sample I get the following error:

java.net.BindException: Can't assign requested address at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:433) at sun.nio.ch.Net.bind(Net.java:425) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) at sun.net.httpserver.ServerImpl.<init>(ServerImpl.java:100) at sun.net.httpserver.HttpServerImpl.<init>(HttpServerImpl.java:50) at sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:35) at com.sun.net.httpserver.HttpServer.create(HttpServer.java:130) at io.prometheus.client.exporter.HTTPServer.<init>(HTTPServer.java:176) at io.prometheus.client.exporter.HTTPServer.<init>(HTTPServer.java:211) at com.test.promtheus.App.main(App.java:38)

When i try the URL on the browser it loads the dashboard correctly.

public class App {
 public static void main( String[] args ) { 
 System.out.println( "Hello World!" );
 final Counter counter =
Counter.build().namespace("java").name("my_counter").help("This is my counter").register(); 
 Thread bgThread = new Thread(new Runnable() { 
 @Override 
 public void run() { 
 while (true) { 
 try { 
 counter.inc(); 
 Thread.sleep(1000); 
 } catch (InterruptedException e) 
{
 e.printStackTrace(); 
 }
 }
 } 
 }); 
 bgThread.start();
 try 
{
 HTTPServer server = new HTTPServer("test.xyz.com",30000);
 } catch (IOException e) 
{
 e.printStackTrace();
 } 
 } 
}

Am i missing something?

Reply all
Reply to author
Forward
0 new messages