private void delete() { try { this.pushGateway.delete(this.job, this.groupingKey); } catch (Throwable ex) { logger.error("Unable to delete metrics from Prometheus Pushgateway", ex); } }
/** * Pushes all metrics in a registry, replacing only previously pushed metrics of the same name. * <p> * This uses the POST HTTP method. * @deprecated use {@link #pushAdd(CollectorRegistry, String, Map)} */ @Deprecated public void pushAdd(CollectorRegistry registry, String job, String instance) throws IOException { pushAdd(registry, job, Collections.singletonMap("instance", instance)); }
/** * Pushes all metrics in a Collector, replacing all those with the same job and instance. * <p> * This is useful for pushing a single Gauge. * <p> * This uses the PUT HTTP method. * @deprecated use {@link #push(Collector, String, Map)} */ @Deprecated public void push(Collector collector, String job, String instance) throws IOException { push(collector, job, Collections.singletonMap("instance", instance)); }
public PrometheusUriSender(Configure configure) { URI uri = configure.getMetricUri(); try { this.gateway = new PushGateway(uri.toURL()); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Pushes all metrics in a registry, replacing only previously pushed metrics of the same name, job and grouping key. * <p> * This uses the POST HTTP method. */ public void pushAdd(CollectorRegistry registry, String job, Map<String, String> groupingKey) throws IOException { doRequest(registry, job, groupingKey, "POST"); }
/** * Construct a Pushgateway, with the given address. * <p> * @param address host:port or ip:port of the Pushgateway. */ public PushGateway(String address) { this(createURLSneakily("http://" + address)); }
InputStream errorStream = connection.getErrorStream(); if(response >= 400 && errorStream != null) { String errBody = readFromStream(errorStream); errorMessage = "Response code from " + url + " was " + response + ", response body: " + errBody; } else {
public PrometheusReporter(String address, String job, Map<String, String> labels, MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit) { super(registry, name, filter, rateUnit, durationUnit); this.pushGateway = new PushGateway(address); this.address = address; this.job = job; this.registry.register(new MetricRegistryDecorator(registry, job, labels)); }
/** * Deletes metrics from the Pushgateway. * <p> * Deletes metrics with no grouping key and the provided job. * This uses the DELETE HTTP method. */ public void delete(String job) throws IOException { doRequest(null, job, null, "DELETE"); }
/** * Pushes all metrics in a Collector, replacing only previously pushed metrics of the same name. * <p> * This is useful for pushing a single Gauge. * <p> * This uses the POST HTTP method. * @deprecated use {@link #pushAdd(Collector, String, Map)} */ @Deprecated public void pushAdd(Collector collector, String job, String instance) throws IOException { pushAdd(collector, job, Collections.singletonMap("instance", instance)); }
/** * Pushes all metrics in a registry, replacing all those with the same job and instance. * <p> * This uses the PUT HTTP method. * @deprecated use {@link #push(CollectorRegistry, String, Map)} */ @Deprecated public void push(CollectorRegistry registry, String job, String instance) throws IOException { push(registry, job, Collections.singletonMap("instance", instance)); }
/** * Deletes metrics from the Pushgateway. * <p> * This uses the DELETE HTTP method. * @deprecated use {@link #delete(String, Map)} */ @Deprecated public void delete(String job, String instance) throws IOException { delete(job, Collections.singletonMap("instance", instance)); }
@Bean @ConditionalOnMissingBean public PrometheusPushGatewayManager prometheusPushGatewayManager( CollectorRegistry collectorRegistry, PrometheusProperties prometheusProperties, Environment environment) { PrometheusProperties.Pushgateway properties = prometheusProperties .getPushgateway(); PushGateway pushGateway = new PushGateway(properties.getBaseUrl()); Duration pushRate = properties.getPushRate(); String job = getJob(properties, environment); Map<String, String> groupingKey = properties.getGroupingKey(); ShutdownOperation shutdownOperation = properties.getShutdownOperation(); return new PrometheusPushGatewayManager(pushGateway, collectorRegistry, pushRate, job, groupingKey, shutdownOperation); }
/** * Deletes metrics from the Pushgateway. * <p> * Deletes metrics with the provided job and grouping key. * This uses the DELETE HTTP method. */ public void delete(String job, Map<String, String> groupingKey) throws IOException { doRequest(null, job, groupingKey, "DELETE"); }
private void push() { try { this.pushGateway.pushAdd(this.registry, this.job, this.groupingKey); } catch (UnknownHostException ex) { String host = ex.getMessage(); String message = "Unable to locate prometheus push gateway host" + (StringUtils.hasLength(host) ? " '" + host + "'" : "") + ". No longer attempting metrics publication to this host"; logger.error(message, ex); shutdown(ShutdownOperation.NONE); } catch (Throwable ex) { logger.error("Unable to push metrics to Prometheus Pushgateway", ex); } }
/** * Pushes all metrics in a Collector, replacing all those with the same job and no grouping key. * <p> * This is useful for pushing a single Gauge. * <p> * This uses the PUT HTTP method. */ public void push(Collector collector, String job) throws IOException { CollectorRegistry registry = new CollectorRegistry(); collector.register(registry); push(registry, job); }
@Override public void delete(String job, Map<String, String> groupingKey) throws IOException { gateway.delete(job, groupingKey); } }
@Bean @ConditionalOnMissingBean public PrometheusPushGatewayManager prometheusPushGatewayManager( CollectorRegistry collectorRegistry, PrometheusProperties prometheusProperties, Environment environment) { PrometheusProperties.Pushgateway properties = prometheusProperties .getPushgateway(); PushGateway pushGateway = new PushGateway(properties.getBaseUrl()); Duration pushRate = properties.getPushRate(); String job = getJob(properties, environment); Map<String, String> groupingKey = properties.getGroupingKey(); PrometheusPushGatewayManager.ShutdownOperation shutdownOperation = properties.getShutdownOperation(); return new PrometheusPushGatewayManager(pushGateway, collectorRegistry, pushRate, job, groupingKey, shutdownOperation); }
/** * Pushes all metrics in a registry, replacing all those with the same job and no grouping key. * <p> * This uses the PUT HTTP method. */ public void push(CollectorRegistry registry, String job) throws IOException { doRequest(registry, job, null, "PUT"); }
/** * Pushes all metrics in a Collector, replacing only previously pushed metrics of the same name and job and no grouping key. * <p> * This is useful for pushing a single Gauge. * <p> * This uses the POST HTTP method. */ public void pushAdd(Collector collector, String job) throws IOException { CollectorRegistry registry = new CollectorRegistry(); collector.register(registry); pushAdd(registry, job); }