use of org.eclipse.hono.adapter.resourcelimits.PrometheusBasedResourceLimitChecks in project hono by eclipse.
the class AbstractProtocolAdapterApplication method prometheusResourceLimitChecks.
/**
* Creates resource limit checks based on data retrieved from a Prometheus server
* via its HTTP API.
*
* @param config The configuration properties.
* @param tenantClient The client to use for retrieving tenant configuration data.
* @throws NullPointerException if any of the parameters are {@code null}-
* @return The checks.
*/
protected ResourceLimitChecks prometheusResourceLimitChecks(final PrometheusBasedResourceLimitChecksConfig config, final TenantClient tenantClient) {
Objects.requireNonNull(config);
Objects.requireNonNull(tenantClient);
if (config.isHostConfigured()) {
final WebClientOptions webClientOptions = new WebClientOptions();
webClientOptions.setConnectTimeout(config.getConnectTimeout());
webClientOptions.setDefaultHost(config.getHost());
webClientOptions.setDefaultPort(config.getPort());
webClientOptions.setTrustOptions(config.getTrustOptions());
webClientOptions.setKeyCertOptions(config.getKeyCertOptions());
webClientOptions.setSsl(config.isTlsEnabled());
final var webClient = WebClient.create(vertx, webClientOptions);
final var cacheTimeout = Duration.ofSeconds(config.getCacheTimeout());
final Caffeine<Object, Object> builder = Caffeine.newBuilder().executor(Executors.newSingleThreadExecutor(r -> {
final var t = new Thread(r);
t.setDaemon(true);
return t;
})).initialCapacity(config.getCacheMinSize()).maximumSize(config.getCacheMaxSize()).expireAfterWrite(cacheTimeout).refreshAfterWrite(cacheTimeout.dividedBy(2));
return new PrometheusBasedResourceLimitChecks(builder.buildAsync(new ConnectedDevicesAsyncCacheLoader(webClient, config, tracer)), builder.buildAsync(new ConnectionDurationAsyncCacheLoader(webClient, config, tracer)), builder.buildAsync(new DataVolumeAsyncCacheLoader(webClient, config, tracer)), tenantClient, tracer);
} else {
return new NoopResourceLimitChecks();
}
}
Aggregations