Search in sources :

Example 1 with HTTPServer

use of io.prometheus.client.exporter.HTTPServer in project incubator-servicecomb-java-chassis by apache.

the class MetricsHttpPublisher method init.

private void init(String address) {
    try {
        InetSocketAddress socketAddress = getSocketAddress(address);
        MetricsCollector metricsCollector = new MetricsCollector();
        metricsCollector.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);
    }
}
Also used : HTTPServer(io.prometheus.client.exporter.HTTPServer) InetSocketAddress(java.net.InetSocketAddress) ServiceCombException(org.apache.servicecomb.foundation.common.exceptions.ServiceCombException) ServiceCombException(org.apache.servicecomb.foundation.common.exceptions.ServiceCombException)

Example 2 with HTTPServer

use of io.prometheus.client.exporter.HTTPServer in project bboxdb by jnidzwetzki.

the class PerformanceCounterService method init.

@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);
    }
}
Also used : HTTPServer(io.prometheus.client.exporter.HTTPServer) BBoxDBConfiguration(org.bboxdb.misc.BBoxDBConfiguration) IOException(java.io.IOException)

Example 3 with HTTPServer

use of io.prometheus.client.exporter.HTTPServer in project modules-extra by CubeEngine.

the class Stats method onPreInit.

@Listener
public void onPreInit(GamePreInitializationEvent event) {
    final CollectorRegistry registry = monitoring.getRegistry();
    final InetSocketAddress bindAddr = new InetSocketAddress(config.bindAddress, config.bindPort);
    registerDefaults(registry);
    players.register(registry);
    tps.register(registry);
    loadedChunks.register(registry);
    playersOnline.register(registry);
    entities.register(registry);
    tileEntities.register(registry);
    try {
        this.exporter = new HTTPServer(bindAddr, registry, true);
        this.scheduler.scheduleAtFixedRate(this::sampleServer, config.samplingInterval.toMillis(), config.samplingInterval.toMillis(), TimeUnit.MILLISECONDS);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : HTTPServer(io.prometheus.client.exporter.HTTPServer) InetSocketAddress(java.net.InetSocketAddress) CollectorRegistry(io.prometheus.client.CollectorRegistry) IOException(java.io.IOException) Listener(org.spongepowered.api.event.Listener)

Example 4 with HTTPServer

use of io.prometheus.client.exporter.HTTPServer in project jmx_exporter by prometheus.

the class WebServer method main.

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);
}
Also used : HTTPServer(io.prometheus.client.exporter.HTTPServer) InetSocketAddress(java.net.InetSocketAddress) File(java.io.File)

Example 5 with HTTPServer

use of io.prometheus.client.exporter.HTTPServer in project jmx_exporter by prometheus.

the class JavaAgent method premain.

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);
}
Also used : HTTPServer(io.prometheus.client.exporter.HTTPServer) InetSocketAddress(java.net.InetSocketAddress) File(java.io.File)

Aggregations

HTTPServer (io.prometheus.client.exporter.HTTPServer)6 InetSocketAddress (java.net.InetSocketAddress)5 CollectorRegistry (io.prometheus.client.CollectorRegistry)2 File (java.io.File)2 IOException (java.io.IOException)2 ServiceCombException (org.apache.servicecomb.foundation.common.exceptions.ServiceCombException)1 BBoxDBConfiguration (org.bboxdb.misc.BBoxDBConfiguration)1 CollectorRegistrySingleton (org.opendaylight.infrautils.metrics.prometheus.impl.CollectorRegistrySingleton)1 PrometheusMetricProviderImpl (org.opendaylight.infrautils.metrics.prometheus.impl.PrometheusMetricProviderImpl)1 Listener (org.spongepowered.api.event.Listener)1