Package org.confng.metrics
Class ConfigMetrics
- java.lang.Object
-
- org.confng.metrics.ConfigMetrics
-
public class ConfigMetrics extends Object
Tracks configuration access metrics including lookup counts, cache hits, and timing.This class provides observability into configuration usage patterns, which can help identify frequently accessed keys, cache effectiveness, and potential issues.
Example Usage:
// Enable metrics collection ConfigMetrics.getInstance().setEnabled(true); // Get metrics long lookups = ConfigMetrics.getInstance().getTotalLookups(); long cacheHits = ConfigMetrics.getInstance().getCacheHits(); double hitRate = ConfigMetrics.getInstance().getCacheHitRate(); // Get per-key metrics Map<String, Long> keyLookups = ConfigMetrics.getInstance().getKeyLookupCounts(); // Export metrics String json = ConfigMetrics.getInstance().toJson();- Since:
- 1.1.0
- Author:
- Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetCacheHitRate()longgetCacheHits()longgetCacheMisses()longgetDecryptionAttempts()longgetDecryptionFailures()longgetDefaultValueUsed()static ConfigMetricsgetInstance()Gets the singleton instance.Map<String,Long>getKeyLookupCounts()longgetLookupCount(String key)Gets the lookup count for a specific key.longgetMissingRequiredKeys()longgetSourceLookupCount(String sourceName)Gets the lookup count for a specific source.Map<String,Long>getSourceLookupCounts()longgetTotalLookups()longgetUptimeMs()booleanisEnabled()Checks if metrics collection is enabled.voidlogSummary()Logs a summary of current metrics.voidrecordDecryption(boolean success)Records a decryption attempt.voidrecordLookup(String key, boolean cacheHit, boolean usedDefault)Records a configuration lookup.voidrecordMissingRequired(String key)Records a missing required key.voidrecordSourceLookup(String sourceName)Records a source lookup.voidreset()Resets all metrics.voidsetEnabled(boolean enabled)Enables or disables metrics collection.StringtoJson()Exports metrics as JSON string.
-
-
-
Method Detail
-
getInstance
public static ConfigMetrics getInstance()
Gets the singleton instance.
-
setEnabled
public void setEnabled(boolean enabled)
Enables or disables metrics collection.
-
isEnabled
public boolean isEnabled()
Checks if metrics collection is enabled.
-
recordLookup
public void recordLookup(String key, boolean cacheHit, boolean usedDefault)
Records a configuration lookup.
-
recordSourceLookup
public void recordSourceLookup(String sourceName)
Records a source lookup.
-
recordMissingRequired
public void recordMissingRequired(String key)
Records a missing required key.
-
recordDecryption
public void recordDecryption(boolean success)
Records a decryption attempt.
-
getTotalLookups
public long getTotalLookups()
-
getCacheHits
public long getCacheHits()
-
getCacheMisses
public long getCacheMisses()
-
getDefaultValueUsed
public long getDefaultValueUsed()
-
getMissingRequiredKeys
public long getMissingRequiredKeys()
-
getDecryptionAttempts
public long getDecryptionAttempts()
-
getDecryptionFailures
public long getDecryptionFailures()
-
getCacheHitRate
public double getCacheHitRate()
-
getUptimeMs
public long getUptimeMs()
-
toJson
public String toJson()
Exports metrics as JSON string.
-
reset
public void reset()
Resets all metrics.
-
logSummary
public void logSummary()
Logs a summary of current metrics.
-
getLookupCount
public long getLookupCount(String key)
Gets the lookup count for a specific key.- Parameters:
key- the configuration key- Returns:
- the number of times this key was looked up
-
getSourceLookupCount
public long getSourceLookupCount(String sourceName)
Gets the lookup count for a specific source.- Parameters:
sourceName- the source name- Returns:
- the number of times this source was queried
-
-