@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; }
@Override public void terminate() { running = false; try { instanceExports.terminate(); if (clientProfiler.isStart()) { clientProfiler.stop(); } profiler().setInstanceProfiler(NOP); if (server != null) { server.stop(); } } catch (Throwable t) { logger.warn("Something happened while terminating.", t); } }
public void handle(HttpExchange t) throws IOException { String query = t.getRequestURI().getRawQuery(); ByteArrayOutputStream response = this.response.get(); response.reset(); OutputStreamWriter osw = new OutputStreamWriter(response); TextFormat.write004(osw, registry.filteredMetricFamilySamples(parseQuery(query))); osw.flush(); osw.close(); response.flush(); response.close(); t.getResponseHeaders().set("Content-Type", TextFormat.CONTENT_TYPE_004); if (shouldUseCompression(t)) { t.getResponseHeaders().set("Content-Encoding", "gzip"); t.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0); final GZIPOutputStream os = new GZIPOutputStream(t.getResponseBody()); response.writeTo(os); os.close(); } else { t.getResponseHeaders().set("Content-Length", String.valueOf(response.size())); t.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.size()); response.writeTo(t.getResponseBody()); } t.close(); }
public void handle(HttpExchange t) throws IOException { String query = t.getRequestURI().getRawQuery(); ByteArrayOutputStream response = this.response.get(); response.reset(); OutputStreamWriter osw = new OutputStreamWriter(response); TextFormat.write004(osw, registry.filteredMetricFamilySamples(parseQuery(query))); osw.flush(); osw.close(); response.flush(); response.close(); t.getResponseHeaders().set("Content-Type", TextFormat.CONTENT_TYPE_004); if (shouldUseCompression(t)) { t.getResponseHeaders().set("Content-Encoding", "gzip"); t.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0); final GZIPOutputStream os = new GZIPOutputStream(t.getResponseBody()); response.writeTo(os); os.close(); } else { t.getResponseHeaders().set("Content-Length", String.valueOf(response.size())); t.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.size()); response.writeTo(t.getResponseBody()); } t.close(); }
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); } }
@Override public void destroy() { if (httpServer == null) { return; } httpServer.stop(); httpServer = null; LOGGER.info("Prometheus httpServer stopped."); } }
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 BuildInfoCollector().register(); new JmxCollector(new File(args[1])).register(); new HTTPServer(socket, CollectorRegistry.defaultRegistry); } }
@Override public void destroy() { if (this.server != null) { this.server.stop(); } }
@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); } }
@Override public void stop() { logger.trace("Stopping DataDog reporter."); server.stop(); }
@PostConstruct public void startServer() throws IOException { this.server = new HTTPServer(new InetSocketAddress(metricsPort), collectorRegistry, true); LOG.info("Metrics server started at port {} successfully ", metricsPort); }
@PreDestroy public void stopServer() { if (server != null) { server.stop(); LOG.info("Metrics server suspended at port {} successfully ", metricsPort); } } }
/** * Constructor. * * @param configuration Reporter configuration * @param globalConfiguration Global configuration * @throws IOException if HTTPServer cannot be initialized */ public PrometheusReporter(ReporterConfiguration configuration, GlobalConfiguration globalConfiguration) throws IOException { super(configuration, globalConfiguration); logger.debug("Initializing prometheus client with config: {}", configuration.toString()); final String httpServerHost = configuration.getOption(HTTP_SERVER_HOST_KEY); final int httpServerPort = configuration.getDefaultOption(HTTP_SERVER_PORT_KEY, DEFAULT_HTTP_SERVER_PORT); server = new HTTPServer(httpServerHost, httpServerPort); logger.info("Initialized prometheus reporter on host and port: {}", httpServerHost + ":" + httpServerPort); }
@Override public void terminate() { running = false; try { instanceExports.terminate(); if (clientProfiler.isStart()) { clientProfiler.stop(); } profiler().setInstanceProfiler(NOP); if (server != null) { server.stop(); } } catch (Throwable t) { logger.warn("Something happened while terminating.", t); } }
@Override public void startup() { PrometheusStatsCollector.createAndRegister(); DefaultExports.initialize(); try { this.server = new HTTPServer(this.exporterConfig.getExportPort()); } catch (Exception e) { // } }
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); } }
@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; }
public static void main(String[] args) throws Exception { Logger logger = LoggerFactory.getLogger(Main.class); String configPath = args.length > 0 ? args[0] : Config.DEFAULT_PATH; Optional<Config> cfgO = Config.fromFile(configPath); if (!cfgO.isPresent()) { logger.error("Cannot parse config file present at {}", configPath); return; } Config cfg = cfgO.get(); boolean isOneShot = Arrays.asList(args).contains("--oneshot"); HTTPServer server = new HTTPServer(cfg.getListenAddress(), cfg.getListenPort()); JmxScraper scrapper = new JmxScraper(String.format("service:jmx:rmi:///jndi/rmi://%s/jmxrmi", cfg.getHost()), cfg.getUser(), cfg.getPassword(), cfg.getSSL(), cfg.getBlacklist(), cfg.getMaxScrapFrequencyInSec()); if (isOneShot) { scrapper.run(false); System.exit(0); } for (; ; ) { try { scrapper.run(true); } catch (Exception e) { logger.error("Scrapper stopped due to uncaught exception", e); } try { Thread.sleep(1000); } catch (InterruptedException e) { System.exit(0); } } }
try { DefaultExports.initialize(); HTTPServer server = new HTTPServer(port); } catch (IOException e) { logger.error("initializing prometheus failed", e);