Class 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 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()
      • getKeyLookupCounts

        public Map<String,​Long> getKeyLookupCounts()
      • getSourceLookupCounts

        public Map<String,​Long> getSourceLookupCounts()
      • 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