Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Fetcher displays protocol status names in counters instead of their code

Julien Nioche753414e620f8
diff --git a/src/java/org/apache/nutch/fetcher/FetcherReducer.java b/src/java/org/apache/nutch/fetcher/FetcherReducer.java
index 82f532b26..e929b74b5 100644
--- a/src/java/org/apache/nutch/fetcher/FetcherReducer.java
+++ b/src/java/org/apache/nutch/fetcher/FetcherReducer.java
@@ -455,7 +455,7 @@ extends GoraReducer<IntWritable, FetchEntry, String, WebPage> {
// unblock queue
fetchQueues.finishFetchItem(fit);
- context.getCounter("FetcherStatus", "code_"+status.getCode()).increment(1);
+ context.getCounter("FetcherStatus", ProtocolStatusUtils.getName(status.getCode())).increment(1);
int length = 0;
if (content!=null && content.getContent()!=null) length= content.getContent().length;
diff --git a/src/java/org/apache/nutch/storage/ProtocolStatusUtils.java b/src/java/org/apache/nutch/storage/ProtocolStatusUtils.java
index cec0b6b0a..7487c7e3e 100644
--- a/src/java/org/apache/nutch/storage/ProtocolStatusUtils.java
+++ b/src/java/org/apache/nutch/storage/ProtocolStatusUtils.java
@@ -22,6 +22,42 @@ public class ProtocolStatusUtils implements ProtocolStatusCodes {
public static final ProtocolStatus STATUS_WOULDBLOCK = makeStatus(WOULDBLOCK);
public static final ProtocolStatus STATUS_BLOCKED = makeStatus(BLOCKED);
+ public static String getName(int code) {
+ if (code == SUCCESS)
+ return "SUCCESS";
+ else if (code == FAILED)
+ return "FAILED";
+ else if (code == PROTO_NOT_FOUND)
+ return "PROTO_NOT_FOUND";
+ else if (code == GONE)
+ return "GONE";
+ else if (code == MOVED)
+ return "MOVED";
+ else if (code == TEMP_MOVED)
+ return "TEMP_MOVED";
+ else if (code == NOTFOUND)
+ return "NOTFOUND";
+ else if (code == RETRY)
+ return "RETRY";
+ else if (code == EXCEPTION)
+ return "EXCEPTION";
+ else if (code == ACCESS_DENIED)
+ return "ACCESS_DENIED";
+ else if (code == ROBOTS_DENIED)
+ return "ROBOTS_DENIED";
+ else if (code == REDIR_EXCEEDED)
+ return "REDIR_EXCEEDED";
+ else if (code == NOTFETCHING)
+ return "NOTFETCHING";
+ else if (code == NOTMODIFIED)
+ return "NOTMODIFIED";
+ else if (code == WOULDBLOCK)
+ return "WOULDBLOCK";
+ else if (code == BLOCKED)
+ return "BLOCKED";
+ return "UNKNOWN_CODE_" + code;
+ }
+
public static ProtocolStatus makeStatus(int code) {
ProtocolStatus pstatus = new ProtocolStatus();
pstatus.setCode(code);
@@ -47,4 +83,3 @@ public class ProtocolStatusUtils implements ProtocolStatusCodes {
return TableUtil.toString(args.iterator().next());
}
}
-