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

[or-cvs] [metrics-web/master] Add new dirbytes graph.



Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Wed, 13 Oct 2010 12:30:41 +0200
Subject: Add new dirbytes graph.
Commit: c593b457be58ce8600e29cd959c0577b0bd4b104

---
 etc/web.xml                                        |    4 ++
 rserve/graphs.R                                    |   28 ++++++++++
 .../torproject/ernie/web/GraphImageServlet.java    |    1 +
 web/WEB-INF/network.jsp                            |   53 ++++++++++++++++++++
 4 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/etc/web.xml b/etc/web.xml
index f6f86ab..5962066 100644
--- a/etc/web.xml
+++ b/etc/web.xml
@@ -157,6 +157,10 @@
   </servlet-mapping>
   <servlet-mapping>
     <servlet-name>GraphImageServlet</servlet-name>
+    <url-pattern>/dirbytes.png</url-pattern>
+  </servlet-mapping>
+  <servlet-mapping>
+    <servlet-name>GraphImageServlet</servlet-name>
     <url-pattern>/new-users.png</url-pattern>
   </servlet-mapping>
   <servlet-mapping>
diff --git a/rserve/graphs.R b/rserve/graphs.R
index 86a4894..7949c1b 100644
--- a/rserve/graphs.R
+++ b/rserve/graphs.R
@@ -125,6 +125,34 @@ plot_bandwidth <- function(start, end, path) {
   ggsave(filename = path, width = 8, height = 5, dpi = 72)
 }
 
+plot_dirbytes <- function(start, end, path) {
+  drv <- dbDriver("PostgreSQL")
+  con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db)
+  q <- paste("SELECT date, read, written, dirread, dirwritten ",
+      "FROM total_bwhist WHERE date >= '", start, "' AND date <= '", end,
+      "' AND date < (SELECT MAX(date) FROM total_bwhist) - 1 ", sep = "")
+  rs <- dbSendQuery(con, q)
+  bw_hist <- fetch(rs, n = -1)
+  dbDisconnect(con)
+  dbUnloadDriver(drv)
+  bw_hist <- melt(bw_hist, id = "date")
+  ggplot(bw_hist, aes(x = as.Date(date, "%Y-%m-%d"), y = value /
+      (86400 * 2^20), colour = variable)) +
+    geom_line(size = 1) +
+    scale_x_date(name = paste("\nThe Tor Project - ",
+        "https://metrics.torproject.org/";, sep = "")) +
+    scale_y_continuous(name="Bandwidth (MiB/s)",
+        limits = c(0, max(bw_hist$value, na.rm = TRUE) /
+        (86400 * 2^20))) +
+    scale_colour_hue(name = "",
+        breaks = c("written", "read", "dirwritten", "dirread"),
+        labels = c("Total written bytes", "Total read bytes",
+            "Written dir bytes", "Read dir bytes")) +
+    opts(title = "Number of bytes spent on answering directory requests",
+        legend.position = "top")
+  ggsave(filename = path, width = 8, height = 5, dpi = 72)
+}
+
 plot_relayflags <- function(start, end, flags, path) {
   drv <- dbDriver("PostgreSQL")
   con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db)
diff --git a/src/org/torproject/ernie/web/GraphImageServlet.java b/src/org/torproject/ernie/web/GraphImageServlet.java
index f6a76c7..333ef65 100644
--- a/src/org/torproject/ernie/web/GraphImageServlet.java
+++ b/src/org/torproject/ernie/web/GraphImageServlet.java
@@ -35,6 +35,7 @@ public class GraphImageServlet extends HttpServlet {
     this.availableGraphs.put("versions", "start,end,filename");
     this.availableGraphs.put("platforms", "start,end,filename");
     this.availableGraphs.put("bandwidth", "start,end,filename");
+    this.availableGraphs.put("dirbytes", "start,end,filename");
     this.availableGraphs.put("new-users", "start,end,country,filename");
     this.availableGraphs.put("direct-users",
         "start,end,country,filename");
diff --git a/web/WEB-INF/network.jsp b/web/WEB-INF/network.jsp
index 3a1e8e6..84623ba 100644
--- a/web/WEB-INF/network.jsp
+++ b/web/WEB-INF/network.jsp
@@ -348,6 +348,59 @@ out.println("<img src=\"" + bandwidthUrl.toString() + "\" width=\"576\" "
   </div>
 </form>
 <br>
+
+<h3>Number of bytes spent on answering directory requests</h3>
+<br>
+<p>Relays running on 0.2.2.15-alpha or higher report the number of bytes
+they spend on answering directory requests. The following graph shows
+total written and read bytes as well as written and read dir bytes. The
+dir bytes are extrapolated from those relays who report them to reflect
+the number of written and read dir bytes by all relays.</p>
+<a name="dirbytes"></a>
+<%
+StringBuilder dirbytesUrl = new StringBuilder("dirbytes.png");
+if ("dirbytes".equals(request.getParameter("graph"))) {
+  List<String> parameters = new ArrayList<String>();
+// TODO check values here!
+  String startParameter = request.getParameter("start"),
+      endParameter = request.getParameter("end");
+  if (startParameter != null && startParameter.length() > 0) {
+    parameters.add("start=" + startParameter);
+  }
+  if (endParameter != null && endParameter.length() > 0) {
+    parameters.add("end=" + endParameter);
+  }
+  if (parameters.size() > 0) {
+    dirbytesUrl.append("?" + parameters.get(0));
+    if (parameters.size() > 1) {
+      for (int i = 1; i < parameters.size(); i++) {
+        dirbytesUrl.append("&" + parameters.get(i));
+      }
+    }
+  }
+}
+out.println("<img src=\"" + dirbytesUrl.toString() + "\" width=\"576\" "
+    + "height=\"360\" alt=\"Dir bytes graph\">");
+%><form action="network.html#dirbytes">
+  <div class="formrow">
+    <input type="hidden" name="graph" value="dirbytes">
+    <p>
+    <label>Start date (yyyy-mm-dd):</label>
+      <input type="text" name="start" size="10"
+        value="<%=("dirbytes".equals(request.getParameter("graph")) &&
+                   request.getParameter("start") != null) ?
+                      request.getParameter("start") : ""%>">
+    <label>End date (yyyy-mm-dd):</label>
+      <input type="text" name="end" size="10"
+        value="<%=("dirbytes".equals(request.getParameter("graph")) &&
+                   request.getParameter("end") != null) ?
+                      request.getParameter("end") : ""%>">
+    </p><p>
+    <input class="submit" type="submit" value="Update graph">
+    </p>
+  </div>
+</form>
+<br>
     </div>
   </div>
   <div class="bottom" id="bottom">
-- 
1.7.1