Add logging, so that we can distinguish INFOs from WARNINGs.

This commit is contained in:
Karsten Loesing 2010-02-02 18:18:14 +01:00
parent c3c1231bf9
commit 6dba3aeb87
15 changed files with 201 additions and 135 deletions

3
.gitignore vendored
View File

@ -11,3 +11,6 @@ stats/
# generated graphs
website/graphs/*.png
# logfiles
log.*

View File

@ -1,3 +1,3 @@
#!/bin/sh
java -cp bin/:lib/commons-codec-1.4.jar Main download
java -cp bin/:lib/commons-codec-1.4.jar:lib/commons-compress-1.0.jar -Djava.util.logging.config.file=logging.properties Main download

View File

@ -1,3 +1,3 @@
#!/bin/sh
java -cp bin/:lib/commons-codec-1.4.jar:lib/commons-compress-1.0.jar Main import
java -cp bin/:lib/commons-codec-1.4.jar:lib/commons-compress-1.0.jar -Djava.util.logging.config.file=logging.properties Main import

10
logging.properties Normal file
View File

@ -0,0 +1,10 @@
handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler
.level=FINEST
java.util.logging.ConsoleHandler.level=WARNING
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.level=ALL
java.util.logging.FileHandler.pattern=log
java.util.logging.FileHandler.limit=5000000
java.util.logging.FileHandler.count=5
java.util.logging.FileHandler.append=true
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter

View File

@ -1,5 +1,6 @@
import java.io.*;
import java.util.*;
import java.util.logging.*;
/**
* Read in all files in a given directory and pass buffered readers of
@ -7,14 +8,15 @@ import java.util.*;
*/
public class ArchiveReader {
public ArchiveReader(RelayDescriptorParser rdp, String archivesDir) {
Logger logger = Logger.getLogger(ArchiveReader.class.getName());
if (new File(archivesDir).exists()) {
try {
rdp.initialize();
} catch (IOException e) {
return;
}
System.out.print("Importing files in directory " + archivesDir
+ "/... ");
logger.info("Importing files in directory " + archivesDir
+ "/...");
Stack<File> filesInInputDir = new Stack<File>();
filesInInputDir.add(new File(archivesDir));
List<File> problems = new ArrayList<File>();
@ -38,14 +40,16 @@ public class ArchiveReader {
}
}
if (problems.isEmpty()) {
System.out.println("done");
logger.info("Finished importing files in directory " + archivesDir
+ "/.");
} else {
System.out.println("failed");
StringBuilder sb = new StringBuilder("Failed importing files in "
+ "directory " + archivesDir + "/:");
int printed = 0;
for (File f : problems) {
System.out.println(" " + f.getAbsolutePath());
sb.append("\n " + f.getAbsolutePath());
if (++printed >= 3) {
System.out.println(" ... more");
sb.append("\n ... more");
break;
}
}

View File

@ -1,17 +1,21 @@
import java.io.*;
import java.text.*;
import java.util.*;
import java.util.logging.*;
import org.apache.commons.codec.digest.*;
public class BridgeDescriptorParser {
private ConsensusStatsFileHandler csfh;
private BridgeStatsFileHandler bsfh;
SortedSet<String> countries;
private SortedSet<String> countries;
private Logger logger;
public BridgeDescriptorParser(ConsensusStatsFileHandler csfh,
BridgeStatsFileHandler bsfh, SortedSet<String> countries) {
this.csfh = csfh;
this.bsfh = bsfh;
this.countries = countries;
this.logger =
Logger.getLogger(BridgeDescriptorParser.class.getName());
}
public void initialize() throws IOException {
this.csfh.initialize();
@ -47,7 +51,7 @@ public class BridgeDescriptorParser {
&& line.split(" ").length > 1) {
if (publishedLine == null ||
geoipStartTimeLine == null) {
System.out.println("Either published line or "
this.logger.warning("Either published line or "
+ "geoip-start-time line is not present in "
+ (sanitized ? "sanitized" : "non-sanitized")
+ " bridge descriptors from " + dateTime + ".");

View File

@ -1,6 +1,7 @@
import java.io.*;
import java.text.*;
import java.util.*;
import java.util.logging.*;
import org.apache.commons.compress.compressors.gzip.*;
import org.apache.commons.compress.archivers.tar.*;
@ -11,6 +12,8 @@ public class BridgeSnapshotReader {
public BridgeSnapshotReader(BridgeDescriptorParser bdp,
String bridgeDirectoriesDir, String statsDirectory,
Set<String> countries) {
Logger logger =
Logger.getLogger(BridgeSnapshotReader.class.getName());
SortedSet<String> parsed = new TreeSet<String>();
File bdDir = new File(bridgeDirectoriesDir);
File pbdFile = new File(statsDirectory
@ -18,8 +21,8 @@ public class BridgeSnapshotReader {
boolean modified = false;
if (bdDir.exists()) {
if (pbdFile.exists()) {
System.out.print("Reading file " + statsDirectory
+ "/parsed-bridge-directories... ");
logger.info("Reading file " + statsDirectory
+ "/parsed-bridge-directories...");
try {
BufferedReader br = new BufferedReader(new FileReader(pbdFile));
String line = null;
@ -27,9 +30,11 @@ public class BridgeSnapshotReader {
parsed.add(line);
}
br.close();
System.out.println("done");
logger.info("Finished reading file " + statsDirectory
+ "/parsed-bridge-directories.");
} catch (IOException e) {
System.out.println("failed");
logger.log(Level.WARNING, "Failed reading file "
+ statsDirectory + "/parsed-bridge-directories!", e);
return;
}
}
@ -38,8 +43,8 @@ public class BridgeSnapshotReader {
} catch (IOException e) {
return;
}
System.out.print("Importing files in directory "
+ bridgeDirectoriesDir + "/... ");
logger.info("Importing files in directory " + bridgeDirectoriesDir
+ "/...");
Stack<File> filesInInputDir = new Stack<File>();
filesInInputDir.add(bdDir);
List<File> problems = new ArrayList<File>();
@ -84,20 +89,23 @@ public class BridgeSnapshotReader {
}
}
if (problems.isEmpty()) {
System.out.println("done");
logger.info("Finished importing files in directory "
+ bridgeDirectoriesDir + "/.");
} else {
System.out.println("failed");
StringBuilder sb = new StringBuilder("Failed importing files in "
+ "directory " + bridgeDirectoriesDir + "/:");
int printed = 0;
for (File f : problems) {
System.out.println(" " + f.getAbsolutePath());
sb.append("\n " + f.getAbsolutePath());
if (++printed >= 3) {
System.out.println(" ... more");
sb.append("\n ... more");
break;
}
}
logger.warning(sb.toString());
}
if (!parsed.isEmpty() && modified) {
System.out.print("Writing file " + pbdFile + "... ");
logger.info("Writing file " + pbdFile + "...");
try {
new File(statsDirectory).mkdirs();
BufferedWriter bw = new BufferedWriter(new FileWriter(pbdFile));
@ -105,9 +113,10 @@ public class BridgeSnapshotReader {
bw.append(f + "\n");
}
bw.close();
System.out.println("done");
logger.info("Finished writing file " + pbdFile + ".");
} catch (IOException e) {
System.out.println("failed");
logger.log(Level.WARNING, "Failed writing file "
+ pbdFile + "!", e);
}
}
}

View File

@ -1,5 +1,6 @@
import java.io.*;
import java.util.*;
import java.util.logging.*;
/**
*
@ -14,6 +15,7 @@ public class BridgeStatsFileHandler {
private SortedMap<String, String> observations;
private boolean initialized;
private boolean modified;
private Logger logger;
public BridgeStatsFileHandler(String statsDir,
SortedSet<String> countries) {
this.statsDir = statsDir;
@ -23,6 +25,8 @@ public class BridgeStatsFileHandler {
this.observations = new TreeMap<String, String>();
this.hashedRelayIdentitiesFile = new File(statsDir
+ "/hashed-relay-identities");
this.logger =
Logger.getLogger(BridgeStatsFileHandler.class.getName());
}
public void initialize() throws IOException {
if (this.initialized) {
@ -30,8 +34,8 @@ public class BridgeStatsFileHandler {
}
this.initialized = true;
if (this.bridgeStatsFile.exists()) {
System.out.print("Reading file " + statsDir
+ "/bridge-stats-raw... ");
this.logger.info("Reading file " + statsDir
+ "/bridge-stats-raw...");
BufferedReader br = new BufferedReader(new FileReader(
this.bridgeStatsFile));
String line = br.readLine();
@ -52,12 +56,13 @@ public class BridgeStatsFileHandler {
this.addObs(hashedBridgeIdentity, date, time, obs);
}
}
System.out.println("done");
this.logger.info("Finished reading file " + statsDir
+ "/bridge-stats-raw.");
br.close();
}
if (this.hashedRelayIdentitiesFile.exists()) {
System.out.print("Reading file " + statsDir
+ "/hashed-relay-identities... ");
this.logger.info("Reading file " + statsDir
+ "/hashed-relay-identities...");
BufferedReader br = new BufferedReader(new FileReader(
this.hashedRelayIdentitiesFile));
String line = null;
@ -65,7 +70,8 @@ public class BridgeStatsFileHandler {
this.hashedRelays.add(line);
}
br.close();
System.out.println("done");
this.logger.info("Finished reading file " + statsDir
+ "/hashed-relay-identities.");
}
}
public void addHashedRelay(String hashedRelayIdentity)
@ -107,8 +113,8 @@ public class BridgeStatsFileHandler {
}
try {
if (!this.hashedRelays.isEmpty()) {
System.out.print("Writing file " + this.statsDir
+ "/hashed-relay-identities... ");
this.logger.info("Writing file " + this.statsDir
+ "/hashed-relay-identities...");
new File(this.statsDir).mkdirs();
BufferedWriter bwRelayIdentities = new BufferedWriter(
new FileWriter(this.hashedRelayIdentitiesFile));
@ -116,11 +122,12 @@ public class BridgeStatsFileHandler {
bwRelayIdentities.append(hashedRelay + "\n");
}
bwRelayIdentities.close();
System.out.println("done");
this.logger.info("Finished writing file " + this.statsDir
+ "/hashed-relay-identities.");
}
if (!this.observations.isEmpty()) {
System.out.print("Writing file " + this.statsDir
+ "/bridge-stats-raw... ");
this.logger.info("Writing file " + this.statsDir
+ "/bridge-stats-raw...");
new File(this.statsDir).mkdirs();
BufferedWriter bwBridgeStats = new BufferedWriter(
new FileWriter(this.bridgeStatsFile));
@ -150,8 +157,10 @@ public class BridgeStatsFileHandler {
}
}
bwBridgeStats.close();
System.out.print("done\nWriting file " + this.statsDir
+ "/bridge-stats... ");
this.logger.info("Finished writing file " + this.statsDir
+ "/bridge-stats-raw.");
this.logger.info("Writing file " + this.statsDir
+ "/bridge-stats...");
BufferedWriter bwBridgeStatsDate = new BufferedWriter(
new FileWriter(this.bridgeStatsDateFile));
bwBridgeStatsDate.append("date");
@ -174,15 +183,19 @@ public class BridgeStatsFileHandler {
}
bwBridgeStatsDate.append(date);
for (int i = 0; i < sums.length; i++) {
bwBridgeStatsDate.append("," + String.format("%.2f", sums[i]));
bwBridgeStatsDate.append(","
+ String.format("%.2f", sums[i]));
}
bwBridgeStatsDate.append("\n");
}
bwBridgeStatsDate.close();
System.out.println("done");
this.logger.info("Finished writing file " + this.statsDir
+ "/bridge-stats.");
}
} catch (IOException e) {
System.out.println("failed");
this.logger.log(Level.WARNING, "Failed writing " + this.statsDir
+ "/{hashed-relay-identities|bridge-stats-raw|bridge-stats}!",
e);
}
}
}

View File

@ -1,6 +1,7 @@
import java.io.*;
import java.text.*;
import java.util.*;
import java.util.logging.*;
/**
*
@ -18,6 +19,7 @@ public class ConsensusStatsFileHandler {
new TreeMap<String, String>();
private boolean initialized;
private boolean modified;
private Logger logger;
public ConsensusStatsFileHandler(String statsDir) {
this.statsDir = statsDir;
this.consensusResults = new TreeMap<String, String>();
@ -27,6 +29,8 @@ public class ConsensusStatsFileHandler {
this.bridgeConsensusStatsRawFile = new File(statsDir
+ "/bridge-consensus-stats-raw");
this.consensusStatsFile = new File(statsDir + "/consensus-stats");
this.logger =
Logger.getLogger(ConsensusStatsFileHandler.class.getName());
}
public void initialize() throws IOException {
if (this.initialized) {
@ -34,32 +38,34 @@ public class ConsensusStatsFileHandler {
}
this.initialized = true;
if (this.consensusStatsRawFile.exists()) {
System.out.print("Reading file " + statsDir
+ "/consensus-stats-raw... ");
this.logger.info("Reading file " + statsDir
+ "/consensus-stats-raw...");
BufferedReader br = new BufferedReader(new FileReader(
this.consensusStatsRawFile));
String line = null;
while ((line = br.readLine()) != null) {
consensusResults.put(line.split(",")[0], line);
}
System.out.println("done");
br.close();
this.logger.info("Finished reading file " + statsDir
+ "/consensus-stats-raw.");
}
if (this.bridgeConsensusStatsRawFile.exists()) {
System.out.print("Reading file " + statsDir
+ "/bridge-consensus-stats-raw... ");
this.logger.info("Reading file " + statsDir
+ "/bridge-consensus-stats-raw...");
BufferedReader br = new BufferedReader(new FileReader(
this.bridgeConsensusStatsRawFile));
String line = null;
while ((line = br.readLine()) != null) {
bridgeConsensusResults.put(line.split(",")[0], line);
}
System.out.println("done");
br.close();
this.logger.info("Finished reading file " + statsDir
+ "/bridge-consensus-stats-raw.");
}
if (this.consensusStatsFile.exists()) {
System.out.print("Reading file " + statsDir
+ "/consensus-stats... ");
this.logger.info("Reading file " + statsDir
+ "/consensus-stats...");
BufferedReader br = new BufferedReader(new FileReader(
this.consensusStatsFile));
String line = br.readLine();
@ -81,7 +87,8 @@ public class ConsensusStatsFileHandler {
}
}
br.close();
System.out.println("done");
this.logger.info("Finished reading file " + statsDir
+ "/consensus-stats.");
}
}
public void addConsensusResults(String validAfter, int exit, int fast,
@ -106,8 +113,8 @@ public class ConsensusStatsFileHandler {
return;
}
if (!consensusResults.isEmpty()) {
System.out.print("Writing file " + this.statsDir
+ "/consensus-stats-raw... ");
this.logger.info("Writing file " + this.statsDir
+ "/consensus-stats-raw...");
try {
new File(this.statsDir).mkdirs();
BufferedWriter bwConsensusStatsRaw = new BufferedWriter(
@ -153,9 +160,11 @@ public class ConsensusStatsFileHandler {
}
}
bwConsensusStatsRaw.close();
System.out.println("done");
this.logger.info("Finished writing file " + this.statsDir
+ "/consensus-stats-raw.");
} catch (IOException e) {
System.out.println("failed");
this.logger.log(Level.WARNING, "Failed writing file "
+ this.statsDir + "/consensus-stats-raw!", e);
}
if (!bridgeConsensusResults.isEmpty()) {
String tempDate = null;
@ -183,8 +192,8 @@ public class ConsensusStatsFileHandler {
brunningDay += Integer.parseInt(next.split(",")[1]);
}
}
System.out.print("Writing file " + this.statsDir
+ "/bridge-consensus-stats-raw... ");
this.logger.info("Writing file " + this.statsDir
+ "/bridge-consensus-stats-raw...");
try {
new File(this.statsDir).mkdirs();
BufferedWriter bwBridgeConsensusStatsRaw = new BufferedWriter(
@ -193,14 +202,16 @@ public class ConsensusStatsFileHandler {
bwBridgeConsensusStatsRaw.append(line + "\n");
}
bwBridgeConsensusStatsRaw.close();
System.out.println("done");
this.logger.info("Finished writing file " + this.statsDir
+ "/bridge-consensus-stats-raw.");
} catch (IOException e) {
System.out.println("failed");
this.logger.log(Level.WARNING, "Failed writing file "
+ this.statsDir + "/bridge-consensus-stats-raw!", e);
}
}
if (!this.csAggr.isEmpty() || !this.bcsAggr.isEmpty()) {
System.out.print("Writing file " + this.statsDir
+ "/consensus-stats... ");
this.logger.info("Writing file " + this.statsDir
+ "/consensus-stats...");
try {
new File(this.statsDir).mkdirs();
BufferedWriter bwConsensusStats = new BufferedWriter(
@ -231,11 +242,14 @@ public class ConsensusStatsFileHandler {
currentDate += 86400000L;
}
bwConsensusStats.close();
System.out.println("done");
this.logger.info("Finished writing file " + this.statsDir
+ "/consensus-stats.");
} catch (IOException e) {
System.out.println("failed");
this.logger.log(Level.WARNING, "Failed writing file "
+ this.statsDir + "/consensus-stats!", e);
} catch (ParseException e) {
System.out.println("failed");
this.logger.log(Level.WARNING, "Failed writing file "
+ this.statsDir + "/consensus-stats!", e);
}
}
}

View File

@ -1,5 +1,6 @@
import java.io.*;
import java.util.*;
import java.util.logging.*;
import java.text.*;
/**
@ -12,12 +13,15 @@ public class DirreqStatsFileHandler {
private SortedMap<String, String> observations;
private boolean initialized;
private boolean modified;
private Logger logger;
public DirreqStatsFileHandler(String statsDir,
SortedSet<String> countries) {
this.statsDir = statsDir;
this.countries = countries;
this.dirreqStatsFile = new File(statsDir + "/dirreq-stats");
this.observations = new TreeMap<String, String>();
this.logger =
Logger.getLogger(DirreqStatsFileHandler.class.getName());
}
public void initialize() throws IOException {
if (this.initialized) {
@ -25,7 +29,7 @@ public class DirreqStatsFileHandler {
}
this.initialized = true;
if (this.dirreqStatsFile.exists()) {
System.out.print("Reading file " + statsDir + "/dirreq-stats... ");
this.logger.info("Reading file " + statsDir + "/dirreq-stats...");
BufferedReader br = new BufferedReader(new FileReader(
this.dirreqStatsFile));
String line = br.readLine();
@ -48,8 +52,9 @@ public class DirreqStatsFileHandler {
}
}
}
System.out.println("done");
br.close();
this.logger.info("Finished reading file " + statsDir
+ "/dirreq-stats...");
}
}
public void addObs(String dirNickname, String date,
@ -72,8 +77,8 @@ public class DirreqStatsFileHandler {
}
try {
if (!this.observations.isEmpty()) {
System.out.print("Writing file " + this.statsDir
+ "/dirreq-stats... ");
this.logger.info("Writing file " + this.statsDir
+ "/dirreq-stats...");
new File(this.statsDir).mkdirs();
BufferedWriter bwDirreqStats = new BufferedWriter(
new FileWriter(this.dirreqStatsFile));
@ -105,12 +110,15 @@ public class DirreqStatsFileHandler {
bwDirreqStats.append(observation + "\n");
}
bwDirreqStats.close();
System.out.println("done");
this.logger.info("Finished writing file " + this.statsDir
+ "/dirreq-stats.");
}
} catch (IOException e) {
System.out.println("failed");
this.logger.log(Level.WARNING, "Failed writing file "
+ this.statsDir + "/dirreq-stats!", e);
} catch (ParseException e) {
System.out.println("failed");
this.logger.log(Level.WARNING, "Failed writing file "
+ this.statsDir + "/dirreq-stats!", e);
}
}
}

View File

@ -1,14 +1,18 @@
import java.io.*;
import java.util.logging.*;
public class LockFile {
private File lockFile;
private Logger logger;
public LockFile() {
this.lockFile = new File("lock");
this.logger = Logger.getLogger(LockFile.class.getName());
}
public boolean acquireLock() {
this.logger.info("Trying to acquire lock...");
try {
if (this.lockFile.exists()) {
BufferedReader br = new BufferedReader(new FileReader("lock"));
@ -21,14 +25,19 @@ public class LockFile {
BufferedWriter bw = new BufferedWriter(new FileWriter("lock"));
bw.append("" + System.currentTimeMillis() + "\n");
bw.close();
this.logger.info("Acquired lock.");
return true;
} catch (IOException e) {
this.logger.warning("Caught exception while trying to acquire "
+ "lock!");
return false;
}
}
public void releaseLock() {
this.logger.info("Releasing lock...");
this.lockFile.delete();
this.logger.info("Released lock.");
}
}

View File

@ -1,6 +1,7 @@
import java.io.*;
import java.text.*;
import java.util.*;
import java.util.logging.*;
/**
* Coordinate downloading and parsing of descriptors and extraction of
@ -9,11 +10,14 @@ import java.util.*;
public class Main {
public static void main(String[] args) {
Logger logger = Logger.getLogger(Main.class.getName());
logger.info("Starting ERNIE...");
// Use lock file to avoid overlapping runs
LockFile lf = new LockFile();
if (!lf.acquireLock()) {
System.out.println("Warning: ERNIE is already running or has not "
+ "exited cleanly! Exiting.");
logger.severe("Warning: ERNIE is already running or has not exited "
+ "cleanly! Exiting!");
System.exit(1);
}
@ -24,7 +28,7 @@ public class Main {
&& args[0].equals("download");
// Define which stats we are interested in
String authority = "86.59.21.38";
String authority = "194.109.206.212";
SortedSet<String> countries = new TreeSet<String>();
countries.add("bh");
countries.add("cn");
@ -63,6 +67,7 @@ public class Main {
// Read files in archives/ and bridges/ directory
if (!downloadOnly) {
logger.info("Importing data...");
ArchiveReader ar = new ArchiveReader(rdp, "archives");
SanitizedBridgesReader sbr = new SanitizedBridgesReader(bdp,
"bridges", countries);
@ -70,12 +75,15 @@ public class Main {
"bridge-directories", statsDirectory, countries);
TorperfProcessor tp = new TorperfProcessor(statsDirectory,
"torperf");
logger.info("Finished importing data.");
}
// Download current descriptors
if (!importOnly) {
logger.info("Downloading descriptors...");
RelayDescriptorDownloader rdd = new RelayDescriptorDownloader(rdp,
authority, directories);
logger.info("Finished downloading descriptors.");
}
// Write updated stats files to disk
@ -85,6 +93,8 @@ public class Main {
// Remove lock file
lf.releaseLock();
logger.info("Terminating ERNIE.");
}
}

View File

@ -1,6 +1,7 @@
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.logging.*;
/**
* Download the current consensus and relevant extra-info descriptors and
@ -9,14 +10,16 @@ import java.util.*;
public class RelayDescriptorDownloader {
public RelayDescriptorDownloader(RelayDescriptorParser rdp,
String authority, SortedMap<String, String> directories) {
Logger logger =
Logger.getLogger(RelayDescriptorDownloader.class.getName());
try {
rdp.initialize();
} catch (IOException e) {
return;
}
try {
System.out.print("Downloading current consensus from " + authority
+ "... ");
logger.info("Downloading current consensus from " + authority
+ "...");
URL u = new URL("http://" + authority
+ "/tor/status-vote/current/consensus");
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
@ -36,8 +39,10 @@ public class RelayDescriptorDownloader {
String consensus = sb.toString();
rdp.parse(new BufferedReader(new StringReader(consensus)));
}
System.out.print("done\nDownloading extra-info descriptors from "
+ authority + "... ");
logger.info("Finished downloading current consensus from "
+ authority + ".");
logger.info("Downloading extra-info descriptors from " + authority
+ "...");
Stack<String> extraInfos = new Stack<String>();
for (String fingerprint : directories.keySet()) {
u = new URL("http://" + authority + "/tor/extra/fp/"
@ -64,9 +69,12 @@ public class RelayDescriptorDownloader {
}
}
}
System.out.println("done");
logger.info("Finished downloading extra-info descriptors from "
+ authority + ".");
} catch (IOException e) {
System.out.println("failed");
logger.log(Level.WARNING, "Failed downloading either current "
+ "consensus or extra-info descriptors from " + authority
+ "!", e);
}
}
}

View File

@ -1,19 +1,21 @@
import java.io.*;
import java.text.*;
import java.util.*;
import java.util.logging.*;
import org.apache.commons.codec.digest.*;
public class SanitizedBridgesReader {
public SanitizedBridgesReader(BridgeDescriptorParser bdp,
String bridgesDir, SortedSet<String> countries) {
Logger logger =
Logger.getLogger(SanitizedBridgesReader.class.getName());
if (new File(bridgesDir).exists()) {
try {
bdp.initialize();
} catch (IOException e) {
return;
}
System.out.print("Importing files in directory " + bridgesDir
+ "/... ");
logger.info("Importing files in directory " + bridgesDir + "/...");
Stack<File> filesInInputDir = new Stack<File>();
filesInInputDir.add(new File(bridgesDir));
List<File> problems = new ArrayList<File>();
@ -47,17 +49,20 @@ public class SanitizedBridgesReader {
}
}
if (problems.isEmpty()) {
System.out.println("done");
logger.info("Finished importing files in directory " + bridgesDir
+ "/.");
} else {
System.out.println("failed");
StringBuilder sb = new StringBuilder("Failed importing files in "
+ "directory " + bridgesDir + "/:");
int printed = 0;
for (File f : problems) {
System.out.println(" " + f.getAbsolutePath());
sb.append("\n " + f.getAbsolutePath());
if (++printed >= 3) {
System.out.println(" ... more");
sb.append("\n ... more");
break;
}
}
logger.warning(sb.toString());
}
}
}

View File

@ -1,10 +1,12 @@
import java.io.*;
import java.text.*;
import java.util.*;
import java.util.logging.*;
public class TorperfProcessor {
public TorperfProcessor(String statsDirectory,
String torperfDirectory) {
Logger logger = Logger.getLogger(TorperfProcessor.class.getName());
File rawFile = new File(statsDirectory + "/torperf-raw");
File statsFile = new File(statsDirectory + "/torperf-stats");
File torperfDir = new File(torperfDirectory);
@ -12,8 +14,7 @@ public class TorperfProcessor {
SortedMap<String, String> stats = new TreeMap<String, String>();
try {
if (rawFile.exists()) {
System.out.print("Reading file " + statsDirectory
+ "/torperf-raw... ");
logger.info("Reading file " + statsDirectory + "/torperf-raw...");
BufferedReader br = new BufferedReader(new FileReader(rawFile));
String line = br.readLine(); // ignore header
while ((line = br.readLine()) != null) {
@ -21,11 +22,12 @@ public class TorperfProcessor {
rawObs.put(key, line);
}
br.close();
System.out.println("done");
logger.info("Finished reading file " + statsDirectory
+ "/torperf-raw.");
}
if (statsFile.exists()) {
System.out.print("Reading file " + statsDirectory
+ "/torperf-stats... ");
logger.info("Reading file " + statsDirectory
+ "/torperf-stats...");
BufferedReader br = new BufferedReader(new FileReader(statsFile));
String line = br.readLine(); // ignore header
while ((line = br.readLine()) != null) {
@ -33,11 +35,11 @@ public class TorperfProcessor {
stats.put(key, line);
}
br.close();
System.out.println("done");
logger.info("Finished reading file " + statsDirectory
+ "/torperf-stats.");
}
if (torperfDir.exists()) {
System.out.print("Importing files in " + torperfDirectory
+ "/... ");
logger.info("Importing files in " + torperfDirectory + "/...");
Stack<File> filesInInputDir = new Stack<File>();
filesInInputDir.add(torperfDir);
while (!filesInInputDir.isEmpty()) {
@ -78,11 +80,11 @@ public class TorperfProcessor {
br.close();
}
}
System.out.println("done");
logger.info("Finished importing files in " + torperfDirectory
+ "/.");
}
if (rawObs.size() > 0) {
System.out.print("Writing file " + statsDirectory
+ "/torperf-raw... ");
logger.info("Writing file " + statsDirectory + "/torperf-raw...");
new File(statsDirectory).mkdirs();
BufferedWriter bw = new BufferedWriter(new FileWriter(rawFile));
bw.append("source,date,start,completemillis\n");
@ -117,11 +119,12 @@ public class TorperfProcessor {
}
}
bw.close();
System.out.println("done");
logger.info("Finished writing file " + statsDirectory
+ "/torperf-raw.");
}
if (stats.size() > 0) {
System.out.print("Writing file " + statsDirectory
+ "/torperf-stats... ");
logger.info("Writing file " + statsDirectory
+ "/torperf-stats...");
new File(statsDirectory).mkdirs();
BufferedWriter bw = new BufferedWriter(new FileWriter(statsFile));
bw.append("source,date,q1,md,q3\n");
@ -130,47 +133,13 @@ public class TorperfProcessor {
bw.append(s + "\n");
}
bw.close();
System.out.println("done");
logger.info("Finished writing file " + statsDirectory
+ "/torperf-stats.");
}
} catch (IOException e) {
System.out.println("failed");
logger.log(Level.WARNING, "Failed writing " + statsDirectory
+ "/torperf-{raw|stats}!", e);
}
}
}
/*
File tsFile = new File(torperfStatsFile);
List<String> sizeStr = new ArrayList<String>();
sizeStr.add("5mb");
sizeStr.add("1mb");
sizeStr.add("50kb");
for (String size : sizeStr) {
SortedMap<String, File> inFiles = new TreeMap<String, File>();
inFiles.put("gabelmoo", new File("gabelmoo-" + size + ".data"));
inFiles.put("moria", new File("moria-" + size + ".data"));
inFiles.put("torperf", new File("torperf-" + size + ".data"));
File out = new File(size + ".out");
BufferedWriter bw = new BufferedWriter(new FileWriter(out));
bw.append("date,complete,source\n");
Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (Map.Entry<String, File> e : inFiles.entrySet()) {
BufferedReader br = new BufferedReader(new FileReader(
e.getValue()));
String line = null;
while ((line = br.readLine()) != null) {
String[] parts = line.split(" ");
Date date = new Date(Long.parseLong(parts[0]) * 1000L);
long start = Long.parseLong(parts[0]);
long complete = Long.parseLong(parts[16]);
if (complete - start >= 0) {
String s = formatter.format(date);
bw.append(s + "," + (complete - start) + "," + e.getKey()
+ "\n");
}
}
br.close();
}
bw.close();
}
*/