Search in sources :

Example 6 with PushGateway

use of io.prometheus.client.exporter.PushGateway in project nimbus by nimbus-org.

the class GaugePushgatewayWriterService method startService.

public void startService() throws Exception {
    if (name == null || "".equals(name)) {
        throw new IllegalArgumentException("Name is null or empty.");
    }
    if (valuePropertyList == null || valuePropertyList.isEmpty()) {
        throw new IllegalArgumentException("ValuePropertyList is null or empty.");
    }
    if (pushGatewayHostName == null || "".equals(pushGatewayHostName)) {
        throw new IllegalArgumentException("PushGatewayHostName is null or empty.");
    }
    if (pushGatewayPort <= 0) {
        throw new IllegalArgumentException("PushGatewayPort is illegal value. PushGatewayPort=" + pushGatewayPort);
    }
    if (pushGatewayJobName == null || "".equals(pushGatewayJobName)) {
        pushGatewayJobName = getServiceNameObject().toString();
    }
    int labelNamesSize = (labelPropertyList == null ? 0 : labelPropertyList.size()) + (fixedLabelMap == null ? 0 : fixedLabelMap.size());
    List labelNameList = null;
    if (labelNamesSize > 0) {
        isOutputLabel = true;
        labelNameList = new ArrayList();
        if (labelPropertyList != null && labelPropertyList.size() > 0) {
            labelNameList.addAll(labelPropertyList);
        }
        if (fixedLabelMap != null && fixedLabelMap.size() > 0) {
            labelNameList.addAll(fixedLabelMap.keySet());
            fixedLabelValues = fixedLabelMap.values();
        }
    }
    for (int i = 0; i < valuePropertyList.size(); i++) {
        String key = (String) valuePropertyList.get(i);
        Builder builder = Gauge.build().name(name + "_" + key.toLowerCase());
        if (help != null && !"".equals(help)) {
            builder = builder.help(help + "(" + key + ")");
        }
        if (isOutputLabel) {
            builder = builder.labelNames((String[]) labelNameList.toArray(new String[0]));
        }
        gaugeMap.put(key, builder.register(registry));
    }
    pushGateway = new PushGateway(pushGatewayHostName + ":" + pushGatewayPort);
}
Also used : Builder(io.prometheus.client.Gauge.Builder) ArrayList(java.util.ArrayList) PushGateway(io.prometheus.client.exporter.PushGateway) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with PushGateway

use of io.prometheus.client.exporter.PushGateway in project druid by apache.

the class PrometheusEmitterTest method testEmitterPush.

@Test
public void testEmitterPush() throws IOException {
    PrometheusEmitterConfig emitterConfig = new PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.pushgateway, "namespace3", null, 0, "pushgateway");
    PushGateway mockPushGateway = mock(PushGateway.class);
    mockPushGateway.push(anyObject(Collector.class), anyString(), anyObject(ImmutableMap.class));
    PrometheusEmitter emitter = new PrometheusEmitter(emitterConfig);
    emitter.start();
    emitter.setPushGateway(mockPushGateway);
    ServiceMetricEvent build = ServiceMetricEvent.builder().setDimension("task", "index_parallel").build("task/run/time", 500).build(ImmutableMap.of("service", "peon"));
    emitter.emit(build);
    emitter.flush();
}
Also used : Collector(io.prometheus.client.Collector) PushGateway(io.prometheus.client.exporter.PushGateway) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 8 with PushGateway

use of io.prometheus.client.exporter.PushGateway in project notifications-backend by RedHatInsights.

the class DailyEmailAggregationJob method processDailyEmail.

@ActivateRequestContext
public void processDailyEmail() {
    CollectorRegistry registry = new CollectorRegistry();
    Gauge duration = Gauge.build().name("aggregator_job_duration_seconds").help("Duration of the aggregator job in seconds.").register(registry);
    Gauge.Timer durationTimer = duration.startTimer();
    try {
        LocalDateTime now = LocalDateTime.now(UTC);
        List<AggregationCommand> aggregationCommands = processAggregateEmails(now, registry);
        List<CompletableFuture<Void>> futures = new ArrayList<>();
        for (AggregationCommand aggregationCommand : aggregationCommands) {
            try {
                final String payload = objectMapper.writeValueAsString(aggregationCommand);
                futures.add(emitter.send(payload).toCompletableFuture());
            } catch (JsonProcessingException e) {
                LOG.warn("Could not transform AggregationCommand to JSON object.", e);
            }
            // resolve completable futures so the Quarkus main thread doesn't stop before everything has been sent
            try {
                CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get();
            } catch (InterruptedException | ExecutionException ie) {
                LOG.error("Writing AggregationCommands failed", ie);
            }
        }
        emailAggregationResources.updateLastCronJobRun(now);
        Gauge lastSuccess = Gauge.build().name("aggregator_job_last_success").help("Last time the aggregator job succeeded.").register(registry);
        lastSuccess.setToCurrentTime();
    } finally {
        durationTimer.setDuration();
        PushGateway pg = new PushGateway(prometheusPushGatewayUrl);
        try {
            pg.pushAdd(registry, "aggregator_job");
        } catch (IOException e) {
            LOG.warn("Could not push metrics to Prometheus Pushgateway.", e);
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ArrayList(java.util.ArrayList) CollectorRegistry(io.prometheus.client.CollectorRegistry) IOException(java.io.IOException) Gauge(io.prometheus.client.Gauge) CompletableFuture(java.util.concurrent.CompletableFuture) AggregationCommand(com.redhat.cloud.notifications.models.AggregationCommand) PushGateway(io.prometheus.client.exporter.PushGateway) ExecutionException(java.util.concurrent.ExecutionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ActivateRequestContext(javax.enterprise.context.control.ActivateRequestContext)

Example 9 with PushGateway

use of io.prometheus.client.exporter.PushGateway in project besu by hyperledger.

the class MetricsPushGatewayService method start.

@Override
public CompletableFuture<?> start() {
    LOG.info("Starting metrics push gateway service pushing to {}:{}", config.getPushHost(), config.getPushPort());
    pushGateway = new PushGateway(config.getPushHost() + ":" + config.getPushPort());
    // Create the executor
    scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
    scheduledExecutorService.scheduleAtFixedRate(this::pushMetrics, config.getPushInterval() / 2, config.getPushInterval(), TimeUnit.SECONDS);
    return CompletableFuture.completedFuture(null);
}
Also used : PushGateway(io.prometheus.client.exporter.PushGateway)

Example 10 with PushGateway

use of io.prometheus.client.exporter.PushGateway in project jackrabbit-oak by apache.

the class MetricsExporterFixtureProviderTest method checkCorrectPushGatewayInit.

@Test
public void checkCorrectPushGatewayInit() throws Exception {
    OptionParser parser = new OptionParser();
    DataStoreOptions dataStoreOptions = new DataStoreOptions(parser);
    OptionSet option = parser.parse("--export-metrics", "pushgateway;localhost:9091;key1=value1,key2=value2");
    dataStoreOptions.configure(option);
    MetricsExporterFixture metricsExporterFixture = MetricsExporterFixtureProvider.create(dataStoreOptions, new DefaultWhiteboard());
    assertEquals("pushgateway", metricsExporterFixture.getExporterType().name());
    Object metricsExporter = metricsExporterFixture.getMetricsExporter();
    assertTrue(metricsExporter instanceof PushGateway);
}
Also used : DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) PushGateway(io.prometheus.client.exporter.PushGateway) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Aggregations

PushGateway (io.prometheus.client.exporter.PushGateway)14 CollectorRegistry (io.prometheus.client.CollectorRegistry)5 IOException (java.io.IOException)3 Test (org.junit.Test)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Collector (io.prometheus.client.Collector)2 Gauge (io.prometheus.client.Gauge)2 DropwizardExports (io.prometheus.client.dropwizard.DropwizardExports)2 BasicAuthHttpConnectionFactory (io.prometheus.client.exporter.BasicAuthHttpConnectionFactory)2 ArrayList (java.util.ArrayList)2 ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AggregationCommand (com.redhat.cloud.notifications.models.AggregationCommand)1 StatInfoRevisionCollector (com.tencent.polaris.plugins.stat.common.model.StatInfoRevisionCollector)1 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)1 Builder (io.prometheus.client.Gauge.Builder)1 PostConstruct (jakarta.annotation.PostConstruct)1 UncheckedIOException (java.io.UncheckedIOException)1 LocalDateTime (java.time.LocalDateTime)1