Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
initial version of the pulseui & pulse web services
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiugh committed Sep 16, 2011
1 parent e1d0136 commit cdbeaf4
Show file tree
Hide file tree
Showing 163 changed files with 10,342 additions and 8 deletions.
21 changes: 13 additions & 8 deletions 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
-------

Expand All @@ -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.
13 changes: 13 additions & 0 deletions server/.classpath
@@ -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>
17 changes: 17 additions & 0 deletions server/.project
@@ -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>
31 changes: 31 additions & 0 deletions server/build.xml
@@ -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 added server/lib/guava-r09.jar
Binary file not shown.
Binary file added server/lib/hadoop-core-0.20-append-r1056497.jar
Binary file not shown.
Binary file added server/lib/hbase-0.90.3.jar
Binary file not shown.
Binary file added server/lib/json_simple-1.1.jar
Binary file not shown.
Binary file added server/lib/log4j-1.2.16.jar
Binary file not shown.
Binary file added server/lib/servlet-api.jar
Binary file not shown.
Binary file added server/lib/zookeeper-3.3.2.jar
Binary file not shown.
94 changes: 94 additions & 0 deletions server/src/com/facebook/tsdb/pulse/server/DataEndpoint.java
@@ -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();
}
}
52 changes: 52 additions & 0 deletions server/src/com/facebook/tsdb/pulse/server/MetricsEndpoint.java
@@ -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();
}
}

0 comments on commit cdbeaf4

Please sign in to comment.