diff --git a/core/java/src/net/i2p/stat/StatManager.java b/core/java/src/net/i2p/stat/StatManager.java index cfba4ecc5..ffbbc7e0a 100644 --- a/core/java/src/net/i2p/stat/StatManager.java +++ b/core/java/src/net/i2p/stat/StatManager.java @@ -12,6 +12,7 @@ import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import net.i2p.I2PAppContext; +import net.i2p.stat.prometheus.PromStat; import net.i2p.util.Log; /** @@ -25,6 +26,12 @@ public class StatManager { private final I2PAppContext _context; private final Log _log; + /** + * stat name to PromStat + * @since 0.9.67 + */ + private final ConcurrentHashMap _promStats; + /** stat name to FrequencyStat */ private final ConcurrentHashMap _frequencyStats; /** stat name to RateStat */ @@ -57,6 +64,7 @@ public class StatManager { public StatManager(I2PAppContext context) { _context = context; _log = context.logManager().getLog(getClass()); + _promStats = new ConcurrentHashMap(32); _frequencyStats = new ConcurrentHashMap(8); _rateStats = new ConcurrentHashMap(128); String filter = getStatFilter(); @@ -66,6 +74,7 @@ public class StatManager { /** @since 0.8.8 */ public synchronized void shutdown() { + _promStats.clear(); _frequencyStats.clear(); _rateStats.clear(); } @@ -236,6 +245,70 @@ public class StatManager { return _frequencyStats.containsKey(statName); } + ///// begin PromStats ///// + + /** + * Is the given stat a PromStat? + * @since 0.9.67 + */ + public boolean isPromStat(String statName) { + return _promStats.containsKey(statName); + } + + /** + * Create a PromStat. + * The stat is ONLY created if the stat.full property is true or we are not in the router context. + * + * @param name unique name of the statistic + * @param description simple description of the statistic + * @param group used to group statistics together + * @since 0.9.67 + */ + public void createPromStat(PromStat ps) { + if (ignoreStat(ps.getName())) + return; + createRequiredPromStat(ps); + } + + /** + * Create a PromStat. + * The stat is always created, independent of the stat.full setting or context. + * + * @param name unique name of the statistic + * @param description simple description of the statistic + * @param group used to group statistics together + * @since 0.9.67 + */ + public void createRequiredPromStat(PromStat ps) { + _promStats.putIfAbsent(ps.getName(), ps); + } + + /** + * Remove a PromStat. + * @since 0.9.67 + */ + public void removePromStat(PromStat ps) { + removePromStat(ps.getName()); + } + + /** + * Remove a PromStat. + * @since 0.9.67 + */ + public void removePromStat(String name) { + _promStats.remove(name); + } + + /** + * Get a PromStat. + * @since 0.9.67 + */ + public PromStat getPromStat(String name) { + return _promStats.get(name); + } + + ///// end PromStats ///// + /** * Group name (untranslated String) to a SortedSet of untranslated stat names. * Map is unsorted.