Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 2bdcae1

Browse files
committed
TAJO-1711: Add basic monitoring page.
1 parent 81ab265 commit 2bdcae1

File tree

14 files changed

+1576
-28
lines changed

14 files changed

+1576
-28
lines changed

tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.apache.tajo.util.metrics.TajoSystemMetrics;
6666
import org.apache.tajo.webapp.QueryExecutorServlet;
6767
import org.apache.tajo.webapp.StaticHttpServer;
68+
import org.apache.tajo.webapp.servlet.MasterMetricsServlet;
6869
import org.apache.tajo.ws.rs.TajoRestService;
6970

7071
import java.io.IOException;
@@ -235,6 +236,7 @@ private void initWebServer() throws Exception {
235236
webServer = StaticHttpServer.getInstance(this ,"admin", address.getHostName(), address.getPort(),
236237
true, null, context.getConf(), null);
237238
webServer.addServlet("queryServlet", "/query_exec", QueryExecutorServlet.class);
239+
webServer.addServlet("masterMetricsServlet", "/metrics", MasterMetricsServlet.class);
238240
webServer.start();
239241
}
240242
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.tajo.webapp.servlet;
20+
21+
import org.apache.hadoop.util.StringUtils;
22+
import org.codehaus.jackson.map.ObjectMapper;
23+
24+
import javax.servlet.http.HttpServlet;
25+
import javax.servlet.http.HttpServletResponse;
26+
import java.io.IOException;
27+
import java.io.NotSerializableException;
28+
import java.io.OutputStream;
29+
import java.util.Calendar;
30+
import java.util.HashMap;
31+
import java.util.Map;
32+
33+
public abstract class AbstractExecutorServlet extends HttpServlet {
34+
protected transient ObjectMapper om = new ObjectMapper();
35+
36+
protected void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {
37+
throw new NotSerializableException( getClass().getName() );
38+
}
39+
40+
protected void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, ClassNotFoundException {
41+
throw new NotSerializableException( getClass().getName() );
42+
}
43+
44+
protected void errorResponse(HttpServletResponse response, Exception e) throws IOException {
45+
errorResponse(response, e, null);
46+
}
47+
48+
protected void errorResponse(HttpServletResponse response, Exception e, String type) throws IOException {
49+
errorResponse(response, e.getMessage() + "\n" + StringUtils.stringifyException(e), type);
50+
}
51+
52+
protected void errorResponse(HttpServletResponse response, String message) throws IOException {
53+
errorResponse(response, message, null);
54+
}
55+
56+
protected void errorResponse(HttpServletResponse response, String message, String type) throws IOException {
57+
Map<String, Object> errorMessage = new HashMap<String, Object>();
58+
errorMessage.put("success", "false");
59+
errorMessage.put("errorMessage", message);
60+
errorMessage.put("timestamp", Calendar.getInstance().getTimeInMillis());
61+
writeHttpResponse(response, errorMessage, type);
62+
}
63+
64+
protected void writeHttpResponse(HttpServletResponse response, Map<String, Object> outputMessage) throws IOException {
65+
writeHttpResponse(response, outputMessage, null);
66+
}
67+
68+
protected void writeHttpResponse(HttpServletResponse response, Map<String, Object> outputMessage, String type) throws IOException {
69+
if(type==null){
70+
type = "text/html";
71+
}
72+
response.setContentType(type);
73+
74+
OutputStream out = response.getOutputStream();
75+
out.write(om.writeValueAsBytes(outputMessage));
76+
77+
out.flush();
78+
out.close();
79+
}
80+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.tajo.webapp.servlet;
20+
21+
import com.codahale.metrics.Metric;
22+
import com.codahale.metrics.MetricFilter;
23+
import org.apache.commons.logging.Log;
24+
import org.apache.commons.logging.LogFactory;
25+
import org.apache.tajo.master.TajoMaster;
26+
import org.apache.tajo.util.metrics.TajoSystemMetrics;
27+
import org.apache.tajo.webapp.StaticHttpServer;
28+
import org.codehaus.jackson.map.DeserializationConfig;
29+
30+
import javax.servlet.ServletConfig;
31+
import javax.servlet.ServletException;
32+
import javax.servlet.http.HttpServletRequest;
33+
import javax.servlet.http.HttpServletResponse;
34+
import java.io.IOException;
35+
import java.util.*;
36+
37+
public class MasterMetricsServlet extends AbstractExecutorServlet {
38+
private static final Log LOG = LogFactory.getLog(MasterMetricsServlet.class);
39+
private static final long serialVersionUID = -1517586415474706579L;
40+
41+
@Override
42+
public void init(ServletConfig config) throws ServletException {
43+
om.getDeserializationConfig().disable(
44+
DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
45+
}
46+
47+
@Override
48+
public void service(HttpServletRequest request,
49+
HttpServletResponse response) throws ServletException, IOException {
50+
String action = request.getParameter("action");
51+
String type = request.getParameter("type");
52+
if(type!=null && type.equalsIgnoreCase("json")){
53+
type = "application/json";
54+
} else {
55+
type = "text/html";
56+
}
57+
Map<String, Object> returnValue = new HashMap<String, Object>();
58+
try {
59+
if(action == null || action.trim().isEmpty()) {
60+
errorResponse(response, "no action parameter.");
61+
return;
62+
}
63+
if("getMetrics".equals(action)) {
64+
TajoMaster master = (TajoMaster) StaticHttpServer.getInstance().getAttribute("tajo.info.server.object");
65+
if(master!=null){
66+
TajoSystemMetrics systemMetrics = master.getContext().getMetrics();
67+
TreeMap<String, Metric> treeMap = new TreeMap<String, Metric>( systemMetrics.getMetrics() );
68+
Iterator<String> iteratorKey = treeMap.keySet().iterator( );
69+
returnValue.put("metrics", treeMap/*systemMetrics.getMetrics()*/);
70+
} else {
71+
returnValue.put("metrics", new TreeMap<String, Metric>());
72+
}
73+
}
74+
returnValue.put("success", "true");
75+
returnValue.put("timestamp", Calendar.getInstance().getTimeInMillis());
76+
writeHttpResponse(response, returnValue, type);
77+
} catch (Exception e) {
78+
LOG.error(e.getMessage(), e);
79+
errorResponse(response, e, type);
80+
}
81+
}
82+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.tajo.webapp.servlet;
20+
21+
import com.codahale.metrics.Metric;
22+
import com.codahale.metrics.MetricFilter;
23+
import org.apache.commons.logging.Log;
24+
import org.apache.commons.logging.LogFactory;
25+
import org.apache.tajo.util.metrics.TajoSystemMetrics;
26+
import org.apache.tajo.webapp.StaticHttpServer;
27+
import org.apache.tajo.worker.TajoWorker;
28+
import org.codehaus.jackson.map.DeserializationConfig;
29+
30+
import javax.servlet.ServletConfig;
31+
import javax.servlet.ServletException;
32+
import javax.servlet.http.HttpServletRequest;
33+
import javax.servlet.http.HttpServletResponse;
34+
import java.io.IOException;
35+
import java.util.*;
36+
37+
public class WorkerMetricsServlet extends AbstractExecutorServlet {
38+
private static final Log LOG = LogFactory.getLog(WorkerMetricsServlet.class);
39+
private static final long serialVersionUID = -1517586415428296579L;
40+
41+
@Override
42+
public void init(ServletConfig config) throws ServletException {
43+
om.getDeserializationConfig().disable(
44+
DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
45+
}
46+
47+
@Override
48+
public void service(HttpServletRequest request,
49+
HttpServletResponse response) throws ServletException, IOException {
50+
String action = request.getParameter("action");
51+
String type = request.getParameter("type");
52+
if(type!=null && type.equalsIgnoreCase("json")){
53+
type = "application/json";
54+
} else {
55+
type = "text/html";
56+
}
57+
Map<String, Object> returnValue = new HashMap<String, Object>();
58+
try {
59+
if(action == null || action.trim().isEmpty()) {
60+
errorResponse(response, "no action parameter.");
61+
return;
62+
}
63+
if("getMetrics".equals(action)) {
64+
TajoWorker worker = (TajoWorker) StaticHttpServer.getInstance().getAttribute("tajo.info.server.object");
65+
if(worker!=null){
66+
TajoSystemMetrics systemMetrics = worker.getWorkerContext().getMetrics();
67+
TreeMap<String, Metric> treeMap = new TreeMap<String, Metric>(systemMetrics.getMetrics());
68+
Iterator<String> iteratorKey = treeMap.keySet().iterator();
69+
returnValue.put("metrics", treeMap/*systemMetrics.getMetrics()*/);
70+
} else {
71+
returnValue.put("metrics", new TreeMap<String, Metric>());
72+
}
73+
}
74+
returnValue.put("success", "true");
75+
returnValue.put("timestamp", Calendar.getInstance().getTimeInMillis());
76+
writeHttpResponse(response, returnValue, type);
77+
} catch (Exception e) {
78+
LOG.error(e.getMessage(), e);
79+
errorResponse(response, e, type);
80+
}
81+
}
82+
}

tajo-core/src/main/java/org/apache/tajo/worker/TajoWorker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.apache.tajo.util.history.HistoryWriter;
5757
import org.apache.tajo.util.metrics.TajoSystemMetrics;
5858
import org.apache.tajo.webapp.StaticHttpServer;
59+
import org.apache.tajo.webapp.servlet.WorkerMetricsServlet;
5960

6061
import java.io.IOException;
6162
import java.io.PrintWriter;
@@ -224,6 +225,7 @@ private int initWebServer() {
224225
try {
225226
webServer = StaticHttpServer.getInstance(this, "worker", null, httpPort,
226227
true, null, systemConf, null);
228+
webServer.addServlet("workerMetricsServlet", "/metrics", WorkerMetricsServlet.class);
227229
webServer.start();
228230
httpPort = webServer.getPort();
229231
LOG.info("Worker info server started:" + httpPort);

tajo-core/src/main/resources/tajo-metrics.properties

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,53 @@ reporter.ganglia=org.apache.tajo.util.metrics.reporter.GangliaReporter
3131
###############################################################################
3232

3333
###############################################################################
34-
# tajo master
34+
# MASTER
3535
###############################################################################
36-
tajomaster.reporters=null
37-
38-
#tajomaster.reporters=file,console
39-
#tajomaster.console.period=60
40-
#tajomaster.file.filename=/tmp/tajo/tajomaster-metrics.out
41-
#tajomaster.file.period=60
42-
#tajomaster.ganglia.server=my.ganglia.com
43-
#tajomaster.ganglia.port=8649
44-
#tajomaster.ganglia.period=60
36+
MASTER.reporters=null
37+
#MASTER.reporters=file,console,ganglia
38+
#MASTER.file.filename=/tmp/tajo/master-metrics.log
39+
#MASTER.file.period=60
40+
#MASTER.console.period=60
41+
#MASTER.ganglia.server=my.ganglia.com
42+
#MASTER.ganglia.port=8649
43+
#MASTER.ganglia.period=60
4544
###############################################################################
4645

4746
###############################################################################
48-
# tajo master-jvm
47+
# MASTER-JVM
4948
###############################################################################
50-
tajomaster-jvm.reporters=null
51-
#tajomaster-jvm.reporters=console
52-
#tajomaster-jvm.console.period=60
53-
#tajomaster-jvm.file.filename=/tmp/tajo/tajomaster-jvm-metrics.out
54-
#tajomaster-jvm.file.period=60
49+
MASTER-JVM.reporters=null
50+
#MASTER-JVM.reporters=file,console,ganglia
51+
#MASTER-JVM.file.filename=/tmp/tajo/master-jvm-metrics.log
52+
#MASTER-JVM.file.period=60
53+
#MASTER-JVM.console.period=60
54+
#MASTER-JVM.ganglia.server=my.ganglia.com
55+
#MASTER-JVM.ganglia.port=8649
56+
#MASTER-JVM.ganglia.period=60
5557
###############################################################################
5658

5759
###############################################################################
58-
# worker
60+
# NODE
5961
###############################################################################
60-
worker.reporters=null
61-
#worker.reporters=file,console
62-
#worker.console.period=60
63-
#worker.file.filename=/tmp/tajo/worker-metrics.out
64-
#worker.file.period=60
62+
NODE.reporters=null
63+
#NODE.reporters=file,console,ganglia
64+
#NODE.file.filename=/tmp/tajo/node-metrics.log
65+
#NODE.file.period=60
66+
#NODE.console.period=60
67+
#NODE.ganglia.server=my.ganglia.com
68+
#NODE.ganglia.port=8649
69+
#NODE.ganglia.period=60
6570
###############################################################################
6671

6772
###############################################################################
68-
# worker-jvm
73+
# NODE-JVM
6974
###############################################################################
70-
worker-jvm.reporters=null
71-
#worker-jvm.reporters=console
72-
#worker-jvm.console.period=60
73-
#worker-jvm.file.filename=/tmp/tajo/worker-jvm-metrics.out
74-
#worker-jvm.file.period=60
75+
NODE-JVM.reporters=null
76+
#NODE-JVM.reporters=file,console,ganglia
77+
#NODE-JVM.file.filename=/tmp/tajo/node-jvm-metrics.log
78+
#NODE-JVM.file.period=60
79+
#NODE-JVM.console.period=60
80+
#NODE-JVM.ganglia.server=my.ganglia.com
81+
#NODE-JVM.ganglia.port=8649
82+
#NODE-JVM.ganglia.period=60
7583
###############################################################################

tajo-core/src/main/resources/webapps/admin/header.jsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<li><a class='top_menu_item' href='query.jsp'>Query</a></li>
2727
<li><a class='top_menu_item' href='catalogview.jsp'>Catalog</a></li>
2828
<li><a class='top_menu_item' href='query_executor.jsp'>Execute Query</a></li>
29+
<li><a class='top_menu_item' href='monitoring.jsp'>Monitoring</a></li>
2930
</ul>
3031
<br style='clear:left'/>
3132
</div>

0 commit comments

Comments
 (0)