001package io.prometheus.jmx;
002
003import java.io.File;
004import java.net.InetSocketAddress;
005
006import io.prometheus.client.CollectorRegistry;
007import io.prometheus.client.exporter.HTTPServer;
008
009public class WebServer {
010
011   public static void main(String[] args) throws Exception {
012     if (args.length < 2) {
013       System.err.println("Usage: WebServer <[hostname:]port> <yaml configuration file>");
014       System.exit(1);
015     }
016
017     String[] hostnamePort = args[0].split(":");
018     int port;
019     InetSocketAddress socket;
020     
021     if (hostnamePort.length == 2) {
022       port = Integer.parseInt(hostnamePort[1]);
023       socket = new InetSocketAddress(hostnamePort[0], port);
024     } else {
025       port = Integer.parseInt(hostnamePort[0]);
026       socket = new InetSocketAddress(port);
027     }
028
029     new BuildInfoCollector().register();
030     new JmxCollector(new File(args[1])).register();
031     new HTTPServer(socket, CollectorRegistry.defaultRegistry);
032   }
033}