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