forked from I2P_Developers/i2p.i2p
StatManager cleanup and synch
BuildTime update Make clock.skew stat non-required
This commit is contained in:
@ -30,6 +30,11 @@ public class StatManager {
|
|||||||
/** may be null */
|
/** may be null */
|
||||||
private StatLog _statLog;
|
private StatLog _statLog;
|
||||||
|
|
||||||
|
private int coalesceCounter;
|
||||||
|
/** every this many minutes for frequencies */
|
||||||
|
private static final int FREQ_COALESCE_RATE = 9;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comma-separated stats or * for all.
|
* Comma-separated stats or * for all.
|
||||||
* This property must be set at startup, or
|
* This property must be set at startup, or
|
||||||
@ -47,7 +52,7 @@ public class StatManager {
|
|||||||
* appropriate application context itself.
|
* appropriate application context itself.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public StatManager(I2PAppContext context) {
|
public StatManager(I2PAppContext context) {
|
||||||
_context = context;
|
_context = context;
|
||||||
_frequencyStats = new ConcurrentHashMap<String,FrequencyStat>(8);
|
_frequencyStats = new ConcurrentHashMap<String,FrequencyStat>(8);
|
||||||
_rateStats = new ConcurrentHashMap<String,RateStat>(128);
|
_rateStats = new ConcurrentHashMap<String,RateStat>(128);
|
||||||
@ -57,18 +62,29 @@ public class StatManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @since 0.8.8 */
|
/** @since 0.8.8 */
|
||||||
public void shutdown() {
|
public synchronized void shutdown() {
|
||||||
_frequencyStats.clear();
|
_frequencyStats.clear();
|
||||||
_rateStats.clear();
|
_rateStats.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** may be null */
|
/**
|
||||||
public StatLog getStatLog() { return _statLog; }
|
* Gets the default stat log for RateStats
|
||||||
public void setStatLog(StatLog log) {
|
* Deprecated, unused
|
||||||
|
* @return null always
|
||||||
|
*/
|
||||||
|
public synchronized StatLog getStatLog() { return _statLog; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the default stat log for ALL known RateStats.
|
||||||
|
* Deprecated, unused
|
||||||
|
* @deprecated unused
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public synchronized void setStatLog(StatLog log) {
|
||||||
_statLog = log;
|
_statLog = log;
|
||||||
for (RateStat rs : _rateStats.values()) {
|
for (RateStat rs : _rateStats.values()) {
|
||||||
rs.setStatLog(log);
|
rs.setStatLog(log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -158,11 +174,7 @@ public class StatManager {
|
|||||||
if (stat != null) stat.addData(data);
|
if (stat != null) stat.addData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int coalesceCounter;
|
public synchronized void coalesceStats() {
|
||||||
/** every this many minutes for frequencies */
|
|
||||||
private static final int FREQ_COALESCE_RATE = 9;
|
|
||||||
|
|
||||||
public void coalesceStats() {
|
|
||||||
if (++coalesceCounter % FREQ_COALESCE_RATE == 0) {
|
if (++coalesceCounter % FREQ_COALESCE_RATE == 0) {
|
||||||
for (FrequencyStat stat : _frequencyStats.values()) {
|
for (FrequencyStat stat : _frequencyStats.values()) {
|
||||||
if (stat != null) {
|
if (stat != null) {
|
||||||
@ -170,15 +182,13 @@ public class StatManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (RateStat stat : _rateStats.values()) {
|
for (RateStat stat : _rateStats.values()) {
|
||||||
if (stat != null) {
|
stat.coalesceStats();
|
||||||
stat.coalesceStats();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Misnamed, as it returns a FrequenceyStat, not a Frequency.
|
* Misnamed, as it returns a FrequencyStat, not a Frequency.
|
||||||
*/
|
*/
|
||||||
public FrequencyStat getFrequency(String name) {
|
public FrequencyStat getFrequency(String name) {
|
||||||
return _frequencyStats.get(name);
|
return _frequencyStats.get(name);
|
||||||
@ -191,10 +201,12 @@ public class StatManager {
|
|||||||
return _rateStats.get(name);
|
return _rateStats.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return a copy */
|
||||||
public Set<String> getFrequencyNames() {
|
public Set<String> getFrequencyNames() {
|
||||||
return new HashSet<String>(_frequencyStats.keySet());
|
return new HashSet<String>(_frequencyStats.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return a copy */
|
||||||
public Set<String> getRateNames() {
|
public Set<String> getRateNames() {
|
||||||
return new HashSet<String>(_rateStats.keySet());
|
return new HashSet<String>(_rateStats.keySet());
|
||||||
}
|
}
|
||||||
@ -258,9 +270,11 @@ public class StatManager {
|
|||||||
* @since 0.9.23
|
* @since 0.9.23
|
||||||
*/
|
*/
|
||||||
public void store(OutputStream out, String prefix) throws IOException {
|
public void store(OutputStream out, String prefix) throws IOException {
|
||||||
for (FrequencyStat fs : _frequencyStats.values())
|
for (FrequencyStat fs : _frequencyStats.values()) {
|
||||||
fs.store(out, prefix);
|
fs.store(out, prefix);
|
||||||
for (RateStat rs : _rateStats.values())
|
}
|
||||||
|
for (RateStat rs : _rateStats.values()) {
|
||||||
rs.store(out,prefix);
|
rs.store(out,prefix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,10 @@ public class BuildTime {
|
|||||||
private static final long _latestTime;
|
private static final long _latestTime;
|
||||||
private static final long YEARS_25 = 25L*365*24*60*60*1000;
|
private static final long YEARS_25 = 25L*365*24*60*60*1000;
|
||||||
/** update this periodically */
|
/** update this periodically */
|
||||||
private static final String EARLIEST = "2019-03-13 12:00:00 UTC";
|
private static final String EARLIEST = "2019-06-23 12:00:00 UTC";
|
||||||
// fallback if parse fails ticket #1976
|
// fallback if parse fails ticket #1976
|
||||||
// date -d 201x-xx-xx +%s
|
// date -d 201x-xx-xx +%s
|
||||||
private static final long EARLIEST_LONG = 1552449600 * 1000L;
|
private static final long EARLIEST_LONG = 1561262400 * 1000L;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// this is the standard format of build.timestamp as set in the top-level build.xml
|
// this is the standard format of build.timestamp as set in the top-level build.xml
|
||||||
|
@ -128,7 +128,7 @@ public class Clock implements Timestamper.UpdateListener {
|
|||||||
getLog().info("Updating clock offset to " + offsetMs + "ms from " + _offset + "ms");
|
getLog().info("Updating clock offset to " + offsetMs + "ms from " + _offset + "ms");
|
||||||
|
|
||||||
if (!_statCreated) {
|
if (!_statCreated) {
|
||||||
_context.statManager().createRequiredRateStat("clock.skew", "Clock step adjustment (ms)", "Clock", new long[] { 10*60*1000, 3*60*60*1000, 24*60*60*1000 });
|
_context.statManager().createRateStat("clock.skew", "Clock step adjustment (ms)", "Clock", new long[] { 60*60*1000 });
|
||||||
_statCreated = true;
|
_statCreated = true;
|
||||||
}
|
}
|
||||||
_context.statManager().addRateData("clock.skew", delta, 0);
|
_context.statManager().addRateData("clock.skew", delta, 0);
|
||||||
|
@ -189,7 +189,7 @@ public class RouterClock extends Clock {
|
|||||||
getLog().info("Updating target clock offset to " + offsetMs + "ms from " + _offset + "ms, Stratum " + stratum);
|
getLog().info("Updating target clock offset to " + offsetMs + "ms from " + _offset + "ms, Stratum " + stratum);
|
||||||
|
|
||||||
if (!_statCreated) {
|
if (!_statCreated) {
|
||||||
_context.statManager().createRequiredRateStat("clock.skew", "Clock step adjustment (ms)", "Clock", new long[] { 10*60*1000, 3*60*60*1000, 24*60*60*1000 });
|
_context.statManager().createRateStat("clock.skew", "Clock step adjustment (ms)", "Clock", new long[] { 60*60*1000 });
|
||||||
_statCreated = true;
|
_statCreated = true;
|
||||||
}
|
}
|
||||||
_context.statManager().addRateData("clock.skew", delta);
|
_context.statManager().addRateData("clock.skew", delta);
|
||||||
|
Reference in New Issue
Block a user