commit c7532f18d4f5ac93a7c21fbca3e0274a6c6ac505 Author: Karsten Loesing karsten.loesing@gmx.net Date: Mon Dec 12 16:40:52 2016 +0100
Put metrics into categories. --- website/build.xml | 3 + website/etc/categories.json | 67 ++++++++++++++++++++++ .../src/org/torproject/metrics/web/Category.java | 34 +++++++++++ .../torproject/metrics/web/ContentProvider.java | 38 ++++++++++++ .../org/torproject/metrics/web/GraphServlet.java | 13 +++++ .../org/torproject/metrics/web/MetricServlet.java | 8 +++ .../torproject/metrics/web/MetricsProvider.java | 38 ------------ .../org/torproject/metrics/web/TableServlet.java | 12 ++++ website/web/WEB-INF/graph.jsp | 28 ++++++++- website/web/WEB-INF/table.jsp | 28 ++++++++- 10 files changed, 229 insertions(+), 40 deletions(-)
diff --git a/website/build.xml b/website/build.xml index 9f37d13..6e156b4 100644 --- a/website/build.xml +++ b/website/build.xml @@ -51,6 +51,9 @@ <zipfileset dir="etc" prefix="WEB-INF/classes" includes="metrics.json"/> + <zipfileset dir="etc" + prefix="WEB-INF/classes" + includes="categories.json"/> <metainf dir="etc" includes="context.xml"/> </war> diff --git a/website/etc/categories.json b/website/etc/categories.json new file mode 100644 index 0000000..563b662 --- /dev/null +++ b/website/etc/categories.json @@ -0,0 +1,67 @@ +[ + { + "id": "clients", + "header": "Users", + "description": "<p>Where are Tor users from? How do they connect to Tor?</p>", + "metrics": [ + "userstats-relay-country", + "userstats-bridge-country", + "userstats-bridge-transport", + "userstats-bridge-combined", + "userstats-bridge-version", + "userstats-relay-table", + "userstats-censorship-events", + "userstats-bridge-table" + ] + }, + { + "id": "servers", + "header": "Relays and Bridges", + "description": "<p>How many relays and bridges are online? What do we know about them?</p>", + "metrics": [ + "networksize", + "relayflags", + "versions", + "platforms" + ] + }, + { + "id": "traffic", + "header": "Traffic", + "description": "<p>How much traffic can the Tor network handle? How much traffic is there?</p>", + "metrics": [ + "bandwidth", + "bandwidth-flags", + "advbwdist-perc", + "advbwdist-relay", + "bwhist-flags", + "dirbytes" + ] + }, + { + "id": "performance", + "header": "Performance", + "description": "<p>How fast and reliable is the Tor network?</p>", + "metrics": [ + "torperf", + "torperf-failures", + "connbidirect" + ] + }, + { + "id": "onion-services", + "header": "Onion Services", + "description": "<p>How many onion services are there? How much traffic do they pull?</p>", + "metrics": [ + "hidserv-dir-onions-seen", + "hidserv-rend-relayed-cells", + "hidserv-frac-reporting" + ] + }, + { + "id": "downloads", + "header": "Downloads (coming soon)", + "description": "<p>How many downloads of Tor applications are there? How many updates?</p>", + "metrics": [] + } +] diff --git a/website/src/org/torproject/metrics/web/Category.java b/website/src/org/torproject/metrics/web/Category.java new file mode 100644 index 0000000..7f71b22 --- /dev/null +++ b/website/src/org/torproject/metrics/web/Category.java @@ -0,0 +1,34 @@ +/* Copyright 2016 The Tor Project + * See LICENSE for licensing information */ + +package org.torproject.metrics.web; + +import java.util.List; + +public class Category { + + private String id; + + private String header; + + private String description; + + private List<String> metrics; + + public String getId() { + return id; + } + + public String getHeader() { + return header; + } + + public String getDescription() { + return description; + } + + public List<String> getMetrics() { + return metrics; + } +} + diff --git a/website/src/org/torproject/metrics/web/ContentProvider.java b/website/src/org/torproject/metrics/web/ContentProvider.java new file mode 100644 index 0000000..606e7db --- /dev/null +++ b/website/src/org/torproject/metrics/web/ContentProvider.java @@ -0,0 +1,38 @@ +/* Copyright 2016 The Tor Project + * See LICENSE for licensing information */ + +package org.torproject.metrics.web; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MetricsProvider { + + private static MetricsProvider instance = new MetricsProvider(); + + public static MetricsProvider getInstance() { + return MetricsProvider.instance; + } + + private List<Metric> metricsList; + + private MetricsProvider() { + InputStream in = this.getClass().getClassLoader() + .getResourceAsStream("metrics.json"); + Gson gson = new GsonBuilder().create(); + Metric[] metricsArray = gson.fromJson(new InputStreamReader(in), + Metric[].class); + this.metricsList = Arrays.asList(metricsArray); + } + + public List<Metric> getMetricsList() { + return new ArrayList<Metric>(this.metricsList); + } +} + diff --git a/website/src/org/torproject/metrics/web/GraphServlet.java b/website/src/org/torproject/metrics/web/GraphServlet.java index 189406c..3a73fa5 100644 --- a/website/src/org/torproject/metrics/web/GraphServlet.java +++ b/website/src/org/torproject/metrics/web/GraphServlet.java @@ -8,6 +8,7 @@ import org.torproject.metrics.web.graphs.GraphParameterChecker;
import java.io.IOException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; @@ -135,6 +136,18 @@ public class GraphServlet extends MetricServlet { } request.setAttribute("id", requestedId); request.setAttribute("title", this.titles.get(requestedId)); + if (this.categories.containsKey(requestedId)) { + Category category = this.categories.get(requestedId); + request.setAttribute("categoryHeader", category.getHeader()); + request.setAttribute("categoryDescription", category.getDescription()); + List<String[]> categoryTabs = new ArrayList<String[]>(); + for (String metricId : category.getMetrics()) { + categoryTabs.add(new String[] { + this.titles.get(metricId), + requestedId.equals(metricId) ? null : metricId }); + } + request.setAttribute("categoryTabs", categoryTabs); + } request.setAttribute("description", this.descriptions.get(requestedId)); request.setAttribute("data", this.data.get(requestedId)); diff --git a/website/src/org/torproject/metrics/web/MetricServlet.java b/website/src/org/torproject/metrics/web/MetricServlet.java index 086f9e7..8de6922 100644 --- a/website/src/org/torproject/metrics/web/MetricServlet.java +++ b/website/src/org/torproject/metrics/web/MetricServlet.java @@ -47,6 +47,8 @@ public abstract class MetricServlet extends HttpServlet { protected Map<String, List<String[]>> related = new HashMap<String, List<String[]>>();
+ protected Map<String, Category> categories = new HashMap<String, Category>(); + @Override public void init() throws ServletException { this.metrics = MetricsProvider.getInstance().getMetricsList(); @@ -113,6 +115,12 @@ public abstract class MetricServlet extends HttpServlet { } } } + for (Category category : + CategoriesProvider.getInstance().getCategoriesList()) { + for (String id : category.getMetrics()) { + categories.put(id, category); + } + } } }
diff --git a/website/src/org/torproject/metrics/web/MetricsProvider.java b/website/src/org/torproject/metrics/web/MetricsProvider.java deleted file mode 100644 index 606e7db..0000000 --- a/website/src/org/torproject/metrics/web/MetricsProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2016 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.metrics.web; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class MetricsProvider { - - private static MetricsProvider instance = new MetricsProvider(); - - public static MetricsProvider getInstance() { - return MetricsProvider.instance; - } - - private List<Metric> metricsList; - - private MetricsProvider() { - InputStream in = this.getClass().getClassLoader() - .getResourceAsStream("metrics.json"); - Gson gson = new GsonBuilder().create(); - Metric[] metricsArray = gson.fromJson(new InputStreamReader(in), - Metric[].class); - this.metricsList = Arrays.asList(metricsArray); - } - - public List<Metric> getMetricsList() { - return new ArrayList<Metric>(this.metricsList); - } -} - diff --git a/website/src/org/torproject/metrics/web/TableServlet.java b/website/src/org/torproject/metrics/web/TableServlet.java index ad2b10a..035c0be 100644 --- a/website/src/org/torproject/metrics/web/TableServlet.java +++ b/website/src/org/torproject/metrics/web/TableServlet.java @@ -50,6 +50,18 @@ public class TableServlet extends MetricServlet { } request.setAttribute("id", requestedId); request.setAttribute("title", this.titles.get(requestedId)); + if (this.categories.containsKey(requestedId)) { + Category category = this.categories.get(requestedId); + request.setAttribute("categoryHeader", category.getHeader()); + request.setAttribute("categoryDescription", category.getDescription()); + List<String[]> categoryTabs = new ArrayList<String[]>(); + for (String metricId : category.getMetrics()) { + categoryTabs.add(new String[] { + this.titles.get(metricId), + requestedId.equals(metricId) ? null : metricId }); + } + request.setAttribute("categoryTabs", categoryTabs); + } request.setAttribute("description", this.descriptions.get(requestedId)); request.setAttribute("tableheader", diff --git a/website/web/WEB-INF/graph.jsp b/website/web/WEB-INF/graph.jsp index ad33e4d..2ce9583 100644 --- a/website/web/WEB-INF/graph.jsp +++ b/website/web/WEB-INF/graph.jsp @@ -11,8 +11,34 @@ <body> <div class="center"> <div class="main-column"> + <h2><a href="/"><img src="images/metrics-logo.png" width="153" height="200" alt="Metrics logo"><img src="images/metrics-wordmark.png" width="384" height="50" alt="Metrics wordmark"></a></h2> + <br> + +<p>"Tor metrics are the ammunition that lets Tor and other security +advocates argue for a more private and secure Internet from a position +of data, rather than just dogma or perspective." +<i>- Bruce Schneier (June 1, 2016)</i></p> + + <!-- Navigation start --> + Metrics | + <a href="about.html">About</a> | + <a href="news.html">News</a> | + <a href="sources.html">Sources</a> | + <a href="tools.html">Tools</a> | + <a href="research.html">Research</a> + <br> + <br> + <!-- Navigation end --> + +<h2>${categoryHeader}</h2> + +${categoryDescription} + +<c:forEach var="tab" items="${categoryTabs}"> +<c:if test="${fn:length(tab[1]) > 0}"><a href="${tab[1]}.html"></c:if>${tab[0]}<c:if test="${fn:length(tab[1]) > 0}"></a></c:if> | +</c:forEach> +<br>
-<h2><a href="."><img src="images/metrics-wordmark-small.png" width="138" height="18" alt="Metrics wordmark"></a> — ${title}</h2> <br> ${description} <img src="${id}.png${parameters}" diff --git a/website/web/WEB-INF/table.jsp b/website/web/WEB-INF/table.jsp index 1eca70f..ffabd75 100644 --- a/website/web/WEB-INF/table.jsp +++ b/website/web/WEB-INF/table.jsp @@ -11,8 +11,34 @@ <body> <div class="center"> <div class="main-column"> + <h2><a href="/"><img src="images/metrics-logo.png" width="153" height="200" alt="Metrics logo"><img src="images/metrics-wordmark.png" width="384" height="50" alt="Metrics wordmark"></a></h2> + <br> + +<p>"Tor metrics are the ammunition that lets Tor and other security +advocates argue for a more private and secure Internet from a position +of data, rather than just dogma or perspective." +<i>- Bruce Schneier (June 1, 2016)</i></p> + + <!-- Navigation start --> + Metrics | + <a href="about.html">About</a> | + <a href="news.html">News</a> | + <a href="sources.html">Sources</a> | + <a href="tools.html">Tools</a> | + <a href="research.html">Research</a> + <br> + <br> + <!-- Navigation end --> + +<h2>${categoryHeader}</h2> + +${categoryDescription} + +<c:forEach var="tab" items="${categoryTabs}"> +<c:if test="${fn:length(tab[1]) > 0}"><a href="${tab[1]}.html"></c:if>${tab[0]}<c:if test="${fn:length(tab[1]) > 0}"></a></c:if> | +</c:forEach> +<br>
-<h2><a href="."><img src="images/metrics-wordmark-small.png" width="138" height="18" alt="Metrics wordmark"></a> — ${title}</h2> <br> ${description} <form action="${id}.html">
tor-commits@lists.torproject.org