[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-web/master] Add table with top-10 relays by bandwidth.



commit e988175f5056c2b4f4eb74bc0d8b8df26886eb2c
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Fri Jul 29 20:41:04 2011 -0400

    Add table with top-10 relays by bandwidth.
---
 rserve/tables.R                                    |   16 ++++++++++
 .../ernie/web/GraphsSubpagesServlet.java           |    3 ++
 .../ernie/web/TableParameterChecker.java           |    1 +
 web/WEB-INF/network.jsp                            |   31 ++++++++++++++++++++
 4 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/rserve/tables.R b/rserve/tables.R
index 6d3b5fb..aabd588 100644
--- a/rserve/tables.R
+++ b/rserve/tables.R
@@ -69,3 +69,19 @@ write_censorship_events <- function(start, end, path) {
   write.csv(r, path, quote = FALSE, row.names = FALSE)
 }
 
+write_top_10_relays <- function(start, end, path) {
+  drv <- dbDriver("PostgreSQL")
+  con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db)
+  q <- paste("SELECT fingerprint, SUM(written_sum) ",
+      "AS written_sum FROM bwhist WHERE date >= '", start,
+      "' AND date <= '", end, "' GROUP BY 1 ORDER BY 2 DESC LIMIT 10",
+      sep = "")
+  rs <- dbSendQuery(con, q)
+  c <- fetch(rs, n = -1)
+  dbDisconnect(con)
+  dbUnloadDriver(drv)
+  c <- data.frame(fingerprint = c$fingerprint,
+    written_sum = round(c$written_sum / 2^40, 2))
+  write.csv(c, path, quote = FALSE, row.names = FALSE)
+}
+
diff --git a/src/org/torproject/ernie/web/GraphsSubpagesServlet.java b/src/org/torproject/ernie/web/GraphsSubpagesServlet.java
index c7f3056..16d0db0 100644
--- a/src/org/torproject/ernie/web/GraphsSubpagesServlet.java
+++ b/src/org/torproject/ernie/web/GraphsSubpagesServlet.java
@@ -36,6 +36,9 @@ public class GraphsSubpagesServlet extends HttpServlet {
     this.availableGraphsSubpageTables.put("users.html",
         new HashSet<String>(Arrays.asList(
         "direct-users,censorship-events".split(","))));
+    this.availableGraphsSubpageTables.put("network.html",
+        new HashSet<String>(Arrays.asList(
+        "top-10-relays".split(","))));
 
     this.knownCountries = Countries.getInstance().getCountryList();
   }
diff --git a/src/org/torproject/ernie/web/TableParameterChecker.java b/src/org/torproject/ernie/web/TableParameterChecker.java
index 5b6f627..2c0a7be 100644
--- a/src/org/torproject/ernie/web/TableParameterChecker.java
+++ b/src/org/torproject/ernie/web/TableParameterChecker.java
@@ -41,6 +41,7 @@ public class TableParameterChecker {
     this.availableTables = new HashMap<String, String>();
     this.availableTables.put("direct-users", "start,end,filename");
     this.availableTables.put("censorship-events", "start,end,filename");
+    this.availableTables.put("top-10-relays", "start,end,filename");
 
     this.knownParameterValues = new HashMap<String, String>();
   }
diff --git a/web/WEB-INF/network.jsp b/web/WEB-INF/network.jsp
index 1789cb7..9d83cf1 100644
--- a/web/WEB-INF/network.jsp
+++ b/web/WEB-INF/network.jsp
@@ -1,5 +1,6 @@
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"; %>
 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"; %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"; %>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 <html>
 <head>
@@ -230,6 +231,36 @@ in the network.</p>
 </form>
 <p><a href="csv/bandwidth.csv">CSV</a> file containing all data.</p>
 <br>
+<a name="top-10-relays"></a>
+<p><b>Top-10 relays by bandwidth history:</b></p>
+<table>
+  <tr>
+    <th>Fingerprint</th>
+    <th>Bandwidth history</th>
+  </tr>
+  <c:forEach var="row" items="${top_10_relays_tabledata}">
+    <tr>
+      <td><a href="https://metrics.torproject.org/relay.html?fingerprint=${row['fingerprint']}">${row['fingerprint']}</a>&emsp;</td>
+      <td><fmt:formatNumber type="number" minFractionDigits="2" value="${row['written_sum']}" /> TiB</td>
+    </tr>
+  </c:forEach>
+</table>
+<br>
+<form action="network.html#top-10-relays">
+  <div class="formrow">
+    <input type="hidden" name="table" value="top-10-relays">
+    <p>
+    <label>Start date (yyyy-mm-dd):</label>
+      <input type="text" name="start" size="10"
+             value="<c:choose><c:when test="${fn:length(top_10_relays_start) == 0}">${default_start_date}</c:when><c:otherwise>${top_10_relays_start[0]}</c:otherwise></c:choose>">
+    <label>End date (yyyy-mm-dd):</label>
+      <input type="text" name="end" size="10"
+             value="<c:choose><c:when test="${fn:length(top_10_relays_end) == 0}">${default_end_date}</c:when><c:otherwise>${top_10_relays_end[0]}</c:otherwise></c:choose>">
+    </p><p>
+    <input class="submit" type="submit" value="Update table">
+    </p>
+  </div>
+</form>
 
 <h3>Relay bandwidth by Exit and/or Guard flags</h3>
 <br>

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits