io.prometheus.client.exporter.HTTPServer Java Examples
The following examples show how to use
io.prometheus.client.exporter.HTTPServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrometheusService.java From canal with Apache License 2.0 | 8 votes |
@Override public void initialize() { try { logger.info("Start prometheus HTTPServer on port {}.", port); //TODO 2.Https? server = new HTTPServer(port); } catch (IOException e) { logger.warn("Unable to start prometheus HTTPServer.", e); return; } try { // JVM exports DefaultExports.initialize(); instanceExports.initialize(); if (!clientProfiler.isStart()) { clientProfiler.start(); } profiler().setInstanceProfiler(clientProfiler); } catch (Throwable t) { logger.warn("Unable to initialize server exports.", t); } running = true; }
Example #2
Source File: PrometheusService.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
@Override public void initialize() { try { logger.info("Start prometheus HTTPServer on port {}.", port); //TODO 2.Https? server = new HTTPServer(port); } catch (IOException e) { logger.warn("Unable to start prometheus HTTPServer.", e); return; } try { // JVM exports DefaultExports.initialize(); instanceExports.initialize(); if (!clientProfiler.isStart()) { clientProfiler.start(); } profiler().setInstanceProfiler(clientProfiler); } catch (Throwable t) { logger.warn("Unable to initialize server exports.", t); } running = true; }
Example #3
Source File: PrometheusBistouryMetricRegistry.java From bistoury with GNU General Public License v3.0 | 6 votes |
public PrometheusBistouryMetricRegistry() { DynamicConfig<LocalDynamicConfig> config = DynamicConfigLoader.load("prometheus.properties", false); String type = config.getString("monitor.type", "prometheus"); if ("prometheus".equals(type)) { String action = config.getString("monitor.action", "metrics"); if ("metrics".equals(action)) { try { HTTPServer server = new HTTPServer(config.getInt("monitor.port", 3333)); } catch (IOException e) { e.printStackTrace(); } } } else if ("graphite".equals(type)) { String host = config.getString("graphite.host"); int port = config.getInt("graphite.port"); Graphite graphite = new Graphite(host, port); graphite.start(CollectorRegistry.defaultRegistry, 60); } }
Example #4
Source File: Prometheus.java From MantaroBot with GNU General Public License v3.0 | 6 votes |
public static void enable() throws IOException { if (STATE.compareAndSet(State.DISABLED, State.ENABLING)) { //replaced by jfr? needs testing, if yes then remove //used for cpu usage new StandardExports().register(); //replaced by jfr? needs testing, if yes then remove //used for memory usage new MemoryPoolsExports().register(); //ig we can keep this one for now new BufferPoolsExports().register(); //replaced by jfr, jfr also has this as a histogram //new GarbageCollectorExports().register(); //not needed //new ClassLoadingExports().register(); //not needed //new VersionInfoExports().register(); //replaced by jfr //new MantaroThreadExports().register(); //replaced by jfr //new SafepointExports().register(); JFRExports.register(); //DiscordLatencyExports.register(); server = new HTTPServer(MantaroData.config().get().prometheusPort); STATE.set(State.ENABLED); } }
Example #5
Source File: PrometheusPublisher.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Override public void init(GlobalRegistry globalRegistry, EventBus eventBus, MetricsBootstrapConfig config) { this.globalRegistry = globalRegistry; //prometheus default port allocation is here : https://github.com/prometheus/prometheus/wiki/Default-port-allocations String address = DynamicPropertyFactory.getInstance().getStringProperty(METRICS_PROMETHEUS_ADDRESS, "0.0.0.0:9696").get(); try { InetSocketAddress socketAddress = getSocketAddress(address); register(); this.httpServer = new HTTPServer(socketAddress, CollectorRegistry.defaultRegistry, true); LOGGER.info("Prometheus httpServer listened : {}.", address); } catch (Exception e) { throw new ServiceCombException("create http publish server failed,may bad address : " + address, e); } }
Example #6
Source File: PrometheusQmqMetricRegistry.java From qmq with Apache License 2.0 | 6 votes |
public PrometheusQmqMetricRegistry() { DynamicConfig config = DynamicConfigLoader.load("qmq.prometheus.properties", false); String type = config.getString("monitor.type", "prometheus"); if ("prometheus".equals(type)) { String action = config.getString("monitor.action", "pull"); if ("pull".equals(action)) { try { HTTPServer server = new HTTPServer(config.getInt("monitor.port", 3333)); } catch (IOException e) { e.printStackTrace(); } } } else if ("graphite".equals(type)) { String host = config.getString("graphite.host"); int port = config.getInt("graphite.port"); Graphite graphite = new Graphite(host, port); graphite.start(CollectorRegistry.defaultRegistry, 60); } }
Example #7
Source File: PerformanceCounterService.java From bboxdb with Apache License 2.0 | 6 votes |
@Override public void init() throws InterruptedException, BBoxDBException { final BBoxDBConfiguration bboxDBConfiguration = BBoxDBConfigurationManager.getConfiguration(); final int port = bboxDBConfiguration.getPerformanceCounterPort(); // Service is disabled if(port == -1) { logger.info("Performance counter service is disabled"); return; } logger.info("Starting performance counter service on port: {}", port); // Expose JVM stats DefaultExports.initialize(); try { server = new HTTPServer(port); } catch (IOException e) { logger.error("Got an exception during starting up performance counter HTTP sever", e); } }
Example #8
Source File: PrometheusReporter.java From flink with Apache License 2.0 | 6 votes |
@Override public void open(MetricConfig config) { super.open(config); String portsConfig = config.getString(ARG_PORT, DEFAULT_PORT); Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig); while (ports.hasNext()) { int port = ports.next(); try { // internally accesses CollectorRegistry.defaultRegistry 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); } }
Example #9
Source File: TxleMetrics.java From txle with Apache License 2.0 | 6 votes |
public TxleMetrics(String promMetricsPort) { try { DefaultExports.initialize(); // Default port logic: the default port 8099 has been configured in application.yaml, thus if it's not 8099, then indicate that someone edited it automatically. if (promMetricsPort != null && promMetricsPort.length() > 0) { int metricsPort = Integer.parseInt(promMetricsPort); if (metricsPort > 0) { // Initialize Prometheus's Metrics Server. // To establish the metrics server immediately without checking the port status. new HTTPServer(metricsPort); isEnableMonitorServer = true; } } this.register(); } catch (IOException e) { log.error("Initialize txle metrics server exception, please check the port " + promMetricsPort + ". " + e); } }
Example #10
Source File: CommonPrometheusMetrics.java From txle with Apache License 2.0 | 6 votes |
public CommonPrometheusMetrics(String promMetricsPort) { try { if (httpServer) { return; } // Default port logic: the default port 8098 if it's null. If not null, use the config value. int metricsPort = Integer.parseInt(promMetricsPort); if (metricsPort > 0) { // Initialize Prometheus's Metrics Server. // To establish the metrics server immediately without checking the port status. new HTTPServer(metricsPort); setHttpServer(true); } } catch (IOException e) { LOG.error(TxleConstants.LOG_ERROR_PREFIX + "Initialize txle sql metrics server exception, please check the port " + promMetricsPort + ". " + e); } }
Example #11
Source File: PrometheusReporter.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public void open(MetricConfig config) { super.open(config); String portsConfig = config.getString(ARG_PORT, DEFAULT_PORT); Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig); while (ports.hasNext()) { int port = ports.next(); try { // internally accesses CollectorRegistry.defaultRegistry 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); } }
Example #12
Source File: PrometheusReporter.java From flink with Apache License 2.0 | 6 votes |
@Override public void open(MetricConfig config) { super.open(config); String portsConfig = config.getString(ARG_PORT, DEFAULT_PORT); Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig); while (ports.hasNext()) { int port = ports.next(); try { // internally accesses CollectorRegistry.defaultRegistry 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); } }
Example #13
Source File: JavaAgent.java From jmx_exporter with Apache License 2.0 | 6 votes |
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"; try { Config config = parseConfig(agentArgument, host); new BuildInfoCollector().register(); new JmxCollector(new File(config.file)).register(); DefaultExports.initialize(); server = new HTTPServer(config.socket, CollectorRegistry.defaultRegistry, true); } catch (IllegalArgumentException e) { System.err.println("Usage: -javaagent:/path/to/JavaAgent.jar=[host:]<port>:<yaml configuration file> " + e.getMessage()); System.exit(1); } }
Example #14
Source File: SolrExporter.java From lucene-solr with Apache License 2.0 | 5 votes |
void start() throws IOException { defaultRegistry.register(prometheusCollector); metricsCollector.addObserver(prometheusCollector); metricsCollector.start(); httpServer = new HTTPServer(new InetSocketAddress(port), defaultRegistry); }
Example #15
Source File: PrometheusMetricsTrackerManagerTest.java From shardingsphere with Apache License 2.0 | 5 votes |
@Test public void startHost() { PrometheusMetricsTrackerManager manager = new PrometheusMetricsTrackerManager(); MetricsConfiguration metricsConfiguration = new MetricsConfiguration("metricsName", "127.0.0.1", 9195, false, true, 8, null); manager.start(metricsConfiguration); HTTPServer server = manager.getServer(); assertThat(server.getPort(), is(9195)); assertNotNull(server); assertThat(manager.getType(), is("prometheus")); manager.stop(); }
Example #16
Source File: PrometheusMetricsTrackerManagerTest.java From shardingsphere with Apache License 2.0 | 5 votes |
@Test public void startNoHost() { PrometheusMetricsTrackerManager manager = new PrometheusMetricsTrackerManager(); MetricsConfiguration metricsConfiguration = new MetricsConfiguration("metricsName", "", 9191, false, true, 8, null); manager.start(metricsConfiguration); HTTPServer server = manager.getServer(); assertNotNull(server); assertThat(manager.getType(), is("prometheus")); manager.stop(); }
Example #17
Source File: PrometheusTelemetryProvider.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void prepare() throws ServiceNotProvidedException, ModuleStartException { this.registerServiceImplementation(MetricsCreator.class, new PrometheusMetricsCreator()); this.registerServiceImplementation(MetricsCollector.class, new MetricsCollectorNoop()); try { new HTTPServer(config.getHost(), config.getPort()); } catch (IOException e) { throw new ModuleStartException(e.getMessage(), e); } DefaultExports.initialize(); }
Example #18
Source File: JavaExample.java From java_examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { DefaultExports.initialize(); HTTPServer server = new HTTPServer(8000); while (true) { myFunction(); Thread.sleep(1000); } }
Example #19
Source File: HelloWorldServer.java From opencensus-java with Apache License 2.0 | 5 votes |
/** Main launches the server from the command line. */ public static void main(String[] args) throws IOException, InterruptedException { // Add final keyword to pass checkStyle. final int serverPort = getPortOrDefaultFromArgs(args, 0, 50051); final String cloudProjectId = getStringOrDefaultFromArgs(args, 1, null); final int zPagePort = getPortOrDefaultFromArgs(args, 2, 3000); final int prometheusPort = getPortOrDefaultFromArgs(args, 3, 9090); // Registers all RPC views. For demonstration all views are registered. You may want to // start with registering basic views and register other views as needed for your application. RpcViews.registerAllViews(); // Registers logging trace exporter. LoggingTraceExporter.register(); // Starts a HTTP server and registers all Zpages to it. ZPageHandlers.startHttpServerAndRegisterAll(zPagePort); logger.info("ZPages server starts at localhost:" + zPagePort); // Registers Stackdriver exporters. if (cloudProjectId != null) { StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder().setProjectId(cloudProjectId).build()); StackdriverStatsExporter.createAndRegister( StackdriverStatsConfiguration.builder() .setProjectId(cloudProjectId) .setExportInterval(Duration.create(60, 0)) .build()); } // Register Prometheus exporters and export metrics to a Prometheus HTTPServer. PrometheusStatsCollector.createAndRegister(); HTTPServer prometheusServer = new HTTPServer(prometheusPort, true); // Start the RPC server. You shouldn't see any output from gRPC before this. logger.info("gRPC starting."); final HelloWorldServer server = new HelloWorldServer(serverPort); server.start(); server.blockUntilShutdown(); }
Example #20
Source File: HelloWorldServer.java From opencensus-java with Apache License 2.0 | 5 votes |
private static void initStatsExporter() throws IOException { HttpViews.registerAllServerViews(); // Register Prometheus exporters and export metrics to a Prometheus HTTPServer. // Refer to https://prometheus.io/ to run Prometheus Server. PrometheusStatsCollector.createAndRegister(); HTTPServer prometheusServer = new HTTPServer(9090, true); }
Example #21
Source File: HelloWorldClient.java From opencensus-java with Apache License 2.0 | 5 votes |
private static void initStatsExporter() throws IOException { HttpViews.registerAllClientViews(); // Register Prometheus exporters and export metrics to a Prometheus HTTPServer. // Refer to https://prometheus.io/ to run Prometheus Server. PrometheusStatsCollector.createAndRegister(); HTTPServer prometheusServer = new HTTPServer(9091, true); }
Example #22
Source File: Repl.java From opencensus-java with Apache License 2.0 | 5 votes |
private static void setupOpenCensusAndPrometheusExporter() throws IOException { // Firstly register the views registerAllViews(); // Create and register the Prometheus exporter PrometheusStatsCollector.createAndRegister(); // Run the server as a daemon on address "localhost:8889" HTTPServer server = new HTTPServer("localhost", 8889, true); }
Example #23
Source File: Application.java From opencensus-java with Apache License 2.0 | 5 votes |
private static void initStatsExporter() throws IOException { HttpViews.registerAllServerViews(); HttpViews.registerAllClientViews(); // Register Prometheus exporters and export metrics to a Prometheus HTTPServer. // Refer to https://prometheus.io/ to run Prometheus Server. PrometheusStatsCollector.createAndRegister(); HTTPServer prometheusServer = new HTTPServer(9090, true); }
Example #24
Source File: Metrics.java From FlareBot with MIT License | 5 votes |
public Metrics() { DefaultExports.initialize(); new BotCollector(new BotMetrics()).register(); try { server = new HTTPServer(9191); logger.info("Setup HTTPServer for Metrics"); } catch (IOException e) { throw new IllegalStateException("Failed to set up HTTPServer for Metrics", e); } }
Example #25
Source File: TestPrometheusPublisher.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void collect() throws IllegalAccessException, IOException { new Expectations(RegistrationManager.INSTANCE) { { RegistrationManager.INSTANCE.getAppId(); result = "testAppId"; } }; ArchaiusUtils.setProperty(PrometheusPublisher.METRICS_PROMETHEUS_ADDRESS, "localhost:0"); publisher.init(globalRegistry, null, null); Registry registry = new DefaultRegistry(new ManualClock()); globalRegistry.add(registry); Counter counter = registry.counter("count.name", "tag1", "tag1v", "tag2", "tag2v"); counter.increment(); HTTPServer httpServer = (HTTPServer) FieldUtils.readField(publisher, "httpServer", true); com.sun.net.httpserver.HttpServer server = (HttpServer) FieldUtils.readField(httpServer, "server", true); URL url = new URL("http://localhost:" + server.getAddress().getPort() + "/metrics"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); try (InputStream is = conn.getInputStream()) { Assert.assertEquals("# HELP ServiceComb_Metrics ServiceComb Metrics\n" + "# TYPE ServiceComb_Metrics untyped\n" + "count_name{appId=\"testAppId\",tag1=\"tag1v\",tag2=\"tag2v\",} 1.0\n", IOUtils.toString(is, StandardCharsets.UTF_8)); } publisher.destroy(); }
Example #26
Source File: SDKEntrypoint.java From abstract-operator with Apache License 2.0 | 5 votes |
public void onStart(@Observes StartupEvent event) { log.info("Starting.."); CompletableFuture<Void> future = run().exceptionally(ex -> { log.error("Unable to start operator for one or more namespaces", ex); System.exit(1); return null; }); if (config.isMetrics()) { CompletableFuture<Optional<HTTPServer>> maybeMetricServer = future.thenCompose(s -> runMetrics()); } }
Example #27
Source File: PrometheusExporter.java From tunnel with Apache License 2.0 | 5 votes |
@Override public void startup() { PrometheusStatsCollector.createAndRegister(); DefaultExports.initialize(); try { this.server = new HTTPServer(this.exporterConfig.getExportPort()); } catch (Exception e) { // } }
Example #28
Source File: PrometheusExporter.java From tunnel with Apache License 2.0 | 5 votes |
@Override public void startup() { PrometheusStatsCollector.createAndRegister(); DefaultExports.initialize(); try { this.server = new HTTPServer(this.exporterConfig.getExportPort()); } catch (Exception e) { // } }
Example #29
Source File: EnforceCommandTest.java From kafka-helmsman with MIT License | 5 votes |
@Before public void setup() throws IOException { config = converter.convert( new ByteArrayInputStream(testConf.getBytes(Charset.forName("UTF-8")))); config.put("metricsPort", findFreePort()); enforcer = mock(Enforcer.class); metricServer = mock(HTTPServer.class); }
Example #30
Source File: EnforceCommand.java From kafka-helmsman with MIT License | 5 votes |
int doRun(final Enforcer enforcer, final Supplier<Boolean> stopCondition) { LOG.info("Dry run is {}, safe mode is {}", dryrun ? "ON" : "OFF", unsafemode ? "OFF" : "ON"); if (!continuous) { return runOnceIgnoreError(enforcer); } // continuous mode HTTPServer server = null; final int port = (int) cmdConfig().getOrDefault("metricsPort", 8081); try { server = metricServer(port); LOG.info("Started metrics server at port {}", port); while (!stopCondition.get()) { runOnceIgnoreError(enforcer); Thread.sleep(interval * 1000); } } catch (Exception e) { // exception caught here must have come prometheus server or thread interrupt // all other exceptions are swallowed by runOnceIgnoreError routine LOG.error("Unexpected error", e); return FAILURE; } finally { if (server != null) { server.stop(); } } return SUCCESS; }