Core instrumentation library for the Prometheus Java client, providing fundamental metric types for application monitoring
—
Info metrics provide key-value metadata pairs for build information, version details, configuration data, and other static or semi-static information. They expose labels with a constant value of 1, making them ideal for metadata that doesn't change frequently.
Create info metrics using the builder pattern for metadata collection.
/**
* Create a new Info builder
* @return Builder instance for configuration
*/
public static Info.Builder build();
/**
* Create a new Info builder with required fields
* @param name The metric name (will have _info suffix added)
* @param help The help text describing the metadata
* @return Builder instance for configuration
*/
public static Info.Builder build(String name, String help);Usage Example:
import io.prometheus.client.Info;
// Application build information
Info buildInfo = Info.build()
.name("application_build")
.help("Application build information")
.register();
// Service configuration info
Info serviceConfig = Info.build()
.name("service_config")
.help("Service configuration metadata")
.labelNames("service", "environment")
.register();Configure info metrics with labels and metadata structure.
public static class Builder extends SimpleCollector.Builder<Builder, Info> {
// Note: Info metrics cannot have a unit - throws IllegalStateException
// Inherits: name(), help(), labelNames(), namespace(), subsystem(),
// register(), create()
}Important: Info metrics cannot have units. Attempting to set a unit will throw an IllegalStateException.
Set metadata information using key-value pairs provided as alternating strings.
/**
* Set info metadata using alternating key-value pairs
* @param labelPairs Even number of strings as key-value pairs
* @throws IllegalArgumentException if odd number of strings provided
*/
public void info(String... labelPairs);Usage Examples:
// Basic build information
buildInfo.info(
"version", "1.2.3",
"commit", "abc123def456",
"branch", "main",
"build_time", "2024-01-15T10:30:00Z"
);
// Service configuration per environment
serviceConfig.labels("user-service", "production").info(
"max_connections", "100",
"timeout_seconds", "30",
"cache_enabled", "true",
"log_level", "INFO"
);
serviceConfig.labels("user-service", "development").info(
"max_connections", "10",
"timeout_seconds", "60",
"cache_enabled", "false",
"log_level", "DEBUG"
);Work with multi-dimensional info metrics using label values.
/**
* Get info child for specific label values
* @param labelValues Values for each label name (must match count)
* @return Info.Child instance for the label combination
* @throws IllegalArgumentException if wrong number of labels
*/
public Info.Child labels(String... labelValues);
/**
* Remove info child for specific label values
* @param labelValues Values identifying the child to remove
*/
public void remove(String... labelValues);
/**
* Remove all info children
*/
public void clear();Info.Child provides metadata operations for labeled instances.
public static class Child {
/**
* Set info metadata for this child using key-value pairs
* @param labelPairs Even number of strings as alternating keys and values
* @throws IllegalArgumentException if odd number of strings
*/
public void info(String... labelPairs);
}Usage Example:
// Application component information
Info componentInfo = Info.build()
.name("component_info")
.help("Component build and runtime information")
.labelNames("component", "instance")
.register();
// Set information for different components
Info.Child webComponent = componentInfo.labels("web-server", "instance-1");
webComponent.info(
"version", "2.1.0",
"port", "8080",
"protocol", "HTTP/1.1",
"worker_threads", "10"
);
Info.Child dbComponent = componentInfo.labels("database", "primary");
dbComponent.info(
"version", "PostgreSQL 13.7",
"max_connections", "200",
"shared_buffers", "256MB",
"maintenance_work_mem", "64MB"
);
// Update info when configuration changes
webComponent.info(
"version", "2.1.1", // Updated version
"port", "8080",
"protocol", "HTTP/2", // Updated protocol
"worker_threads", "20" // Updated thread count
);Info metrics automatically handle the _info suffix:
build_info as the name, it becomes build internallybuild_info for Prometheus compatibilityThe info() method requires an even number of strings:
// Valid usage
info.info("key1", "value1", "key2", "value2");
// Invalid - throws IllegalArgumentException
info.info("key1", "value1", "key2"); // Missing value for key2
info.info("key1"); // Missing value for key1// Application metadata
Info appInfo = Info.build()
.name("application")
.help("Application metadata")
.register();
appInfo.info(
"name", "user-management-service",
"version", "3.2.1",
"git_commit", "a1b2c3d4e5f6",
"build_date", "2024-01-15",
"java_version", System.getProperty("java.version"),
"spring_boot_version", "2.7.8"
);
// Infrastructure information
Info infraInfo = Info.build()
.name("infrastructure")
.help("Infrastructure and deployment information")
.labelNames("environment", "region")
.register();
infraInfo.labels("production", "us-east-1").info(
"kubernetes_version", "1.25.4",
"node_count", "12",
"cluster_name", "prod-cluster",
"ingress_controller", "nginx-1.5.1"
);
// Feature flags and configuration
Info featureFlags = Info.build()
.name("feature_flags")
.help("Feature flag states")
.labelNames("service")
.register();
featureFlags.labels("user-service").info(
"new_auth_enabled", "true",
"rate_limiting_enabled", "false",
"cache_version", "v2",
"experimental_features", "disabled"
);
// Database configuration
Info dbConfig = Info.build()
.name("database_config")
.help("Database configuration and settings")
.labelNames("database_name", "role")
.register();
dbConfig.labels("users_db", "primary").info(
"engine", "PostgreSQL",
"version", "14.5",
"max_connections", "100",
"shared_preload_libraries", "pg_stat_statements",
"timezone", "UTC"
);All info operations are thread-safe:
// Safe concurrent access
Info concurrentInfo = Info.build()
.name("concurrent_metadata")
.help("Thread-safe info metric")
.register();
// Multiple threads can safely update
concurrentInfo.info("key1", "value1"); // Thread 1
concurrentInfo.info("key2", "value2"); // Thread 2Info metrics are particularly useful for:
Install with Tessl CLI
npx tessl i tessl/maven-io-prometheus--simpleclient