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 InetSocketAddress socket; 018 int colonIndex = args[0].lastIndexOf(':'); 019 020 if (colonIndex < 0) { 021 int port = Integer.parseInt(args[0]); 022 socket = new InetSocketAddress(port); 023 } else { 024 int port = Integer.parseInt(args[0].substring(colonIndex + 1)); 025 String host = args[0].substring(0, colonIndex); 026 socket = new InetSocketAddress(host, port); 027 } 028 029 new BuildInfoCollector().register(); 030 new JmxCollector(new File(args[1])).register(); 031 new HTTPServer(socket, CollectorRegistry.defaultRegistry); 032 } 033}