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();
}
}
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);
}
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);
}
}
}
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();
}
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");
}
Aggregations