I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 3f91e448 authored by zab2's avatar zab2
Browse files

Add serialization methods to StatManager, FrequencyStat and Frequency

for easier collection
parent b10b8581
No related branches found
No related tags found
No related merge requests found
...@@ -150,4 +150,16 @@ public class Frequency { ...@@ -150,4 +150,16 @@ public class Frequency {
private final static long now() { private final static long now() {
return System.currentTimeMillis(); return System.currentTimeMillis();
} }
/**
* Appends the data of this frequency to the specified StringBuilder
* @param dest to append data to
* @since 0.9.23
*/
synchronized void store(StringBuilder dest) {
dest.append("avgInterval:").append(_avgInterval).append(',');
dest.append("minAverageInterval").append(_minAverageInterval).append(',');
dest.append("lastEvent").append(_lastEvent).append(",");
dest.append("count").append(_count);
}
} }
package net.i2p.stat; package net.i2p.stat;
import java.io.IOException;
import java.io.OutputStream;
import net.i2p.data.DataHelper;
/** coordinate an event frequency over various periods */ /** coordinate an event frequency over various periods */
public class FrequencyStat { public class FrequencyStat {
/** unique name of the statistic */ /** unique name of the statistic */
...@@ -92,5 +97,34 @@ public class FrequencyStat { ...@@ -92,5 +97,34 @@ public class FrequencyStat {
if ((obj == null) || !(obj instanceof FrequencyStat)) return false; if ((obj == null) || !(obj instanceof FrequencyStat)) return false;
return _statName.equals(((FrequencyStat)obj)._statName); return _statName.equals(((FrequencyStat)obj)._statName);
} }
private final static String NL = System.getProperty("line.separator");
/**
* Serializes this FrequencyStat to the provided OutputStream
* @param out to write to
* @param prefix to prepend to the stat
* @throws IOException if something goes wrong
* @since 0.9.23
*/
public void store(OutputStream out, String prefix) throws IOException {
StringBuilder buf = new StringBuilder(1024);
buf.append(NL);
buf.append("################################################################################").append(NL);
buf.append("# Frequency: ").append(_groupName).append(": ").append(_statName).append(NL);
buf.append("# ").append(_description).append(NL);
buf.append("# ").append(NL).append(NL);
out.write(buf.toString().getBytes("UTF-8"));
buf.setLength(0);
for (Frequency r: _frequencies){
buf.append("#######").append(NL);
buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ")
.append(_groupName).append(" - ").append(_statName).append(NL);
buf.append(NL);
r.store(buf);
out.write(buf.toString().getBytes("UTF-8"));
buf.setLength(0);
}
}
} }
package net.i2p.stat; package net.i2p.stat;
import java.io.IOException;
import java.io.OutputStream;
import java.text.Collator; import java.text.Collator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
...@@ -247,4 +249,18 @@ public class StatManager { ...@@ -247,4 +249,18 @@ public class StatManager {
public boolean ignoreStat(String statName) { public boolean ignoreStat(String statName) {
return _context.isRouterContext() && !_context.getBooleanProperty(PROP_STAT_FULL); return _context.isRouterContext() && !_context.getBooleanProperty(PROP_STAT_FULL);
} }
/**
* Serializes all Frequencies and Rates to the provided OutputStream
* @param out to write to
* @param prefix to use when serializing
* @throws IOException if something goes wrong
* @since 0.9.23
*/
public void store(OutputStream out, String prefix) throws IOException {
for (FrequencyStat fs : _frequencyStats.values())
fs.store(out, prefix);
for (RateStat rs : _rateStats.values())
rs.store(out,prefix);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment