Search in sources :

Example 1 with Child

use of io.prometheus.client.Gauge.Child in project promregator by promregator.

the class MetricsFetcherSimulatorTest method testCall.

@Test
void testCall() throws Exception {
    AbstractMetricFamilySamplesEnricher mfse = new CFAllLabelsMetricFamilySamplesEnricher("testOrgName", "testSpaceName", "testapp", "testinstance1:0");
    Gauge up = Gauge.build("up_test", "help test").labelNames(CFAllLabelsMetricFamilySamplesEnricher.getEnrichingLabelNames()).create();
    Child upChild = up.labels(mfse.getEnrichedLabelValues(new LinkedList<>()).toArray(new String[0]));
    MetricsFetcherSimulator subject = new MetricsFetcherSimulator("accessUrl", new NullEnricher(), mfse, Mockito.mock(MetricsFetcherMetrics.class), upChild);
    HashMap<String, MetricFamilySamples> result = subject.call();
    Assertions.assertEquals(3, result.size());
}
Also used : NullEnricher(org.cloudfoundry.promregator.auth.NullEnricher) AbstractMetricFamilySamplesEnricher(org.cloudfoundry.promregator.rewrite.AbstractMetricFamilySamplesEnricher) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) CFAllLabelsMetricFamilySamplesEnricher(org.cloudfoundry.promregator.rewrite.CFAllLabelsMetricFamilySamplesEnricher) Child(io.prometheus.client.Gauge.Child) Gauge(io.prometheus.client.Gauge) Test(org.junit.jupiter.api.Test)

Example 2 with Child

use of io.prometheus.client.Gauge.Child in project bookkeeper by apache.

the class PrometheusMetricsProvider method start.

@Override
public void start(Configuration conf) {
    int httpPort = conf.getInt(PROMETHEUS_STATS_HTTP_PORT, DEFAULT_PROMETHEUS_STATS_HTTP_PORT);
    InetSocketAddress httpEndpoint = InetSocketAddress.createUnresolved("0.0.0.0", httpPort);
    this.server = new Server(httpEndpoint);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new PrometheusServlet(this)), "/metrics");
    try {
        server.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // Include standard JVM stats
    new StandardExports().register(registry);
    new MemoryPoolsExports().register(registry);
    new GarbageCollectorExports().register(registry);
    new ThreadExports().register(registry);
    // Add direct memory allocated through unsafe
    Gauge.build("jvm_memory_direct_bytes_used", "-").create().setChild(new Child() {

        @Override
        public double get() {
            return directMemoryUsage != null ? directMemoryUsage.longValue() : Double.NaN;
        }
    }).register(registry);
    Gauge.build("jvm_memory_direct_bytes_max", "-").create().setChild(new Child() {

        @Override
        public double get() {
            return PlatformDependent.maxDirectMemory();
        }
    }).register(registry);
    executor = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("metrics"));
    int latencyRolloverSeconds = conf.getInt(PROMETHEUS_STATS_LATENCY_ROLLOVER_SECONDS, DEFAULT_PROMETHEUS_STATS_LATENCY_ROLLOVER_SECONDS);
    executor.scheduleAtFixedRate(() -> {
        rotateLatencyCollection();
    }, 1, latencyRolloverSeconds, TimeUnit.SECONDS);
    log.info("Started Prometheus stats endpoint at {}", httpEndpoint);
}
Also used : Server(org.eclipse.jetty.server.Server) StandardExports(io.prometheus.client.hotspot.StandardExports) ThreadExports(io.prometheus.client.hotspot.ThreadExports) InetSocketAddress(java.net.InetSocketAddress) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) IOException(java.io.IOException) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) GarbageCollectorExports(io.prometheus.client.hotspot.GarbageCollectorExports) MemoryPoolsExports(io.prometheus.client.hotspot.MemoryPoolsExports) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Child(io.prometheus.client.Gauge.Child)

Aggregations

Child (io.prometheus.client.Gauge.Child)2 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)1 MetricFamilySamples (io.prometheus.client.Collector.MetricFamilySamples)1 Gauge (io.prometheus.client.Gauge)1 GarbageCollectorExports (io.prometheus.client.hotspot.GarbageCollectorExports)1 MemoryPoolsExports (io.prometheus.client.hotspot.MemoryPoolsExports)1 StandardExports (io.prometheus.client.hotspot.StandardExports)1 ThreadExports (io.prometheus.client.hotspot.ThreadExports)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 NullEnricher (org.cloudfoundry.promregator.auth.NullEnricher)1 AbstractMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.AbstractMetricFamilySamplesEnricher)1 CFAllLabelsMetricFamilySamplesEnricher (org.cloudfoundry.promregator.rewrite.CFAllLabelsMetricFamilySamplesEnricher)1 Server (org.eclipse.jetty.server.Server)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 Test (org.junit.jupiter.api.Test)1