[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [metrics-web/master] Add new graph on relay flags on 1-hour detail.
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon, 11 Oct 2010 21:09:47 +0200
Subject: Add new graph on relay flags on 1-hour detail.
Commit: 282137e3e24af71528192e5a4a4e66b5ae94101e
---
etc/web.xml | 4 +
rserve/graphs.R | 30 +++++++++
.../torproject/ernie/web/GraphImageServlet.java | 2 +
web/WEB-INF/network.jsp | 65 ++++++++++++++++++++
4 files changed, 101 insertions(+), 0 deletions(-)
diff --git a/etc/web.xml b/etc/web.xml
index e6d0c30..f6f86ab 100644
--- a/etc/web.xml
+++ b/etc/web.xml
@@ -141,6 +141,10 @@
</servlet-mapping>
<servlet-mapping>
<servlet-name>GraphImageServlet</servlet-name>
+ <url-pattern>/relayflags-hour.png</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>GraphImageServlet</servlet-name>
<url-pattern>/versions.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
diff --git a/rserve/graphs.R b/rserve/graphs.R
index b786990..0030d08 100644
--- a/rserve/graphs.R
+++ b/rserve/graphs.R
@@ -152,6 +152,36 @@ plot_relayflags <- function(start, end, flags, path) {
ggsave(filename = path, width = 8, height = 5, dpi = 72)
}
+plot_relayflags_hour <- function(start, end, flags, path) {
+ drv <- dbDriver("PostgreSQL")
+ con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db)
+ columns <- paste("avg_", tolower(flags), sep = "", collapse = ", ")
+ q <- paste("SELECT validafter, ", columns, " FROM network_size_hour ",
+ "WHERE DATE(validafter) >= '", start, "' AND DATE(validafter) <= '",
+ end, "'", sep = "")
+ rs <- dbSendQuery(con, q)
+ networksize <- fetch(rs, n = -1)
+ dbDisconnect(con)
+ dbUnloadDriver(drv)
+ networksize <- melt(networksize, id = "validafter")
+# TODO improve colors?
+ colours <- data.frame(flag = c("Running", "Exit", "Guard", "Fast",
+ "Stable"), colour = c("black", "green", "orange", "red", "blue"),
+ stringsAsFactors = FALSE)
+ colours <- colours[colours$flag %in% flags, "colour"]
+ ggplot(networksize, aes(x = as.POSIXct(validafter), y = value,
+ colour = variable)) + geom_line(size = 1) +
+ scale_x_datetime(name = paste("\nThe Tor Project - ",
+ "https://metrics.torproject.org/", sep = "")) +
+ scale_y_continuous(name = "", limits = c(0, max(networksize$value,
+ na.rm = TRUE))) +
+ scale_colour_manual(name = "Relay flags",
+ breaks = paste("avg_", tolower(flags), sep = ""), labels = flags,
+ values = colours) +
+ opts(title = "Number of relays with relay flags assigned\n")
+ ggsave(filename = path, width = 8, height = 5, dpi = 72)
+}
+
plot_new_users <- function(start, end, country, 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 4f0570e..f6a76c7 100644
--- a/src/org/torproject/ernie/web/GraphImageServlet.java
+++ b/src/org/torproject/ernie/web/GraphImageServlet.java
@@ -30,6 +30,8 @@ public class GraphImageServlet extends HttpServlet {
this.availableGraphs = new HashMap<String, String>();
this.availableGraphs.put("networksize", "start,end,filename");
this.availableGraphs.put("relayflags", "start,end,flag,filename");
+ this.availableGraphs.put("relayflags-hour",
+ "start,end,flag,filename");
this.availableGraphs.put("versions", "start,end,filename");
this.availableGraphs.put("platforms", "start,end,filename");
this.availableGraphs.put("bandwidth", "start,end,filename");
diff --git a/web/WEB-INF/network.jsp b/web/WEB-INF/network.jsp
index a07c5a3..3a1e8e6 100644
--- a/web/WEB-INF/network.jsp
+++ b/web/WEB-INF/network.jsp
@@ -130,6 +130,71 @@ out.println("<img src=\"" + relayflagsUrl.toString() + "\" width=\"576\" "
</form>
<br>
+<h3>Relays with Exit, Fast, Guard, and Stable flags on 1-hour detail</h3>
+<br>
+<p>The same graph on the average number of relays with flags assigned is
+available on 1-hour detail.</p>
+<a name="relayflags-hour"></a>
+<%
+StringBuilder relayflagsHourUrl = new StringBuilder("relayflags-hour.png");
+if ("relayflags-hour".equals(request.getParameter("graph"))) {
+ List<String> parameters = new ArrayList<String>();
+// TODO check values here!
+ String startParameter = request.getParameter("start"),
+ endParameter = request.getParameter("end");
+ String[] flagParameters = request.getParameterValues("flag");
+ if (startParameter != null && startParameter.length() > 0) {
+ parameters.add("start=" + startParameter);
+ }
+ if (endParameter != null && endParameter.length() > 0) {
+ parameters.add("end=" + endParameter);
+ }
+ if (flagParameters != null && flagParameters.length > 0) {
+ for (String flag : flagParameters) {
+ if (flag != null && flag.length() > 0) {
+ parameters.add("flag=" + flag);
+ }
+ }
+ }
+ if (parameters.size() > 0) {
+ relayflagsHourUrl.append("?" + parameters.get(0));
+ if (parameters.size() > 1) {
+ for (int i = 1; i < parameters.size(); i++) {
+ relayflagsHourUrl.append("&" + parameters.get(i));
+ }
+ }
+ }
+}
+out.println("<img src=\"" + relayflagsHourUrl.toString()
+ + "\" width=\"576\" height=\"360\" alt=\"Relay flags graph\">");
+%><form action="network.html#relayflags-hour">
+ <div class="formrow">
+ <input type="hidden" name="graph" value="relayflags-hour">
+ <p>
+ <label>Start date (yyyy-mm-dd):</label>
+ <input type="text" name="start" size="10"
+ value="<%=("relayflags-hour".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="<%=("relayflags-hour".equals(request.getParameter("graph")) &&
+ request.getParameter("end") != null) ?
+ request.getParameter("end") : ""%>">
+ </p><p>
+ <label>Relay flags: </label>
+ <input type="checkbox" name="flag" value="Running"> Running
+ <input type="checkbox" name="flag" value="Exit"> Exit
+ <input type="checkbox" name="flag" value="Fast"> Fast
+ <input type="checkbox" name="flag" value="Guard"> Guard
+ <input type="checkbox" name="flag" value="Stable"> Stable
+ </p><p>
+ <input class="submit" type="submit" value="Update graph">
+ </p>
+ </div>
+</form>
+<br>
+
<h3>Relays by version</h3>
<br>
<p>Relays report the Tor version that they are running to the directory
--
1.7.1