Permalink
Browse files

initial version of the pulseui & pulse web services

  • Loading branch information...
1 parent e1d0136 commit cdbeaf4e59b64bc1a957ba90b997d3971928b95d @claudiugh claudiugh committed Sep 16, 2011
Showing with 10,342 additions and 8 deletions.
  1. +13 −8 README
  2. +13 −0 server/.classpath
  3. +17 −0 server/.project
  4. +31 −0 server/build.xml
  5. BIN server/lib/guava-r09.jar
  6. BIN server/lib/hadoop-core-0.20-append-r1056497.jar
  7. BIN server/lib/hbase-0.90.3.jar
  8. BIN server/lib/json_simple-1.1.jar
  9. BIN server/lib/log4j-1.2.16.jar
  10. BIN server/lib/servlet-api.jar
  11. BIN server/lib/zookeeper-3.3.2.jar
  12. +94 −0 server/src/com/facebook/tsdb/pulse/server/DataEndpoint.java
  13. +81 −0 server/src/com/facebook/tsdb/pulse/server/MetricHeaderEndpoint.java
  14. +52 −0 server/src/com/facebook/tsdb/pulse/server/MetricsEndpoint.java
  15. +120 −0 server/src/com/facebook/tsdb/pulse/server/PlotEndpoint.java
  16. +100 −0 server/src/com/facebook/tsdb/pulse/server/TsdbServlet.java
  17. +111 −0 server/src/com/facebook/tsdb/pulse/server/data/DataTable.java
  18. +52 −0 server/src/com/facebook/tsdb/pulse/server/data/TimeSeries.java
  19. +33 −0 server/src/com/facebook/tsdb/pulse/server/data/TsdbDataProvider.java
  20. +25 −0 server/src/com/facebook/tsdb/pulse/server/data/TsdbDataProviderException.java
  21. +33 −0 server/src/com/facebook/tsdb/pulse/server/data/TsdbDataProviderFactory.java
  22. +27 −0 server/src/com/facebook/tsdb/pulse/server/data/agg/Aggregator.java
  23. +36 −0 server/src/com/facebook/tsdb/pulse/server/data/agg/AverageAggregator.java
  24. +39 −0 server/src/com/facebook/tsdb/pulse/server/data/agg/MaxAggregator.java
  25. +38 −0 server/src/com/facebook/tsdb/pulse/server/data/agg/MinAggregator.java
  26. +37 −0 server/src/com/facebook/tsdb/pulse/server/data/agg/SumAggregator.java
  27. +45 −0 server/src/com/facebook/tsdb/pulse/server/data/hbase/DataPointQualifier.java
  28. +57 −0 server/src/com/facebook/tsdb/pulse/server/data/hbase/HBaseConnection.java
  29. +183 −0 server/src/com/facebook/tsdb/pulse/server/data/hbase/HBaseDataProvider.java
  30. +124 −0 server/src/com/facebook/tsdb/pulse/server/data/hbase/IDMap.java
  31. +73 −0 server/src/com/facebook/tsdb/pulse/server/data/hbase/IDMapSyncLoader.java
  32. +26 −0 server/src/com/facebook/tsdb/pulse/server/data/hbase/IDNotFoundException.java
  33. +87 −0 server/src/com/facebook/tsdb/pulse/server/data/hbase/RowKey.java
  34. +97 −0 server/src/com/facebook/tsdb/pulse/server/data/hbase/RowRange.java
  35. +52 −0 server/src/com/facebook/tsdb/pulse/server/data/hbase/RowTagComparator.java
  36. +104 −0 server/src/com/facebook/tsdb/pulse/server/data/hbase/RowTagFilter.java
  37. +27 −0 server/src/com/facebook/tsdb/pulse/server/gnuplot/DataSource.java
  38. +86 −0 server/src/com/facebook/tsdb/pulse/server/gnuplot/Gnuplot2D.java
  39. +79 −0 server/src/com/facebook/tsdb/pulse/server/gnuplot/Gnuplot3D.java
  40. +25 −0 server/src/com/facebook/tsdb/pulse/server/gnuplot/GnuplotException.java
  41. +172 −0 server/src/com/facebook/tsdb/pulse/server/gnuplot/GnuplotOptions.java
  42. +142 −0 server/src/com/facebook/tsdb/pulse/server/gnuplot/GnuplotProcess.java
  43. +65 −0 server/src/com/facebook/tsdb/pulse/server/model/DataPoint.java
  44. +58 −0 server/src/com/facebook/tsdb/pulse/server/model/ID.java
  45. +427 −0 server/src/com/facebook/tsdb/pulse/server/model/Metric.java
  46. +83 −0 server/src/com/facebook/tsdb/pulse/server/model/MetricQuery.java
  47. +157 −0 server/src/com/facebook/tsdb/pulse/server/model/Tag.java
  48. +154 −0 server/src/com/facebook/tsdb/pulse/server/model/TagsArray.java
  49. +122 −0 server/src/com/facebook/tsdb/pulse/server/model/TimeSeries.java
  50. +8 −0 ui/.classpath
  51. +28 −0 ui/.project
  52. +8 −0 ui/README
  53. +57 −0 ui/build.xml
  54. BIN ui/lib/gwt-dev.jar
  55. BIN ui/lib/gwt-user.jar
  56. BIN ui/lib/gwt-visualization.jar
  57. BIN ui/lib/validation-api-1.0.0.GA-sources.jar
  58. BIN ui/lib/validation-api-1.0.0.GA.jar
  59. +25 −0 ui/src/com/facebook/tsdb/pulse/Pulse.gwt.xml
  60. +376 −0 ui/src/com/facebook/tsdb/pulse/client/ApplicationController.java
  61. +25 −0 ui/src/com/facebook/tsdb/pulse/client/InvalidApplicationStateException.java
  62. +34 −0 ui/src/com/facebook/tsdb/pulse/client/PulseEntryPoint.java
  63. +62 −0 ui/src/com/facebook/tsdb/pulse/client/event/AutoReloadEvent.java
  64. +25 −0 ui/src/com/facebook/tsdb/pulse/client/event/AutoReloadEventHandler.java
  65. +44 −0 ui/src/com/facebook/tsdb/pulse/client/event/ErrorEvent.java
  66. +23 −0 ui/src/com/facebook/tsdb/pulse/client/event/ErrorEventHandler.java
  67. +51 −0 ui/src/com/facebook/tsdb/pulse/client/event/GraphEvent.java
  68. +24 −0 ui/src/com/facebook/tsdb/pulse/client/event/GraphEventHandler.java
  69. +50 −0 ui/src/com/facebook/tsdb/pulse/client/event/KeyboardShortcutEvent.java
  70. +23 −0 ui/src/com/facebook/tsdb/pulse/client/event/KeyboardShortcutHandler.java
  71. +50 −0 ui/src/com/facebook/tsdb/pulse/client/event/LogEvent.java
  72. +23 −0 ui/src/com/facebook/tsdb/pulse/client/event/LogEventHandler.java
  73. +60 −0 ui/src/com/facebook/tsdb/pulse/client/event/MetricEvent.java
  74. +26 −0 ui/src/com/facebook/tsdb/pulse/client/event/MetricEventHandler.java
  75. +47 −0 ui/src/com/facebook/tsdb/pulse/client/event/MetricHeaderEvent.java
  76. +23 −0 ui/src/com/facebook/tsdb/pulse/client/event/MetricHeaderEventHandler.java
  77. +57 −0 ui/src/com/facebook/tsdb/pulse/client/event/PlotOptionsEvent.java
  78. +23 −0 ui/src/com/facebook/tsdb/pulse/client/event/PlotOptionsEventHandler.java
  79. +31 −0 ui/src/com/facebook/tsdb/pulse/client/event/PresenterEvent.java
  80. +64 −0 ui/src/com/facebook/tsdb/pulse/client/event/StateChangeEvent.java
  81. +28 −0 ui/src/com/facebook/tsdb/pulse/client/event/StateChangeHandler.java
  82. +69 −0 ui/src/com/facebook/tsdb/pulse/client/event/TagEvent.java
  83. +24 −0 ui/src/com/facebook/tsdb/pulse/client/event/TagEventHandler.java
  84. +52 −0 ui/src/com/facebook/tsdb/pulse/client/event/TimeRangeChangeEvent.java
  85. +22 −0 ui/src/com/facebook/tsdb/pulse/client/event/TimeRangeChangeEventHandler.java
  86. +58 −0 ui/src/com/facebook/tsdb/pulse/client/event/ViewChangeEvent.java
  87. +22 −0 ui/src/com/facebook/tsdb/pulse/client/event/ViewChangeEventHandler.java
  88. +136 −0 ui/src/com/facebook/tsdb/pulse/client/model/ApplicationState.java
  89. +45 −0 ui/src/com/facebook/tsdb/pulse/client/model/DataPoint.java
  90. +147 −0 ui/src/com/facebook/tsdb/pulse/client/model/Metric.java
  91. +93 −0 ui/src/com/facebook/tsdb/pulse/client/model/MetricHeader.java
  92. +33 −0 ui/src/com/facebook/tsdb/pulse/client/model/PlotResponse.java
  93. +56 −0 ui/src/com/facebook/tsdb/pulse/client/model/TimeRange.java
  94. +36 −0 ui/src/com/facebook/tsdb/pulse/client/model/TimeSeriesResponse.java
  95. +95 −0 ui/src/com/facebook/tsdb/pulse/client/plot/ImagePlot.java
  96. +122 −0 ui/src/com/facebook/tsdb/pulse/client/plot/InteractivePlot.java
  97. +78 −0 ui/src/com/facebook/tsdb/pulse/client/plot/Plot.java
  98. +254 −0 ui/src/com/facebook/tsdb/pulse/client/presenter/AutoreloadPresenter.java
  99. +91 −0 ui/src/com/facebook/tsdb/pulse/client/presenter/ErrorPresenter.java
  100. +204 −0 ui/src/com/facebook/tsdb/pulse/client/presenter/GraphPresenter.java
  101. +72 −0 ui/src/com/facebook/tsdb/pulse/client/presenter/LogPresenter.java
  102. +446 −0 ui/src/com/facebook/tsdb/pulse/client/presenter/MetricPresenter.java
  103. +114 −0 ui/src/com/facebook/tsdb/pulse/client/presenter/PlotOptionsPresenter.java
  104. +24 −0 ui/src/com/facebook/tsdb/pulse/client/presenter/Presenter.java
  105. +228 −0 ui/src/com/facebook/tsdb/pulse/client/presenter/TimePresenter.java
  106. +95 −0 ui/src/com/facebook/tsdb/pulse/client/presenter/TopMenuPresenter.java
  107. +57 −0 ui/src/com/facebook/tsdb/pulse/client/presenter/WrapPresenter.java
  108. +143 −0 ui/src/com/facebook/tsdb/pulse/client/service/HTTPService.java
  109. +31 −0 ui/src/com/facebook/tsdb/pulse/client/service/ServiceException.java
  110. +34 −0 ui/src/com/facebook/tsdb/pulse/client/service/json/ArrayListDecoder.java
  111. +35 −0 ui/src/com/facebook/tsdb/pulse/client/service/json/ErrorDecoder.java
  112. +48 −0 ui/src/com/facebook/tsdb/pulse/client/service/json/JSONDecoder.java
  113. +31 −0 ui/src/com/facebook/tsdb/pulse/client/service/json/JSONParseException.java
  114. +30 −0 ui/src/com/facebook/tsdb/pulse/client/service/json/MetricHeaderDecoder.java
  115. +41 −0 ui/src/com/facebook/tsdb/pulse/client/service/json/PlotResponseDecoder.java
  116. +54 −0 ui/src/com/facebook/tsdb/pulse/client/service/json/TimeSeriesDecoder.java
  117. +25 −0 ui/src/com/facebook/tsdb/pulse/client/service/json/TimeSeriesException.java
  118. +145 −0 ui/src/com/facebook/tsdb/pulse/client/ui/AutoreloadWidget.java
  119. +108 −0 ui/src/com/facebook/tsdb/pulse/client/ui/AutoreloadWidget.ui.xml
  120. +44 −0 ui/src/com/facebook/tsdb/pulse/client/ui/CssHelper.java
  121. +86 −0 ui/src/com/facebook/tsdb/pulse/client/ui/ErrorWidget.java
  122. +45 −0 ui/src/com/facebook/tsdb/pulse/client/ui/ErrorWidget.ui.xml
  123. +65 −0 ui/src/com/facebook/tsdb/pulse/client/ui/GraphWidget.java
  124. +53 −0 ui/src/com/facebook/tsdb/pulse/client/ui/GraphWidget.ui.xml
  125. +51 −0 ui/src/com/facebook/tsdb/pulse/client/ui/LogEntryWidget.java
  126. +46 −0 ui/src/com/facebook/tsdb/pulse/client/ui/LogEntryWidget.ui.xml
  127. +47 −0 ui/src/com/facebook/tsdb/pulse/client/ui/LogWidget.java
  128. +25 −0 ui/src/com/facebook/tsdb/pulse/client/ui/LogWidget.ui.xml
  129. +56 −0 ui/src/com/facebook/tsdb/pulse/client/ui/MetricOptionWidget.java
  130. +35 −0 ui/src/com/facebook/tsdb/pulse/client/ui/MetricOptionWidget.ui.xml
  131. +224 −0 ui/src/com/facebook/tsdb/pulse/client/ui/MetricWidget.java
  132. +140 −0 ui/src/com/facebook/tsdb/pulse/client/ui/MetricWidget.ui.xml
  133. +126 −0 ui/src/com/facebook/tsdb/pulse/client/ui/MetricsFormWidget.java
  134. +48 −0 ui/src/com/facebook/tsdb/pulse/client/ui/MetricsFormWidget.ui.xml
  135. +167 −0 ui/src/com/facebook/tsdb/pulse/client/ui/PlotOptionsWidget.java
  136. +118 −0 ui/src/com/facebook/tsdb/pulse/client/ui/PlotOptionsWidget.ui.xml
  137. +223 −0 ui/src/com/facebook/tsdb/pulse/client/ui/SelectTimeWidget.java
  138. +136 −0 ui/src/com/facebook/tsdb/pulse/client/ui/SelectTimeWidget.ui.xml
  139. +122 −0 ui/src/com/facebook/tsdb/pulse/client/ui/TagWidget.java
  140. +83 −0 ui/src/com/facebook/tsdb/pulse/client/ui/TagWidget.ui.xml
  141. +87 −0 ui/src/com/facebook/tsdb/pulse/client/ui/TopMenuWidget.java
  142. +35 −0 ui/src/com/facebook/tsdb/pulse/client/ui/TopMenuWidget.ui.xml
  143. BIN ui/war/img/agg.png
  144. BIN ui/war/img/chart_curve.png
  145. BIN ui/war/img/chart_edit.png
  146. BIN ui/war/img/chart_line.png
  147. BIN ui/war/img/clone.png
  148. BIN ui/war/img/close.png
  149. BIN ui/war/img/color.png
  150. BIN ui/war/img/control_stop.png
  151. BIN ui/war/img/cube.png
  152. BIN ui/war/img/gem_remove.png
  153. BIN ui/war/img/info.png
  154. BIN ui/war/img/length-measure.png
  155. BIN ui/war/img/loader.gif
  156. BIN ui/war/img/pulse.ico
  157. BIN ui/war/img/pulse.png
  158. BIN ui/war/img/refresh.png
  159. BIN ui/war/img/right_axis.png
  160. BIN ui/war/img/tag.png
  161. BIN ui/war/img/time.png
  162. +36 −0 ui/war/index.html
  163. +154 −0 ui/war/pulse.css
View
21 README
@@ -1,13 +1,5 @@
This is Pulse, a UI for OpenTSDB (http://opentsdb.net/).
-CONTENTS
---------
-
-server/ - contains the sources for the server that offers a HTTP/JSON API for the UI
-ui/ - GWT sources for the UI
-
-to build each of the parts, run "ant" on both dirs. They can be deployed with any Servlet container. We tested it using Tomcat 7.0.20.
-
LICENSE
-------
@@ -26,3 +18,16 @@ License for the specific language governing permissions and limitations
under the License.
+CONTENTS
+--------
+
+server/ - contains the sources for the server that offers a HTTP/JSON API for the UI
+ui/ - GWT sources for the UI
+
+BUILD
+=====
+
+to build each of the parts, run "ant" on both dirs. They can be deployed with any Servlet container. We tested it using Tomcat 7.0.20.
+
+The projects can also be imported in Eclipse (File > Import > Existing project into workspace).
+For the UI, Google Eclipse Plugin must be installed before importing the project.
View
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="lib" path="lib/servlet-api.jar"/>
+ <classpathentry kind="lib" path="lib/hadoop-core-0.20-append-r1056497.jar"/>
+ <classpathentry kind="lib" path="lib/hbase-0.90.3.jar"/>
+ <classpathentry kind="lib" path="lib/log4j-1.2.16.jar"/>
+ <classpathentry kind="lib" path="lib/zookeeper-3.3.2.jar"/>
+ <classpathentry kind="lib" path="lib/guava-r09.jar"/>
+ <classpathentry kind="lib" path="lib/json_simple-1.1.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>tsdb-pulse-server</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
@@ -0,0 +1,31 @@
+<project name="OpenTSDB - pulse server" default="dist" basedir=".">
+ <description>
+ Build file for tsdb-server
+ </description>
+ <property name="src" location="src"/>
+ <property name="build" location="build"/>
+ <property name="dist" location="dist"/>
+ <property name="lib" location="lib"/>
+
+ <target name="init">
+ <mkdir dir="${build}"/>
+ </target>
+
+ <target name="compile" depends="init"
+ description="compile the source ">
+ <javac srcdir="${src}" destdir="${build}" includeantruntime="false">
+ <classpath>
+ <fileset dir="${lib}" includes="*.jar"/>
+ </classpath>
+ </javac>
+ </target>
+
+ <target name="dist" depends="compile"
+ description="generate the distribution" >
+ <jar jarfile="${build}/tsdb-pulse-server.jar" basedir="${build}"/>
+ </target>
+
+ <target name="clean" description="clean up" >
+ <delete dir="${build}"/>
+ </target>
+</project>
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2011 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.facebook.tsdb.pulse.server;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
+
+import com.facebook.tsdb.pulse.server.data.DataTable;
+import com.facebook.tsdb.pulse.server.data.TsdbDataProvider;
+import com.facebook.tsdb.pulse.server.data.TsdbDataProviderFactory;
+import com.facebook.tsdb.pulse.server.model.Metric;
+import com.facebook.tsdb.pulse.server.model.MetricQuery;
+
+public class DataEndpoint extends TsdbServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings("unchecked")
+ public void doGet(HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ response.setContentType("text/plain");
+ PrintWriter out = response.getWriter();
+ try {
+ long ts = System.currentTimeMillis();
+ // decode parameters
+ String jsonParams = request.getParameter("params");
+ if (jsonParams == null) {
+ throw new Exception("Parameters not specified");
+ }
+ JSONObject jsonParamsObj = (JSONObject) JSONValue.parse(jsonParams);
+ long tsFrom = (Long) jsonParamsObj.get("tsFrom");
+ long tsTo = (Long) jsonParamsObj.get("tsTo");
+ JSONArray metricsArray = (JSONArray) jsonParamsObj.get("metrics");
+ if (metricsArray.size() == 0) {
+ throw new Exception("No metrics to fetch");
+ }
+ MetricQuery[] metricQueries = new MetricQuery[metricsArray.size()];
+ for (int i = 0; i < metricsArray.size(); i++) {
+ metricQueries[i] = MetricQuery.fromJSONObject(
+ (JSONObject) metricsArray.get(i));
+ }
+
+ TsdbDataProvider dataProvider = TsdbDataProviderFactory.get();
+ Metric[] metrics = new Metric[metricQueries.length];
+ for (int i = 0; i < metrics.length; i++) {
+ MetricQuery q = metricQueries[i];
+ metrics[i] = dataProvider.fetchMetric(q.name, tsFrom, tsTo,
+ q.tags, q.orders);
+ metrics[i] = metrics[i].dissolveTags(q.getDissolveList(),
+ q.aggregator);
+ }
+ long loadTime = System.currentTimeMillis() - ts;
+ JSONObject responseObj = new JSONObject();
+ JSONArray encodedMetrics = new JSONArray();
+ for (Metric metric : metrics) {
+ encodedMetrics.add(metric.toJSONObject());
+ }
+ responseObj.put("metrics", encodedMetrics);
+ responseObj.put("loadtime", loadTime);
+ DataTable dataTable = new DataTable(metrics);
+ responseObj.put("datatable", dataTable.toJSONObject());
+ out.println(responseObj.toJSONString());
+ long encodingTime = System.currentTimeMillis() - ts - loadTime;
+ logger.info("[Data] time frame: " + (tsTo - tsFrom) + "s, "
+ + "load time: " + loadTime + "ms, "
+ + "encoding time: " + encodingTime + "ms");
+ } catch (Exception e) {
+ out.println(getErrorResponse(e));
+ }
+ out.close();
+ }
+
+}
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2011 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.facebook.tsdb.pulse.server;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.HashMap;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
+
+import com.facebook.tsdb.pulse.server.data.TsdbDataProvider;
+import com.facebook.tsdb.pulse.server.data.TsdbDataProviderFactory;
+import com.facebook.tsdb.pulse.server.model.Metric;
+import com.facebook.tsdb.pulse.server.model.MetricQuery;
+
+/**
+ * fetches the header information (tags set, common tags) for a given time frame
+ * @author cgheorghe
+ *
+ */
+public class MetricHeaderEndpoint extends TsdbServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * GET params:
+ * "metric" - metric name
+ * "from" - start of the time range
+ * "to" - end of the time range
+ */
+ public void doGet(HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ PrintWriter out = response.getWriter();
+ try {
+ // decode parameters
+ long ts = System.currentTimeMillis();
+ String jsonParams = request.getParameter("params");
+ if (jsonParams == null) {
+ throw new Exception("Parameters not specified");
+ }
+ JSONObject jsonParamsObj = (JSONObject) JSONValue.parse(jsonParams);
+ long tsFrom = (Long) jsonParamsObj.get("tsFrom");
+ long tsTo = (Long) jsonParamsObj.get("tsTo");
+ String metricName = (String) jsonParamsObj.get("metric");
+ HashMap<String, String> tags = MetricQuery.decodeTags(
+ (JSONObject) jsonParamsObj.get("tags"));
+ if (metricName == null) {
+ throw new Exception("Missing parameter");
+ }
+ TsdbDataProvider dataProvider = TsdbDataProviderFactory.get();
+ Metric metric = dataProvider.fetchMetricHeader(metricName, tsFrom,
+ tsTo, tags);
+ out.println(metric.toJSONString());
+ long loadTime = System.currentTimeMillis() - ts;
+ logger.info("[Header] time frame: " + (tsTo - tsFrom) + "s, "
+ + "metric: " + metricName + ", tags: " + tags + ", "
+ + "load time: " + loadTime + "ms");
+ } catch (Exception e) {
+ out.println(getErrorResponse(e));
+ }
+ out.close();
+ }
+}
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2011 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.facebook.tsdb.pulse.server;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.json.simple.JSONArray;
+
+import com.facebook.tsdb.pulse.server.data.TsdbDataProvider;
+import com.facebook.tsdb.pulse.server.data.TsdbDataProviderFactory;
+
+public class MetricsEndpoint extends TsdbServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings("unchecked")
+ public void doGet(HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ PrintWriter out = response.getWriter();
+ try {
+ TsdbDataProvider dataProvider = TsdbDataProviderFactory.get();
+ String[] metrics = dataProvider.getMetrics();
+ response.setContentType("text/plain");
+ JSONArray encoded = new JSONArray();
+ for (String metric : metrics) {
+ encoded.add(metric);
+ }
+ out.println(encoded.toJSONString());
+ } catch (Exception e) {
+ out.println(getErrorResponse(e));
+ }
+ out.close();
+ }
+}
Oops, something went wrong.

0 comments on commit cdbeaf4

Please sign in to comment.