io.prometheus.client.exporter.PushGateway Java Examples
The following examples show how to use
io.prometheus.client.exporter.PushGateway.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricsPushGatewayService.java From besu with Apache License 2.0 | 7 votes |
@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); }
Example #2
Source File: PrometheusPushGatewayReporter.java From Flink-CEPplus with Apache License 2.0 | 7 votes |
@Override public void open(MetricConfig config) { super.open(config); String host = config.getString(HOST.key(), HOST.defaultValue()); int port = config.getInteger(PORT.key(), PORT.defaultValue()); String configuredJobName = config.getString(JOB_NAME.key(), JOB_NAME.defaultValue()); boolean randomSuffix = config.getBoolean(RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue()); deleteOnShutdown = config.getBoolean(DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue()); if (host == null || host.isEmpty() || port < 1) { throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port); } if (randomSuffix) { this.jobName = configuredJobName + new AbstractID(); } else { this.jobName = configuredJobName; } pushGateway = new PushGateway(host + ':' + port); log.info("Configured PrometheusPushGatewayReporter with {host:{}, port:{}, jobName: {}, randomJobNameSuffix:{}, deleteOnShutdown:{}}", host, port, jobName, randomSuffix, deleteOnShutdown); }
Example #3
Source File: PrometheusMetricService.java From kardio with Apache License 2.0 | 7 votes |
/** * Push the Metric data to Prometheus end point. * @param registry */ private static void pushMetricToPrometheus(final CollectorRegistry registry,final String surveillerTaskName){ ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { try { PushGateway pg = new PushGateway(prometheusGateWayURL); Map<String, String> groupingKey = new HashMap<String, String>(); groupingKey.put("instance", InetAddress.getLocalHost().getHostName().replace(".corporate.t-mobile.com", "")); groupingKey.put("task_name", surveillerTaskName); pg.pushAdd(registry, "SHD_SURVEILLER", groupingKey); } catch (IOException e) { logger.error("Unable to push Prometheus Metric", e); } }); executor.shutdown(); }
Example #4
Source File: PrometheusPushGatewayReporter.java From flink with Apache License 2.0 | 6 votes |
@Override public void open(MetricConfig config) { super.open(config); String host = config.getString(HOST.key(), HOST.defaultValue()); int port = config.getInteger(PORT.key(), PORT.defaultValue()); String configuredJobName = config.getString(JOB_NAME.key(), JOB_NAME.defaultValue()); boolean randomSuffix = config.getBoolean(RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue()); deleteOnShutdown = config.getBoolean(DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue()); if (host == null || host.isEmpty() || port < 1) { throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port); } if (randomSuffix) { this.jobName = configuredJobName + new AbstractID(); } else { this.jobName = configuredJobName; } pushGateway = new PushGateway(host + ':' + port); log.info("Configured PrometheusPushGatewayReporter with {host:{}, port:{}, jobName: {}, randomJobNameSuffix:{}, deleteOnShutdown:{}}", host, port, jobName, randomSuffix, deleteOnShutdown); }
Example #5
Source File: PushDemo.java From sofa-lookout with Apache License 2.0 | 6 votes |
static void executeBatchJob() throws Exception { CollectorRegistry registry = CollectorRegistry.defaultRegistry; Counter requests = Counter.build() .name("my_library_requests_total").help("Total requests.") .labelNames("method").register(); requests.labels("get").inc(); PushGateway pushgateway = new PushGateway("127.0.0.1:7200/prom"); // pushgateway.setConnectionFactory(new BasicAuthHttpConnectionFactory("my_user", "my_password")); Map<String, String> groupingkeys = new HashMap<>(); groupingkeys.put("app", "xx"); pushgateway.pushAdd(registry, "my_batch_job", groupingkeys); // pushgateway.pushAdd(registry, "my_batch_job"); }
Example #6
Source File: PushGatewayProviderTest.java From graylog-plugin-metrics-reporter with GNU General Public License v3.0 | 6 votes |
@Test public void getReturnsPushGatewayProvider() throws Exception { final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_ACCEPTED)); server.start(); final MetricsPrometheusReporterConfiguration configuration = new MetricsPrometheusReporterConfiguration() { @Override public HostAndPort getAddress() { return HostAndPort.fromParts(server.getHostName(), server.getPort()); } }; final PushGatewayProvider provider = new PushGatewayProvider(configuration); final PushGateway pushGateway = provider.get(); pushGateway.push(CollectorRegistry.defaultRegistry, "test"); final RecordedRequest request = server.takeRequest(); assertEquals("PUT", request.getMethod()); assertEquals("/metrics/job/test", request.getPath()); assertEquals("text/plain; version=0.0.4; charset=utf-8", request.getHeader("Content-Type")); assertEquals(0L, request.getBodySize()); }
Example #7
Source File: PrometheusPushGatewayReporter.java From flink with Apache License 2.0 | 6 votes |
@Override public void open(MetricConfig config) { super.open(config); String host = config.getString(HOST.key(), HOST.defaultValue()); int port = config.getInteger(PORT.key(), PORT.defaultValue()); String configuredJobName = config.getString(JOB_NAME.key(), JOB_NAME.defaultValue()); boolean randomSuffix = config.getBoolean(RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue()); deleteOnShutdown = config.getBoolean(DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue()); groupingKey = parseGroupingKey(config.getString(GROUPING_KEY.key(), GROUPING_KEY.defaultValue())); if (host == null || host.isEmpty() || port < 1) { throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port); } if (randomSuffix) { this.jobName = configuredJobName + new AbstractID(); } else { this.jobName = configuredJobName; } pushGateway = new PushGateway(host + ':' + port); log.info("Configured PrometheusPushGatewayReporter with {host:{}, port:{}, jobName:{}, randomJobNameSuffix:{}, deleteOnShutdown:{}, groupingKey:{}}", host, port, jobName, randomSuffix, deleteOnShutdown, groupingKey); }
Example #8
Source File: PrometheusMetricService.java From kardio with Apache License 2.0 | 5 votes |
/** * Push the Metric data to Prometheus end point. * * @param registry */ private void pushMetricToPrometheus(final CollectorRegistry registry, final String endPointName) { ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(new Runnable() { @Override public void run() { try { PushGateway pg = new PushGateway(prometheusGateWayURL); Map<String, String> groupingKey = new HashMap<String, String>(); groupingKey.put("instance", InetAddress.getLocalHost().getHostName().replace(".corporate.t-mobile.com", "")); groupingKey.put("endpoint_name", endPointName); pg.pushAdd(registry, "SHD_API", groupingKey); } catch (IOException e) { log.error("Unable to push Prometheus Metric", e); } } }); executor.shutdown(); }
Example #9
Source File: PrometheusExporter.java From keycloak-metrics-spi with Apache License 2.0 | 5 votes |
/** * Build a prometheus pushgateway if an address is defined in environment. * * @return PushGateway */ private PushGateway buildPushGateWay() { // host:port or ip:port of the Pushgateway. String host = System.getenv("PROMETHEUS_PUSHGATEWAY_ADDRESS"); if(host != null){ return new PushGateway(host); } else { return null; } }
Example #10
Source File: Metric.java From paraflow with Apache License 2.0 | 5 votes |
public Metric(String gateWayUrl, String id, String name, String help, String job) { this.id = id; this.job = job; this.gateway = new PushGateway(gateWayUrl); this.metric = Gauge.build().name(name).help(help).labelNames("id").register(registry); }
Example #11
Source File: PushGatewayPeriodical.java From graylog-plugin-metrics-reporter with GNU General Public License v3.0 | 5 votes |
@Inject public PushGatewayPeriodical(MetricsPrometheusReporterConfiguration configuration, CollectorRegistry collectorRegistry, PushGateway pushGateway) { this.configuration = requireNonNull(configuration); this.collectorRegistry = requireNonNull(collectorRegistry); this.pushGateway = requireNonNull(pushGateway); }
Example #12
Source File: MetricsPrometheusReporterModule.java From graylog-plugin-metrics-reporter with GNU General Public License v3.0 | 5 votes |
@Override protected void configure() { addConfigBeans(); bind(DropwizardExports.class).toProvider(DropwizardExportsProvider.class); bind(CollectorRegistry.class).toProvider(CollectorRegistryProvider.class); bind(PushGateway.class).toProvider(PushGatewayProvider.class); addPeriodical(PushGatewayPeriodical.class); addRestResource(MetricsResource.class); }
Example #13
Source File: CollectorThroughputMetric.java From paraflow with Apache License 2.0 | 4 votes |
public CollectorThroughputMetric(String id, String gatewayUrl) { this.id = id; this.gateway = new PushGateway(gatewayUrl); }
Example #14
Source File: PushGatewayProvider.java From graylog-plugin-metrics-reporter with GNU General Public License v3.0 | 4 votes |
@Override public PushGateway get() { final HostAndPort address = configuration.getAddress().withDefaultPort(9091); return new PushGateway(address.toString()); }