当前位置: 首页>>代码示例>>Java>>正文


Java HTTPServer类代码示例

本文整理汇总了Java中io.prometheus.client.exporter.HTTPServer的典型用法代码示例。如果您正苦于以下问题:Java HTTPServer类的具体用法?Java HTTPServer怎么用?Java HTTPServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HTTPServer类属于io.prometheus.client.exporter包,在下文中一共展示了HTTPServer类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepare

import io.prometheus.client.exporter.HTTPServer; //导入依赖的package包/类
public static void prepare() {
    try {
        // Create server
        server = HttpServer.create(new InetSocketAddress(Config.getCatalog().webinterface.port), 0);

        // Create server for metrics
        HTTPServer metricsServer = new HTTPServer("0.0.0.0", Config.getCatalog().webinterface.metricsPort);

        metrics = new CustomMetrics();
        DefaultExports.initialize();

        // Register all handlers
        ApiRegistry.register(server);
        AuthRegistry.register(server);
        ConfirmRegistry.register(server);

        // Handle all other request static
        server.createContext("/", new NotFoundController());
    } catch (IOException e) {
        TwasiLogger.log.error(e);
        e.printStackTrace();
    }
}
 
开发者ID:Twasi,项目名称:twasi-core,代码行数:24,代码来源:WebInterfaceApp.java

示例2: startDefaultEndpoint

import io.prometheus.client.exporter.HTTPServer; //导入依赖的package包/类
private void startDefaultEndpoint() {
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            int port = DEFAULT_HTTP_PORT;

            if (configuration.containsKey("httpPort")) {
                port = Integer.parseInt((String)configuration.get("httpPort"));
            }

            try {
                LOGGER.fine("Starting Prometheus HttpServer on port " + port);

                new HTTPServer(port);

            } catch (Exception e) { //widen scope in case of ClassNotFoundException on non oracle/sun JVM
                LOGGER.log(WARNING, "Unable to register Prometheus HttpServer on port " + port, e);
            }
        }
    });
    thread.setDaemon(true);
    thread.start();
}
 
开发者ID:willfleury,项目名称:prometheus-metrics-agent,代码行数:24,代码来源:PrometheusMetricSystem.java

示例3: open

import io.prometheus.client.exporter.HTTPServer; //导入依赖的package包/类
@Override
public void open(MetricConfig config) {
	String portsConfig = config.getString(ARG_PORT, DEFAULT_PORT);
	Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig);

	while (ports.hasNext()) {
		int port = ports.next();
		try {
			httpServer = new HTTPServer(port);
			this.port = port;
			LOG.info("Started PrometheusReporter HTTP server on port {}.", port);
			break;
		} catch (IOException ioe) { //assume port conflict
			LOG.debug("Could not start PrometheusReporter HTTP server on port {}.", port, ioe);
		}
	}
	if (httpServer == null) {
		throw new RuntimeException("Could not start PrometheusReporter HTTP server on any configured port. Ports: " + portsConfig);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:PrometheusReporter.java

示例4: startDefaultEndpoint

import io.prometheus.client.exporter.HTTPServer; //导入依赖的package包/类
@Override
public void startDefaultEndpoint() {
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            int port = DEFAULT_HTTP_PORT;

            if (configuration.containsKey("httpPort")) {
                port = Integer.parseInt((String)configuration.get("httpPort"));
            }

            try {
                LOGGER.fine("Starting Prometheus HttpServer on port " + port);

                new HTTPServer(port);

            } catch (Exception e) { //widen scope in case of ClassNotFoundException on non oracle/sun JVM
                LOGGER.log(WARNING, "Unable to register Prometheus HttpServer on port " + port, e);
            }
        }
    });
    thread.setDaemon(true);
    thread.start();
}
 
开发者ID:willfleury,项目名称:metrics-agent,代码行数:25,代码来源:PrometheusMetricSystem.java

示例5: main

import io.prometheus.client.exporter.HTTPServer; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  if (args.length < 2) {
    System.err.println("Usage: WebServer <[hostname:]port> <yaml configuration file>");
    System.exit(1);
  }

  String[] hostnamePort = args[0].split(":");
  int port;
  InetSocketAddress socket;
  
  if (hostnamePort.length == 2) {
    port = Integer.parseInt(hostnamePort[1]);
    socket = new InetSocketAddress(hostnamePort[0], port);
  } else {
    port = Integer.parseInt(hostnamePort[0]);
    socket = new InetSocketAddress(port);
  }

  new JmxCollector(new File(args[1])).register();
  new HTTPServer(socket, CollectorRegistry.defaultRegistry);
}
 
开发者ID:prometheus,项目名称:jmx_exporter,代码行数:22,代码来源:WebServer.java

示例6: MetricsPublisher

import io.prometheus.client.exporter.HTTPServer; //导入依赖的package包/类
@Autowired
public MetricsPublisher(MetricsCollector metricsCollector) {
  //prometheus default port allocation is here : https://github.com/prometheus/prometheus/wiki/Default-port-allocations
  int publishPort = DynamicPropertyFactory.getInstance().getIntProperty(METRICS_PROMETHEUS_PORT, 9696).get();
  this.metricsCollector = metricsCollector;
  this.metricsCollector.register();
  try {
    this.httpServer = new HTTPServer(new InetSocketAddress(publishPort), CollectorRegistry.defaultRegistry, true);
    LOGGER.info("Prometheus httpServer listened {}.", publishPort);
  } catch (IOException e) {
    throw new ServiceCombException("create http publish server failed", e);
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:14,代码来源:MetricsPublisher.java

示例7: main

import io.prometheus.client.exporter.HTTPServer; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  DefaultExports.initialize();
  HTTPServer server = new HTTPServer(8000);
  while (true) {
    myFunction();
    Thread.sleep(1000);
  }
}
 
开发者ID:RobustPerception,项目名称:java_examples,代码行数:9,代码来源:JavaExample.java

示例8: premain

import io.prometheus.client.exporter.HTTPServer; //导入依赖的package包/类
public static void premain(String agentArgument, Instrumentation instrumentation) throws Exception {
  // Bind to all interfaces by default (this includes IPv6).
  String host = "0.0.0.0";

  // If we have IPv6 address in square brackets, extract it first and then
  // remove it from arguments to prevent confusion from too namy colons.
  Integer indexOfClosingSquareBracket = agentArgument.indexOf("]:");
  if (indexOfClosingSquareBracket >= 0) {
    host = agentArgument.substring(0, indexOfClosingSquareBracket + 1);
    agentArgument = agentArgument.substring(indexOfClosingSquareBracket + 2);
  }

  String[] args = agentArgument.split(":");
  if (args.length < 2 || args.length > 3) {
    System.err.println("Usage: -javaagent:/path/to/JavaAgent.jar=[host:]<port>:<yaml configuration file>");
    System.exit(1);
  }

  int port;
  String file;
  InetSocketAddress socket;

  if (args.length == 3) {
    port = Integer.parseInt(args[1]);
    socket = new InetSocketAddress(args[0], port);
    file = args[2];
  } else {
    port = Integer.parseInt(args[0]);
    socket = new InetSocketAddress(host, port);
    file = args[1];
  }

  new JmxCollector(new File(file)).register();
  DefaultExports.initialize();
  server = new HTTPServer(socket, CollectorRegistry.defaultRegistry, true);
}
 
开发者ID:prometheus,项目名称:jmx_exporter,代码行数:37,代码来源:JavaAgent.java

示例9: premain

import io.prometheus.client.exporter.HTTPServer; //导入依赖的package包/类
public static void premain(String agentArgument, Instrumentation instrumentation) throws Exception {
  String[] args = agentArgument.split(":");

  Map<String, String> arguments = new HashMap<String, String>();
  for (String arg : args) {
    String[] parts = arg.split("=");
    if (parts.length != 2) {
      throw new RuntimeException("Wrong argument format " + arg);
    } else {
      arguments.put(parts[0], parts[1]);
    }
  }

  Config config = new Config();
  if (arguments.containsKey("configfile")) {
    config = Config.from(new File(arguments.get("configfile")));
  }
  for (String argument : arguments.keySet()) {
    try {
      //TODO cast to boolean or int
      Field field = Config.class.getDeclaredField(argument);
      if (field.getType().equals(String.class)) {
        field.set(config, arguments.get(argument));
      } else if (field.getType().equals(int.class) || field.getType().equals(Integer.class)) {
        field.set(config, Integer.parseInt(arguments.get(argument)));
      }

    } catch (NoSuchFieldException ex) {
      System.out.println("Invalid configuration key: " + argument);
    }
  }


  //workaround to get a randomized port
  if (config.port == 0) {
    ServerSocket serverSocket = new ServerSocket(0);
    config.port = serverSocket.getLocalPort();
    serverSocket.close();
  }

  InetSocketAddress socketAddress = getInetSocketAddress(config.host, config.port);
  new JmxCollector(config).register();
  DefaultExports.initialize();
  server = new HTTPServer(socketAddress, CollectorRegistry.defaultRegistry);


  if (config.consulHost != null) {
    registerToConsul(config, socketAddress);
  }


}
 
开发者ID:flokkr,项目名称:jmxpromo,代码行数:53,代码来源:JavaAgent.java

示例10: start

import io.prometheus.client.exporter.HTTPServer; //导入依赖的package包/类
/**
 * Start HTTP server for exporting Solr metrics.
 *
 */
public void start() throws MalformedObjectNameException, IOException {
    InetSocketAddress socket = new InetSocketAddress(port);

    this.collector = new SolrCollector(solrClient, config, numThreads);

    this.registry.register(this.collector);

    this.httpServer = new HTTPServer(socket, this.registry);
}
 
开发者ID:mosuka,项目名称:solr-exporter,代码行数:14,代码来源:SolrExporter.java


注:本文中的io.prometheus.client.exporter.HTTPServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。