Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rate display for metric

  • Loading branch information...
commit 5bc5575083613b833ae1e81ce176832658d3d917 1 parent 117f6cc
Claudiu Dan Gheorghe claudiugh authored
3  server/src/com/facebook/tsdb/tsdash/server/DataEndpoint.java
View
@@ -70,6 +70,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
q.tags, q.orders);
metrics[i] = metrics[i].dissolveTags(q.getDissolveList(),
q.aggregator);
+ if (q.rate) {
+ metrics[i].computeRate();
+ }
}
long loadTime = System.currentTimeMillis() - ts;
JSONObject responseObj = new JSONObject();
7 server/src/com/facebook/tsdb/tsdash/server/PlotEndpoint.java
View
@@ -77,6 +77,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
q.tags, q.orders);
metrics[i] = metrics[i].dissolveTags(q.getDissolveList(),
q.aggregator);
+ if (q.rate) {
+ metrics[i].computeRate();
+ }
}
long loadTime = System.currentTimeMillis() - ts;
// check to see if we have data
@@ -99,8 +102,8 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
GnuplotProcess gnuplot = GnuplotProcess.create(surface);
GnuplotOptions options = new GnuplotOptions(surface);
options.enablePalette(palette);
- options.setDimensions((int) width, (int) height).setTimeRange(
- tsFrom, tsTo);
+ options.setDimensions((int) width, (int) height)
+ .setTimeRange(tsFrom, tsTo);
String plotFilename = gnuplot.plot(metrics, options);
gnuplot.close();
8 server/src/com/facebook/tsdb/tsdash/server/data/DataTable.java
View
@@ -40,14 +40,18 @@ private JSONObject newColumn(String label, String type) {
return col;
}
+ private String renderLineTitle(Metric metric, TagsArray tags) {
+ String suffix = metric.isRate() ? " /s" : "";
+ return metric.getName() + ": " + tags.getTitle() + suffix;
+ }
+
@SuppressWarnings("unchecked")
private JSONArray generateColumns() {
JSONArray cols = new JSONArray();
cols.add(newColumn("Date", "datetime"));
for (Metric metric : metrics) {
for (TagsArray timeSeries : metric.timeSeries.keySet()) {
- cols.add(newColumn(
- metric.getName() + ": " + timeSeries.getTitle(),
+ cols.add(newColumn(renderLineTitle(metric, timeSeries),
"number"));
}
}
15 server/src/com/facebook/tsdb/tsdash/server/gnuplot/Gnuplot2D.java
View
@@ -41,20 +41,33 @@ private void write2DTimeSeries(ArrayList<DataPoint> dataPoints,
writer.close();
}
+ private String renderLineTitle(Metric metric, TagsArray rowTags) {
+ String suffix = metric.isRate() ? " /s" : "";
+ return metric.getName() + "{" + rowTags.getTitle() + "}" + suffix;
+ }
+
@Override
public String plot(Metric[] metrics, GnuplotOptions options)
throws Exception {
int count = 0;
+ int rates = 0;
for (Metric metric : metrics) {
for (ArrayList<DataPoint> dataPoints : metric.timeSeries.values()) {
if (dataPoints.size() > 0) {
count++;
}
}
+ if (metric.isRate()) {
+ rates++;
+ }
}
if (count == 0) {
return noDataFilename();
}
+ // we enable rate display (/s) on the y axis
+ if (count == rates) {
+ options.setDisplayRate(true);
+ }
createPipes(count);
options.clearDataSources();
int i = 0;
@@ -62,7 +75,7 @@ public String plot(Metric[] metrics, GnuplotOptions options)
for (TagsArray rowTags : metric.timeSeries.keySet()) {
if (metric.timeSeries.get(rowTags).size() > 0) {
options.addDataSource(new DataSource(getPipeFilename(i),
- metric.getName() + "{" + rowTags.getTitle() + "}"));
+ renderLineTitle(metric, rowTags)));
i++;
}
}
20 server/src/com/facebook/tsdb/tsdash/server/gnuplot/GnuplotOptions.java
View
@@ -33,6 +33,7 @@
private long tsTo = 0;
private boolean surface;
private boolean palette = false;
+ private boolean displayRate = false;
public GnuplotOptions(boolean surface) {
this.surface = surface;
@@ -46,6 +47,11 @@ public void clearDataSources() {
dataSources.clear();
}
+ public GnuplotOptions setDisplayRate(boolean rate) {
+ displayRate = rate;
+ return this;
+ }
+
public GnuplotOptions setDimensions(int width, int height) {
this.width = width;
this.height = height;
@@ -124,13 +130,21 @@ private String generateSurfacePlotCommand() {
return "splot " + cmd;
}
+ private String getValueFormat() {
+ final String Y_FORMAT = "%.1s %c";
+ if (displayRate) {
+ return '"' + Y_FORMAT + "/s" + '"';
+ }
+ return '"' + Y_FORMAT + '"';
+ }
+
private String generateLinePointsScript() {
String script = "reset\n";
script += "set terminal " + terminal.toString().toLowerCase()
+ " size " + width + "," + height + "\n";
script += "set xdata time\n";
script += "set timefmt \"%s\"\n";
- script += "set format y \"%.1s %c\"\n";
+ script += "set format y " + getValueFormat() + "\n";
script += "set xtic rotate\n";
if (tsFrom > 0 && tsTo > 0) {
script += "set xrange [\"" + tsFrom + "\":\"" + tsTo + "\"]\n";
@@ -149,8 +163,8 @@ private String generateSurfaceScript() {
+ " size " + width + "," + height + "\n";
script += "set ydata time\n";
script += "set timefmt \"%s\"\n";
- script += "set format z \"%.1s %c\"\n";
- script += "set format cb \"%.1s %c\"\n";
+ script += "set format z " + getValueFormat() + "\n";
+ script += "set format cb " + getValueFormat() + "\n";
script += "set grid\n";
script += "set xtics 1\n";
script += "set hidden3d trianglepattern 7\n";
19 server/src/com/facebook/tsdb/tsdash/server/model/Metric.java
View
@@ -68,6 +68,7 @@ private static void loadAggregators() {
Tag.arrayComparator());
private final HashSet<String> dissolvedTags = new HashSet<String>();
private String aggregatorName = null;
+ private boolean rate = false;
public Metric(byte[] id, String name, IDMap idMap) {
this.id = id;
@@ -225,10 +226,6 @@ public long guessTimeCycle() {
return cycle;
}
- public void addTrailingNulls() {
-
- }
-
public void alignAllTimeSeries() {
long cycle = guessTimeCycle();
// wrap the time stamps to a multiple of cycle
@@ -367,6 +364,20 @@ public Metric dissolveTags(ArrayList<String> tagsName,
return newData;
}
+ /**
+ * replace the time series with the rate of change
+ */
+ public void computeRate() {
+ for (ArrayList<DataPoint> points : timeSeries.values()) {
+ TimeSeries.computeRate(points);
+ }
+ rate = true;
+ }
+
+ public boolean isRate() {
+ return rate;
+ }
+
@SuppressWarnings("unchecked")
private JSONObject encodeTagsSet(HashMap<String, HashSet<String>> tagsSet) {
JSONObject tagsSetObj = new JSONObject();
5 server/src/com/facebook/tsdb/tsdash/server/model/MetricQuery.java
View
@@ -28,6 +28,7 @@
public String[] orders;
public String aggregator = null;
public String[] dissolveTags;
+ public boolean rate = false;
public static HashMap<String, String> decodeTags(JSONObject tagsObj) {
HashMap<String, String> tags = new HashMap<String, String>();
@@ -63,6 +64,9 @@
public static MetricQuery fromJSONObject(JSONObject src) {
MetricQuery newQuery = new MetricQuery();
newQuery.name = (String) src.get("name");
+ if (src.get("rate") != null) {
+ newQuery.rate = (Boolean) src.get("rate");
+ }
newQuery.tags = decodeTags((JSONObject) src.get("tags"));
newQuery.aggregator = (String) src.get("aggregator");
newQuery.orders = decodeArray((JSONArray) src.get("orders"));
@@ -78,6 +82,7 @@ public String toString() {
ret += "orders: " + orders + '\n';
ret += "aggregator: " + aggregator + '\n';
ret += "dissolve: " + dissolveTags + '\n';
+ ret += "rate: " + rate + '\n';
ret += '\n';
return ret;
}
16 server/src/com/facebook/tsdb/tsdash/server/model/TimeSeries.java
View
@@ -119,4 +119,20 @@ private static double linearEq(double x, double x1, double y1, double x2,
}
return aggregated;
}
+
+ /**
+ * Compute the rate for the given timeseries in-place
+ * @param points
+ */
+ public static void computeRate(ArrayList<DataPoint> points) {
+ for (int i = points.size() - 1; i > 0; i--) {
+ DataPoint p1 = points.get(i);
+ DataPoint p0 = points.get(i - 1);
+ double rate = (p1.value - p0.value) / (p1.ts - p0.ts);
+ p1.value = rate;
+ }
+ if (points.size() > 1) {
+ points.get(0).value = points.get(1).value;
+ }
+ }
}
1  ui/src/com/facebook/tsdb/tsdash/client/model/Metric.java
View
@@ -105,6 +105,7 @@ public JSONObject encodeTags() {
public JSONObject toJSONParam() {
JSONObject obj = new JSONObject();
obj.put("name", new JSONString(name));
+ obj.put("rate", JSONBoolean.getInstance(rate));
obj.put("tags", encodeTags());
obj.put("orders", new JSONArray());
if (aggregator == null) {
3  ui/src/com/facebook/tsdb/tsdash/client/ui/MetricWidget.ui.xml
View
@@ -77,6 +77,7 @@ under the License.
text-align: center;
line-height: 20px;
margin-top: 3px;
+ margin-right: 3px;
}
.metric .aggregator {
@@ -130,7 +131,7 @@ under the License.
<g:HTMLPanel styleName="{style.commit}">
<g:Button ui:field="commit" enabled="true">add to plot</g:Button>
</g:HTMLPanel>
- <g:Label visible="false" ui:field="rate" styleName="{style.toggleButton}" title="display the rate - delta/time">/s</g:Label>
+ <g:Label ui:field="rate" styleName="{style.toggleButton}" title="display the rate - delta/time">/s</g:Label>
<g:HTML styleName="clear"></g:HTML>
</g:HTMLPanel>
<g:HTMLPanel styleName="{style.tags}" ui:field="tags">
Please sign in to comment.
Something went wrong with that request. Please try again.