Class MetricMetadata
Object
MetricMetadata
Immutable container for metric metadata: name, help, unit.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionMetricMetadata(String name) MetricMetadata(String name, String help) MetricMetadata(String name, String help, Unit unit) Constructor.MetricMetadata(String name, String expositionBaseName, String help, Unit unit) Deprecated.Deprecated.Usebuilder()instead. -
Method Summary
Modifier and TypeMethodDescriptionstatic MetricMetadata.Builderbuilder()Creates a builder forMetricMetadata.The base name for exposition, with unit suffix ensured and type suffix preserved.Same asgetExpositionBaseName()but with all invalid characters and dots replaced by underscores.getHelp()getName()The name does not include the_totalsuffix for counter metrics or the_infosuffix for Info metrics.The original name as provided by the user, before any modification.Same asgetName()but with all invalid characters and dots replaced by underscores.getUnit()booleanhasUnit()
-
Constructor Details
-
MetricMetadata
-
MetricMetadata
-
MetricMetadata
Constructor.- Parameters:
name- must not benull.isValidMetricName(name)must betrue. UsePrometheusNaming.sanitizeMetricName(String)to convert arbitrary strings into valid names.help- optional. May benull.unit- optional. May benull.
-
MetricMetadata
@StableApi @Deprecated public MetricMetadata(String name, String expositionBaseName, @Nullable String help, @Nullable Unit unit) Deprecated.Usebuilder()instead.Constructor with exposition base name.- Parameters:
name- the base name (with type suffixes stripped, e.g. "events" for a counter named "events_total")expositionBaseName- the name with unit suffix ensured and type suffix preserved, used by format writers for smart-append logichelp- optional. May benull.unit- optional. May benull.
-
MetricMetadata
@StableApi @Deprecated public MetricMetadata(String name, String expositionBaseName, String originalName, @Nullable String help, @Nullable Unit unit) Deprecated.Usebuilder()instead.Constructor with exposition base name and original name.- Parameters:
name- the base name (with type suffixes stripped, e.g. "events" for a counter named "events_total")expositionBaseName- the name with unit suffix ensured and type suffix preservedoriginalName- the raw name as provided by the user, before any modificationhelp- optional. May benull.unit- optional. May benull.
-
-
Method Details
-
builder
Creates a builder forMetricMetadata.Use the builder instead of the multi-arg constructors for cleaner, more readable code:
MetricMetadata.builder() .name("http_requests") .help("Total HTTP requests") .unit(Unit.BYTES) .counterSuffix(true) .build(); -
getName
The name does not include the_totalsuffix for counter metrics or the_infosuffix for Info metrics.The name may contain any Unicode chars. Use
getPrometheusName()to get the name in legacy Prometheus format, i.e. with all dots and all invalid chars replaced by underscores. -
getPrometheusName
Same asgetName()but with all invalid characters and dots replaced by underscores.This is used by Prometheus exposition formats.
-
getOriginalName
The original name as provided by the user, before any modification. For example, if the user calledCounter.builder().name("req").unit(BYTES), this returns "req" whilegetName()returns "req_bytes" andgetExpositionBaseName()returns "req_bytes". -
getExpositionBaseName
The base name for exposition, with unit suffix ensured and type suffix preserved. For example, if the user calledCounter.builder().name("events_total"), this returns "events_total" whilegetName()returns "events". -
getExpositionBasePrometheusName
Same asgetExpositionBaseName()but with all invalid characters and dots replaced by underscores. -
getHelp
-
hasUnit
-
getUnit
-
builder()instead.