protected void startHttpServer ( String path , int port ) { try { httpServer = HttpServer . create ( new InetSocketAddress ( port ) , 0 ) ; httpServer . createContext ( path , httpExchange -> { byte [ ] response = generateResponse ( ) ; httpExchange . sendResponseHeaders ( HTTP_STATUS_OK , response . length ) ; OutputStream os = httpExchange . getResponseBody ( ) ; os . write ( response ) ; os . close ( ) ; LOG . log ( Level . INFO , "Received metrics request." ) ; } ) ; LOG . info ( "Starting web sink server on port: " + port ) ; httpServer . start ( ) ; } catch ( IOException e ) { throw new RuntimeException ( "Failed to create Http server on port " + port , e ) ; } }
Start a http server on supplied port that will serve the metrics as json on the specified path .