diff --git a/commons/src/main/java/org/archive/util/ArchiveUtils.java b/commons/src/main/java/org/archive/util/ArchiveUtils.java
index 91410cef..e4ab9b55 100644
--- a/commons/src/main/java/org/archive/util/ArchiveUtils.java
+++ b/commons/src/main/java/org/archive/util/ArchiveUtils.java
@@ -551,7 +551,7 @@ public class ArchiveUtils {
/**
* Convert milliseconds value to a human-readable duration
* @param time
- * @param toMs whether to print to the ms
+ * @param toMs ignored
* @return Human readable string version of passed time
*/
public static String formatMillisecondsToConventional(long time, boolean toMs) {
diff --git a/commons/src/main/java/org/archive/util/FileUtils.java b/commons/src/main/java/org/archive/util/FileUtils.java
index ba1a89f7..9fbc062d 100644
--- a/commons/src/main/java/org/archive/util/FileUtils.java
+++ b/commons/src/main/java/org/archive/util/FileUtils.java
@@ -698,4 +698,12 @@ public class FileUtils {
return dir;
}
+
+ public static File tryToCanonicalize(File file) {
+ try {
+ return file.getCanonicalFile();
+ } catch (IOException e) {
+ return file;
+ }
+ }
}
\ No newline at end of file
diff --git a/commons/src/main/java/org/archive/util/Reporter.java b/commons/src/main/java/org/archive/util/Reporter.java
index 27ea4aad..e5759162 100644
--- a/commons/src/main/java/org/archive/util/Reporter.java
+++ b/commons/src/main/java/org/archive/util/Reporter.java
@@ -21,6 +21,7 @@ package org.archive.util;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.Map;
public interface Reporter {
/**
@@ -38,6 +39,13 @@ public interface Reporter {
*/
public void singleLineReportTo(PrintWriter pw) throws IOException;
+
+ /**
+ * @return Same data that's in the single line report, as key-value pairs
+ */
+ public Map singleLineReportData();
+
+
/**
* Return a legend for the single-line summary report as a String.
*
diff --git a/engine/src/main/java/org/archive/crawler/framework/CrawlController.java b/engine/src/main/java/org/archive/crawler/framework/CrawlController.java
index e2709437..ebc50260 100644
--- a/engine/src/main/java/org/archive/crawler/framework/CrawlController.java
+++ b/engine/src/main/java/org/archive/crawler/framework/CrawlController.java
@@ -25,6 +25,7 @@ import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.LinkedList;
+import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -311,7 +312,6 @@ implements Serializable,
* @param newState State change we're to tell listeners' about.
* @param message Message on state change.
*/
- @SuppressWarnings("unchecked")
protected void sendCrawlStateChangeEvent(State newState,
CrawlStatus status) {
if(this.state == newState) {
@@ -596,6 +596,10 @@ implements Serializable,
return (toePool == null) ? "" : ArchiveUtils.singleLineReport(toePool);
}
+ public Map getToeThreadReportShortData() {
+ return toePool == null ? null : toePool.singleLineReportData();
+
+ }
public String getFrontierReportShort() {
return ArchiveUtils.singleLineReport(getFrontier());
diff --git a/engine/src/main/java/org/archive/crawler/framework/CrawlJob.java b/engine/src/main/java/org/archive/crawler/framework/CrawlJob.java
index 11751013..1e95d974 100644
--- a/engine/src/main/java/org/archive/crawler/framework/CrawlJob.java
+++ b/engine/src/main/java/org/archive/crawler/framework/CrawlJob.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -653,6 +654,21 @@ public class CrawlJob implements Comparable, ApplicationListener {
return cc!=null ? cc.getStatisticsTracker() : null;
}
+ public Map rateReportData() {
+ StatisticsTracker stats = getStats();
+ if (stats == null) {
+ return null;
+ }
+
+ CrawlStatSnapshot snapshot = stats.getSnapshot();
+ Map map = new LinkedHashMap();
+ map.put("currentDocsPerSecond", snapshot.currentDocsPerSecond);
+ map.put("averageDocsPerSecond", snapshot.docsPerSecond);
+ map.put("currentKiBPerSec", snapshot.currentKiBPerSec);
+ map.put("averageKiBPerSec", snapshot.totalKiBPerSec);
+ return map;
+ }
+
public Object rateReport() {
StatisticsTracker stats = getStats();
if(stats==null) {
@@ -672,6 +688,23 @@ public class CrawlJob implements Comparable, ApplicationListener {
return sb.toString();
}
+ public Map loadReportData() {
+ StatisticsTracker stats = getStats();
+ if (stats == null) {
+ return null;
+ }
+
+ CrawlStatSnapshot snapshot = stats.getSnapshot();
+ Map map = new LinkedHashMap();
+
+ map.put("busyThreads", snapshot.busyThreads);
+ map.put("totalThreads", stats.threadCount());
+ map.put("congestionRatio", snapshot.congestionRatio);
+ map.put("averageQueueDepth", snapshot.averageDepth);
+ map.put("deepestQueueDepth", snapshot.deepestUri);
+ return map;
+ }
+
public Object loadReport() {
StatisticsTracker stats = getStats();
if(stats==null) {
@@ -693,32 +726,54 @@ public class CrawlJob implements Comparable, ApplicationListener {
return sb.toString();
}
- public String uriTotalsReport() {
+ public Map uriTotalsReportData() {
StatisticsTracker stats = getStats();
- if(stats==null) {
+ if (stats == null) {
+ return null;
+ }
+
+ CrawlStatSnapshot snapshot = stats.getSnapshot();
+
+ Map totals = new LinkedHashMap();
+ totals.put("downloadedUriCount", snapshot.downloadedUriCount);
+ totals.put("queuedUriCount", snapshot.queuedUriCount);
+ totals.put("totalUriCount", snapshot.totalCount());
+ totals.put("futureUriCount", snapshot.futureUriCount);
+
+ return totals;
+ }
+
+ public String uriTotalsReport() {
+ Map uriTotals = uriTotalsReportData();
+ if (uriTotals == null) {
return "n/a";
}
- CrawlStatSnapshot snapshot = stats.getSnapshot();
- long downloaded = snapshot.downloadedUriCount;
- long total = snapshot.totalCount();
- long queued = snapshot.queuedUriCount;
+
StringBuilder sb = new StringBuilder(64);
sb
- .append(downloaded)
+ .append(uriTotals.get("downloadedUriCount"))
.append(" downloaded + ")
- .append(queued)
+ .append(uriTotals.get("queuedUriCount"))
.append(" queued = ")
- .append(total)
+ .append(uriTotals.get("totalUriCount"))
.append(" total");
- if(snapshot.futureUriCount>0) {
+ if(uriTotals.get("futureUriCount") >0) {
sb
.append(" (")
- .append(snapshot.futureUriCount)
+ .append(uriTotals.get("futureUriCount"))
.append(" future)");
}
return sb.toString();
}
+ public Map sizeTotalsReportData() {
+ StatisticsTracker stats = getStats();
+ if(stats==null) {
+ return null;
+ }
+ return stats.getCrawledBytes();
+ }
+
public String sizeTotalsReport() {
StatisticsTracker stats = getStats();
if(stats==null) {
@@ -727,6 +782,20 @@ public class CrawlJob implements Comparable, ApplicationListener {
return stats.crawledBytesSummary();
}
+ public Map elapsedReportData() {
+ StatisticsTracker stats = getStats();
+ if(stats==null) {
+ return null;
+ }
+
+ Map map = new LinkedHashMap();
+ long timeElapsed = stats.getCrawlElapsedTime();
+ map.put("elapsedMilliseconds", timeElapsed);
+ map.put("elapsedPretty", ArchiveUtils.formatMillisecondsToConventional(timeElapsed));
+
+ return map;
+ }
+
public String elapsedReport() {
StatisticsTracker stats = getStats();
if(stats==null) {
@@ -736,6 +805,14 @@ public class CrawlJob implements Comparable, ApplicationListener {
return ArchiveUtils.formatMillisecondsToConventional(timeElapsed,false);
}
+ public Map threadReportData() {
+ CrawlController cc = getCrawlController();
+ if (cc == null) {
+ return null;
+ }
+ return cc.getToeThreadReportShortData();
+ }
+
public String threadReport() {
CrawlController cc = getCrawlController();
if(cc==null) {
@@ -744,6 +821,14 @@ public class CrawlJob implements Comparable, ApplicationListener {
return cc.getToeThreadReportShort();
}
+ public Map frontierReportData() {
+ CrawlController cc = getCrawlController();
+ if (cc == null) {
+ return null;
+ }
+ return cc.getFrontier().singleLineReportData();
+ }
+
public String frontierReport() {
CrawlController cc = getCrawlController();
if(cc==null) {
diff --git a/engine/src/main/java/org/archive/crawler/framework/Engine.java b/engine/src/main/java/org/archive/crawler/framework/Engine.java
index 93de1a41..48949a63 100644
--- a/engine/src/main/java/org/archive/crawler/framework/Engine.java
+++ b/engine/src/main/java/org/archive/crawler/framework/Engine.java
@@ -24,6 +24,7 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -249,6 +250,14 @@ public class Engine {
return jobsDir;
}
+ public Map heapReportData() {
+ Map map = new LinkedHashMap();
+ map.put("usedBytes", Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
+ map.put("totalBytes", Runtime.getRuntime().totalMemory());
+ map.put("maxBytes", Runtime.getRuntime().maxMemory());
+ return map;
+ }
+
public String heapReport() {
long totalMemory = Runtime.getRuntime().totalMemory();
long freeMemory = Runtime.getRuntime().freeMemory();
@@ -348,5 +357,4 @@ public class Engine {
LOGGER.log(Level.SEVERE,"job: "+jobName+" not found in jobConfig!");
}
}
-
}
\ No newline at end of file
diff --git a/engine/src/main/java/org/archive/crawler/framework/Frontier.java b/engine/src/main/java/org/archive/crawler/framework/Frontier.java
index 5280ce75..dfeea33e 100644
--- a/engine/src/main/java/org/archive/crawler/framework/Frontier.java
+++ b/engine/src/main/java/org/archive/crawler/framework/Frontier.java
@@ -517,6 +517,7 @@ public interface Frontier extends Lifecycle, MultiReporter {
HOLD, // enter a consistent, stable, checkpointable state ASAP
PAUSE, // enter a stable state where no URIs are in-progress; unlike
// HOLD requires all in-process URIs to complete
- FINISH }; // end and cleanup; may not return to any other state after
+ FINISH // end and cleanup; may not return to any other state after
// this state is requested/reached
+ }
}
diff --git a/engine/src/main/java/org/archive/crawler/framework/ToePool.java b/engine/src/main/java/org/archive/crawler/framework/ToePool.java
index d871fbba..9d222a58 100644
--- a/engine/src/main/java/org/archive/crawler/framework/ToePool.java
+++ b/engine/src/main/java/org/archive/crawler/framework/ToePool.java
@@ -21,9 +21,11 @@ package org.archive.crawler.framework;
import java.io.PrintWriter;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeSet;
+import org.apache.commons.lang.StringUtils;
import org.archive.crawler.reporting.AlertThreadGroup;
import org.archive.util.ArchiveUtils;
import org.archive.util.Histotable;
@@ -259,6 +261,34 @@ public class ToePool extends ThreadGroup implements MultiReporter {
}
}
+ public Map singleLineReportData() {
+ Histotable