Search in sources :

Example 1 with PushGateway

use of io.prometheus.client.exporter.PushGateway in project polaris-java by polarismesh.

the class PrometheusPushHandler method doPush.

private void doPush() {
    try {
        putDataFromContainerInOrder(container.getInsCollector(), container.getInsCollector().getCurrentRevision(), SystemMetricLabelOrder.INSTANCE_GAUGE_LABEL_ORDER);
        putDataFromContainerInOrder(container.getRateLimitCollector(), container.getRateLimitCollector().getCurrentRevision(), SystemMetricLabelOrder.RATELIMIT_GAUGE_LABEL_ORDER);
        putDataFromContainerInOrder(container.getCircuitBreakerCollector(), 0, SystemMetricLabelOrder.CIRCUIT_BREAKER_LABEL_ORDER);
        try {
            if (null == pushAddress && null != addressProvider) {
                setPushAddress(addressProvider.getAddress());
            }
            if (null == pushAddress) {
                return;
            }
            if (getPushGateway() == null) {
                LOG.info("init push-gateway {} ", pushAddress);
                setPushGateway(new PushGateway(pushAddress));
            }
            pushGateway.pushAdd(promRegistry, jobName, Collections.singletonMap(PUSH_GROUP_KEY, instanceName));
            // pushGateway.pushAdd(promRegistry, jobName, Collections.emptyMap());
            LOG.info("push result to push-gateway {} success", pushAddress);
        } catch (IOException exception) {
            LOG.error("push result to push-gateway {} encountered exception, exception:{}", pushAddress, exception.getMessage());
            setPushGateway(null);
            setPushAddress(null);
            return;
        }
        for (StatInfoCollector<?, ? extends StatMetric> s : container.getCollectors()) {
            if (s instanceof StatInfoRevisionCollector<?>) {
                long currentRevision = ((StatInfoRevisionCollector<?>) s).incRevision();
                LOG.debug("RevisionCollector inc current revision to {}", currentRevision);
            }
        }
    } catch (Exception e) {
        LOG.error("push result to push-gateway {} encountered exception, exception:{}", pushAddress, e.getMessage());
        e.printStackTrace();
    }
}
Also used : StatInfoRevisionCollector(com.tencent.polaris.plugins.stat.common.model.StatInfoRevisionCollector) PushGateway(io.prometheus.client.exporter.PushGateway) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with PushGateway

use of io.prometheus.client.exporter.PushGateway in project spring-batch by spring-projects.

the class PrometheusConfiguration method init.

@PostConstruct
public void init() {
    pushGateway = new PushGateway(prometheusPushGatewayUrl);
    groupingKey.put(prometheusGroupingKey, prometheusJobName);
    PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
    collectorRegistry = prometheusMeterRegistry.getPrometheusRegistry();
    Metrics.globalRegistry.add(prometheusMeterRegistry);
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) PushGateway(io.prometheus.client.exporter.PushGateway) PostConstruct(jakarta.annotation.PostConstruct)

Example 3 with PushGateway

use of io.prometheus.client.exporter.PushGateway in project dsbulk by datastax.

the class PrometheusManager method pushMetrics.

public void pushMetrics(Duration elapsed, boolean success) {
    if (pushConfig != null) {
        try {
            CollectorRegistry collectorRegistry = new CollectorRegistry();
            new DropwizardExports(registry, PUSH_METRIC_FILTER, sampleBuilder).register(collectorRegistry);
            addFinalMetrics(elapsed, success, collectorRegistry);
            PushGateway pg = new PushGateway(pushConfig.gatewayUrl);
            if (!pushConfig.username.isEmpty() && !pushConfig.password.isEmpty()) {
                pg.setConnectionFactory(new BasicAuthHttpConnectionFactory(pushConfig.username, pushConfig.password));
            }
            Map<String, String> groupingKeys = new LinkedHashMap<>();
            if (pushConfig.groupByInstance) {
                groupingKeys.putAll(PushGateway.instanceIPGroupingKey());
            }
            if (pushConfig.groupByOperation) {
                groupingKeys.put(OPERATION_ID_LABEL, executionId);
            }
            groupingKeys.putAll(pushConfig.groupByKeys);
            pg.pushAdd(collectorRegistry, jobName, groupingKeys);
        } catch (Exception e) {
            LOGGER.error(String.format("Push to Prometheus PushGateway %s failed. %s", pushConfig.gatewayUrl, ThrowableUtils.getSanitizedErrorMessage(e)), e);
        }
    }
}
Also used : DropwizardExports(io.prometheus.client.dropwizard.DropwizardExports) CollectorRegistry(io.prometheus.client.CollectorRegistry) PushGateway(io.prometheus.client.exporter.PushGateway) BasicAuthHttpConnectionFactory(io.prometheus.client.exporter.BasicAuthHttpConnectionFactory) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with PushGateway

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

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 5 with PushGateway

use of io.prometheus.client.exporter.PushGateway in project spring-boot by spring-projects.

the class PrometheusMetricsExportAutoConfigurationTests method getPushGateway.

private PushGateway getPushGateway(AssertableApplicationContext context) {
    assertThat(context).hasSingleBean(PrometheusPushGatewayManager.class);
    PrometheusPushGatewayManager gatewayManager = context.getBean(PrometheusPushGatewayManager.class);
    return (PushGateway) ReflectionTestUtils.getField(gatewayManager, "pushGateway");
}
Also used : PushGateway(io.prometheus.client.exporter.PushGateway) PrometheusPushGatewayManager(org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager)

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