-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
18 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
package lol.hub.headlessbot; | ||
|
||
import com.sun.net.httpserver.HttpServer; | ||
import io.prometheus.client.Counter; | ||
import io.prometheus.client.exporter.HTTPServer; | ||
import io.prometheus.client.hotspot.DefaultExports; | ||
import io.prometheus.metrics.core.metrics.Counter; | ||
import io.prometheus.metrics.exporter.httpserver.HTTPServer; | ||
import io.prometheus.metrics.instrumentation.jvm.JvmMetrics; | ||
|
||
import java.io.IOException; | ||
|
||
public class Metrics { | ||
|
||
public static final Counter deaths = Counter.build() | ||
public static final Counter deaths = Counter.builder() | ||
.name("deaths") | ||
.help("Total deaths.") | ||
.register(); | ||
|
||
static void init(final HttpServer server) throws IOException { | ||
// hotspot metrics | ||
DefaultExports.initialize(); | ||
|
||
// register exporter | ||
new HTTPServer.Builder().withHttpServer(server).build(); | ||
static void init() { | ||
JvmMetrics.builder().register(); | ||
try { | ||
HTTPServer server = HTTPServer.builder() | ||
.port(8080) | ||
.buildAndStart(); | ||
Runtime.getRuntime().addShutdownHook(new Thread(server::stop)); | ||
Log.info("Metrics available at: http://localhost:" + server.getPort() + "/metrics"); | ||
} catch (IOException ex) { | ||
// rethrow this wrapped as IllegalStateException | ||
// to make the game or some mod-loader handle it | ||
throw new IllegalStateException(ex.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters