Class MicrometerRegistryBuilder
java.lang.Object
com.gigaspaces.metrics.micrometer.MicrometerRegistryBuilder
Builder for configuring MeterRegistry instances with various backends.
Usage:
MeterRegistry registry = new MicrometerRegistryBuilder()
.addInfluxDB("http://localhost:8086", "metrics", Duration.ofSeconds(10))
.addPrometheus()
.build();
- Since:
- 17.1.4
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd InfluxDB registry configured entirely from environment variables or system properties.addInfluxDB(String uri, String database, java.time.Duration step) Add InfluxDB registry with explicit configuration.Add logging registry with default step (1 minute).addLogging(java.time.Duration step) Add logging registry that logs metrics to console/logger.addLogging(java.time.Duration step, String outputFilePath) Add logging registry with file output.voidaddOtlp(String url, String headers, java.time.Duration step, io.micrometer.registry.otlp.AggregationTemporality temporality) Add an OTLP registry.voidAdd an OTLP registry reading configuration from system properties / environment variables.Add Prometheus registry (pull-based).io.micrometer.core.instrument.MeterRegistrybuild()Build the MeterRegistry.static io.micrometer.core.instrument.MeterRegistryCreate registry based on environment/system properties.static io.micrometer.core.instrument.MeterRegistrycreateInfluxDB(String uri, String database) Create a registry with InfluxDB backend.disable()Disable metrics completely (no collection, no export).
-
Constructor Details
-
MicrometerRegistryBuilder
public MicrometerRegistryBuilder()
-
-
Method Details
-
addInfluxDB
Add InfluxDB registry with explicit configuration. Properties not covered by the parameters (e.g. username, password, token) are read fromMETRICS_INFLUXDB_*env vars ormetrics.influxdb.*system properties. -
addInfluxDB
Add InfluxDB registry configured entirely from environment variables or system properties. Environment variables take priority over system properties.Each InfluxDB property maps to
METRICS_INFLUXDB_<PROPERTY>(env var) ormetrics.influxdb.<property>(system property). Examples:METRICS_INFLUXDB_URI=http://influx:8086 or metrics.influxdb.uri=http://influx:8086 METRICS_INFLUXDB_DB=mydb or metrics.influxdb.db=mydb METRICS_INFLUXDB_STEP=30 or metrics.influxdb.step=30 METRICS_INFLUXDB_USERNAME=admin or metrics.influxdb.username=admin METRICS_INFLUXDB_PASSWORD=secret or metrics.influxdb.password=secret METRICS_INFLUXDB_TOKEN=mytoken or metrics.influxdb.token=mytoken
Unset properties fall back to defaults: uri=http://localhost:8086, db=metrics, step=10s. -
addOtlpFromEnv
public void addOtlpFromEnv()Add an OTLP registry reading configuration from system properties / environment variables.metrics.otlp.url=https://... metrics.otlp.headers=Authorization=Api-Token TOKEN metrics.otlp.step=60
-
addPrometheus
Add Prometheus registry (pull-based). Note: You need to expose the Prometheus endpoint separately:PrometheusMeterRegistry prometheus = ...; // from builder // Expose scrape endpoint at /metrics String metricsOutput = prometheus.scrape();
-
addLogging
Add logging registry that logs metrics to console/logger. Useful for debugging and development. -
addLogging
Add logging registry with file output. Useful for testing when metrics need to be written to a file.- Parameters:
step- How often to log metricsoutputFilePath- Path to the output file
-
addLogging
Add logging registry with default step (1 minute). -
disable
Disable metrics completely (no collection, no export). Results in a CompositeMeterRegistry with no children - effectively a no-op. Use this when you want zero metrics overhead. -
build
public io.micrometer.core.instrument.MeterRegistry build()Build the MeterRegistry. - If disabled: returns empty CompositeMeterRegistry (no-op, zero overhead) - If multiple registries added: returns CompositeMeterRegistry - If single registry added: returns that registry - If no registries added: returns SimpleMeterRegistry (or as configured) -
createInfluxDB
public static io.micrometer.core.instrument.MeterRegistry createInfluxDB(String uri, String database) Create a registry with InfluxDB backend. -
createFromEnvironment
public static io.micrometer.core.instrument.MeterRegistry createFromEnvironment()Create registry based on environment/system properties. Supports loading configuration from a properties file (metrics.properties): - Set system property: -Dcom.gigaspaces.metrics.config.resource=/path/to/metrics.properties - Or environment variable: METRICS_CONFIG_FILE=/path/to/metrics.properties - Or place file at standard location: ${XAP_HOME}/config/metrics/metrics.properties (auto-discovered) The properties file will be loaded and all properties set as system properties before reading the configuration. Configuration properties: - metrics.registries=influxdb,prometheus,file (comma-separated list, enables multiple registries) Registry-specific properties: - metrics.influxdb.uri=(default: http://localhost:8086) - metrics.influxdb.db= (default: metrics) - metrics.influxdb.step= (default: 10) - metrics.file.path= (optional, if not set logs to console) - metrics.file.step= (default: 1) - Returns:
- MeterRegistry configured based on environment/properties. Returns CompositeMeterRegistry if multiple registries configured, single registry instance if one configured, or SimpleMeterRegistry if none configured (default).
-
addOtlp
public void addOtlp(String url, String headers, java.time.Duration step, io.micrometer.registry.otlp.AggregationTemporality temporality) Add an OTLP registry. Covers Dynatrace, Datadog (via OTLP endpoint), Grafana Cloud, and any OTLP-compatible backend.- Parameters:
url- OTLP metrics endpointheaders- Comma-separatedkey=valueauthentication headers, e.g."Authorization=Api-Token TOKEN". Passnullfor no headers.step- Push interval.
-