This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial version of the pulseui & pulse web services
- Loading branch information
Showing
163 changed files
with
10,342 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
94 changes: 94 additions & 0 deletions
94
server/src/com/facebook/tsdb/pulse/server/DataEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
server/src/com/facebook/tsdb/pulse/server/MetricHeaderEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
server/src/com/facebook/tsdb/pulse/server/MetricsEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.