Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #272 from imotai/master
Browse files Browse the repository at this point in the history
已经上线验证,支持多个数据中心trace展示
  • Loading branch information
imotai committed Dec 18, 2015
2 parents c6736ec + 5742b9c commit 4aa18ed
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 278 deletions.
7 changes: 2 additions & 5 deletions platform/src/bootstrap/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
SECRET_KEY = 'pme%=52e+c=_n%gau$6h-=w@+^6l4r8d*-x9a*q5a$ixsk7(^b'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

Expand Down Expand Up @@ -97,8 +96,6 @@
os.path.join(BASE_DIR, "statics"),
)

GALAXY_ADDR=""
DEBUG = True
LUMIA_ADDR="127.0.0.1:8081"

TRACE_QUERY_ENGINE="xxxx"
GALAXY_MASTER="xxxx"
LITE_DB_PATH=os.path.join(BASE_DIR, "dc.json")
4 changes: 4 additions & 0 deletions platform/src/bootstrap/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
(r'^trace/', urls.include('trace.urls')),
)

urlpatterns += urls.patterns('',
(r'^dc/', urls.include('dc.urls')),
)

36 changes: 36 additions & 0 deletions platform/src/statics/tpl/agent.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<h4>{{}}</h4>

<div class="ui four statistics">
<div class="statistic">
<div class="value">
{{agent_total}}
</div>
<div class="label">
机器总数
</div>
</div>
<div class="statistic">
<div class="value">
{{cpu_total}}
</div>
<div class="label">
总cpu核数
</div>
</div>
<div class="statistic">
<div class="value">
{{cpu_total_used}}
</div>
<div class="label">
总cpu使用核数
</div>
</div>
<div class="statistic">
<div class="value">
{{cpu_total_assigned}}
</div>
<div class="label">
已分配cpu数
</div>
</div>
</div>
8 changes: 7 additions & 1 deletion platform/src/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@


<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>

<script>
var ROOT_URL="{{root_url}}";
var MEDIA_URL="{{media_url}}";
var DC="{dc}";
var TRACE="{trace}";
var MASTER="{master}";
</script>
{%block custom-js%}{%endblock%}
</body>
</html>
25 changes: 13 additions & 12 deletions platform/src/templates/cluster.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="{{root_url}}trace/cluster">Cluster</a></li>
<li><a href="{{root_url}}trace/job">Jobs</a></li>
<li><a href="{{root_url}}trace/sql">Trace</a></li>
<li ><a href="{{root_url}}dc">DataCenter</a></li>
<li class="active"><a href="{{root_url}}trace/cluster?master={{master}}&dc={{dc}}&trace={{trace}}">Cluster</a></li>
<li><a href="{{root_url}}trace/job?master={{master}}&dc={{dc}}&trace={{trace}}">Jobs</a></li>
<li><a href="{{root_url}}trace/sql?master={{master}}&dc={{dc}}&trace={{trace}}">Trace</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
Expand Down Expand Up @@ -117,11 +118,11 @@ <h4>Agent Stat Stream</h4>
var today = new Date();
var last = new Date(today.getTime() - (3 * 24 * 60 * 60 * 1000));

var query_cpu_stat = "select time, total_cpu_assigned,total_cpu_millicores,total_cpu_used_millicores from ClusterStat where data_center='yq01' "+
var query_cpu_stat = "select time, total_cpu_assigned,total_cpu_millicores,total_cpu_used_millicores from ClusterStat where data_center='{{dc}}' "+
" and time >= '" + FormatDate(last) + "' and time <='" + FormatDate(today)+ "'";


$.getJSON(ROOT_URL+"trace/squery?limit=5000&db=baidu.galaxy&sql="+ encodeURIComponent(query_cpu_stat),function(data){
$.getJSON(ROOT_URL+"trace/squery?dc={{dc}}&master={{master}}&trace={{trace}}&limit=5000&db=baidu.galaxy&sql="+ encodeURIComponent(query_cpu_stat),function(data){
$('#cluster_cpu_stat').highcharts('StockChart', {
title: {
text: 'cluster cpu stat'
Expand Down Expand Up @@ -154,9 +155,9 @@ <h4>Agent Stat Stream</h4>
series :ProcessCpuStat(data)
});
});
var query_mem_stat = "select time, total_memory_assigned,total_memory,total_memory_used from ClusterStat where data_center='yq01' "+
var query_mem_stat = "select time, total_memory_assigned,total_memory,total_memory_used from ClusterStat where data_center='{{dc}}' "+
" and time >= '" + FormatDate(last) + "' and time <='" + FormatDate(today)+"'";
$.getJSON(ROOT_URL+"trace/squery?db=baidu.galaxy&sql="+ encodeURIComponent(query_mem_stat),function(data){
$.getJSON(ROOT_URL+"trace/squery?dc={{dc}}&master={{master}}&trace={{trace}}&db=baidu.galaxy&sql="+ encodeURIComponent(query_mem_stat),function(data){
$('#cluster_mem_stat').highcharts('StockChart', {
title: {
text: 'cluster memory stat'
Expand Down Expand Up @@ -189,9 +190,9 @@ <h4>Agent Stat Stream</h4>
series :ProcessMemStat(data)
});
});
var query_stable_stat = "select time,total_pod_count,total_node_count, alive_node_count,dead_node_count from ClusterStat where data_center='yq01'"+
var query_stable_stat = "select time,total_pod_count,total_node_count, alive_node_count,dead_node_count from ClusterStat where data_center='{{dc}}'"+
" and time >= '" + FormatDate(last) + "' and time <='" + FormatDate(today)+"'";
$.getJSON(ROOT_URL+"trace/squery?limit=5000&db=baidu.galaxy&sql="+ encodeURIComponent(query_stable_stat),function(data){
$.getJSON(ROOT_URL+"trace/squery?master={{master}}&dc={{dc}}&trace={{trace}}&limit=5000&db=baidu.galaxy&sql="+ encodeURIComponent(query_stable_stat),function(data){
var total_node = new Array;
var total_alive = new Array;
var total_dead = new Array;
Expand Down Expand Up @@ -273,7 +274,7 @@ <h4>Agent Stat Stream</h4>
});
});
var GetCpuStatus = function(){
$.getJSON(ROOT_URL+"trace/status", function(data){
$.getJSON(ROOT_URL+"trace/status?master={{master}}&dc={{dc}}&trace={{trace}}", function(data){
$.get(MEDIA_URL +"/tpl/cpu.tpl", function(tpl){
var overused = data.data.status.cpu_used - data.data.status.cpu_assigned;
if (overused < 0) {
Expand All @@ -293,9 +294,9 @@ <h4>Agent Stat Stream</h4>
GetCpuStatus();
setInterval(GetCpuStatus(), 60 * 1000);
var GetAgentEvent = function(){
var query = "select addr, time, action, data_center from AgentEvent where data_center='yq01' " +
var query = "select addr, ftime, action, data_center,time from AgentEvent where data_center='{{dc}}' " +
" and time >= '" + FormatDate(last) + "' and time <='" + FormatDate(today)+"'";
$.getJSON(ROOT_URL+"trace/squery?limit=5000&db=baidu.galaxy&sql=" + encodeURIComponent(query), function(data) {
$.getJSON(ROOT_URL+"trace/squery?master={{master}}&dc={{dc}}&trace={{trace}}&limit=5000&db=baidu.galaxy&sql=" + encodeURIComponent(query), function(data) {
var events = Mustache.render(data.data.tpl, {datas:data.data.datas});
$("#agent-stat").html(events);
});
Expand Down
100 changes: 100 additions & 0 deletions platform/src/templates/dc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{%extends "base.html"%}
{%block custom-css%}

<link rel="stylesheet" type="text/css" href="{{media_url}}/statistic.css">
<style>
.my-container {
background-color: rgb(247, 247, 249);
border-radius: 1px;
border-style: solid rgb(225, 225, 232) 1px;
padding:3px;
margin-bottom:5px;
}
</style>

{%endblock%}
{%block main%}
<nav class="navbar navbar-toolbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Galaxy</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="{{root_url}}dc">DataCenter</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>

<div class="container my-container" id="real_time_stat">

</div>


<div class="container my-container">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>name</th>
<th>key</th>
<th>master</th>
<th>trace</th>
</tr>
</thead>
{% for dc in dcs%}
<tr>
<td>{{forloop.counter}}</td>
<td><a href="{{root_url}}trace/cluster?dc={{dc.dc}}&master={{dc.master}}&trace={{dc.trace}}">{{dc.name}}</a></td>
<td>{{dc.dc}}</td>
<td>{{dc.master}}</td>
<td>{{dc.trace}}</td>
</tr>
{%endfor%}
</table>
</div> <!-- /container -->
{%endblock%}

{%block custom-js%}
<script src="//code.highcharts.com/stock/highstock.js"></script>
<script src="{{media_url}}/mustache.js"></script>
<script>
Number.prototype.padLeft = function(base,chr){
var len = (String(base || 10).length - String(this).length)+1;
return len > 0? new Array(len).join(chr || '0')+this : this;
}
var ROOT_URL="{{root_url}}";
var MEDIA_URL="{{media_url}}";
var MASTER_LIST= new Array;
{% for dc in dcs %}
MASTER_LIST.push('{{dc.master}}');
{% endfor %}

$(function(){
$.getJSON(ROOT_URL + "trace/dc",function(data){
var agent_total = 0;
var cpu_total = 0;
var cpu_total_used = 0;
var cpu_total_assigned = 0;
for (var index in data.data.status) {
var dc = data.data.status[index];
agent_total += dc.agent_total;
cpu_total += dc.cpu_total/1000;
cpu_total_used += dc.cpu_used/1000;
cpu_total_assigned += dc.cpu_assigned/1000;
}
cpu_total = Math.round(cpu_total);
cpu_total_used = Math.round(cpu_total_used);
cpu_total_assigned = Math.round(cpu_total_assigned);
$.get(MEDIA_URL +"/tpl/agent.tpl", function(tpl){
var dc_info = Mustache.render(tpl,{cpu_total:cpu_total,
agent_total:agent_total,
cpu_total_assigned:cpu_total_assigned,
cpu_total_used:cpu_total_used});
$("#real_time_stat").html(dc_info);
});
});
});
</script>
{%endblock%}
15 changes: 8 additions & 7 deletions platform/src/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="{{root_url}}trace/cluster">Cluster</a></li>
<li class="active"><a href="{{root_url}}trace/job">Jobs</a></li>
<li><a href="{{root_url}}trace/sql">Trace</a></li>

<li><a href="{{root_url}}dc">DataCenter</a></li>
<li><a href="{{root_url}}trace/cluster?master={{master}}&dc={{dc}}&trace={{trace}}">Cluster</a></li>
<li class="active"><a href="{{root_url}}trace/job?master={{master}}&dc={{dc}}&trace={{trace}}">Jobs</a></li>
<li><a href="{{root_url}}trace/sql?master={{master}}&dc={{dc}}&trace={{trace}}">Trace</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
Expand All @@ -37,7 +39,7 @@
{% for job in jobs%}
<tr>
<td>{{forloop.counter}}</td>
<td><a href="{{root_url}}trace/job/detail?jobid={{job.jobid}}">{{job.jobid}}</a></td>
<td><a href="{{root_url}}trace/job/detail?master={{master}}&dc={{dc}}&trace={{trace}}&jobid={{job.jobid}}">{{job.jobid}}</a></td>
<td>{{job.desc.name}}</td>
<td>{{job.state}}</td>
<td>{{job.running_num}}/{{job.pending_num}}/{{job.deploying_num}}</td>
Expand All @@ -58,16 +60,15 @@
var len = (String(base || 10).length - String(this).length)+1;
return len > 0? new Array(len).join(chr || '0')+this : this;
}
var ROOT_URL="{{root_url}}";
var MEDIA_URL="{{media_url}}";

$(function(){
var today = new Date();
var last = new Date(today.getTime() - (3 * 24 * 60 * 60 * 1000));
var start_time = last * 1000;
var end_time = today * 1000;
$("#query_btn").bind("click",function(e){
var sql = encodeURIComponent($("#sql_content").val());
$.getJSON(ROOT_URL+"trace/squery?db=baidu.galaxy&sql="+sql, function(data){
$.getJSON(ROOT_URL+"trace/squery?dc={{dc}}&master={{master}}&trace={{trace}}&db=baidu.galaxy&sql="+sql, function(data){
var tables = Mustache.render(data.data.tpl,{datas:data.data.datas});
$("#datas").html(tables);
});
Expand Down
11 changes: 6 additions & 5 deletions platform/src/templates/job.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="{{root_url}}trace/cluster">Cluster</a></li>
<li class="active"><a href="{{root_url}}trace/job">Jobs</a></li>
<li><a href="{{root_url}}trace/sql">Trace</a></li>
<li><a href="{{root_url}}dc">DataCenter</a></li>
<li><a href="{{root_url}}trace/cluster?master={{master}}&dc={{dc}}&trace={{trace}}">Cluster</a></li>
<li class="active"><a href="{{root_url}}trace/job?master={{master}}&dc={{dc}}&trace={{trace}}">Jobs</a></li>
<li><a href="{{root_url}}trace/sql?master={{master}}&dc={{dc}}&trace={{trace}}">Trace</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
Expand Down Expand Up @@ -79,7 +80,7 @@ <h4>Task Error Stream</h4>
var query_task_stat = "select cmd,agent_addr,pod_id,ftime,error,exit_code,internal_error,deploy,main,gc_dir,ttime from TaskEvent where job_id='" + JOB_ID + "'";//"' and " +
" time >= '" + FormatDate(last) + "' and time <='" + FormatDate(today)+ "'";
var sql = encodeURIComponent(query_task_stat);
$.getJSON(ROOT_URL+"trace/squery?db=baidu.galaxy&sql="+sql, function(data){
$.getJSON(ROOT_URL+"trace/squery?master={{master}}&dc={{dc}}&trace={{trace}}&db=baidu.galaxy&sql="+sql, function(data){
var tasks = Mustache.render(data.data.tpl, {datas:data.data.datas});
$("#tasks").html(tasks);
});
Expand All @@ -104,7 +105,7 @@ <h4>Task Error Stream</h4>
job_stat_stock.push({name:"pending", data:pending});
return job_stat_stock;
}
$.getJSON(ROOT_URL + "trace/squery?db=baidu.galaxy&limit=5000&sql="+encodeURIComponent(query_job), function(data){
$.getJSON(ROOT_URL + "trace/squery?master={{master}}&dc={{dc}}&trace={{trace}}&db=baidu.galaxy&limit=5000&sql="+encodeURIComponent(query_job), function(data){
$('#stable_stat').highcharts('StockChart', {
title: {
text: 'job stabiliztion stat'
Expand Down
10 changes: 1 addition & 9 deletions platform/src/trace/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@
urlpatterns = urls.patterns('trace.views',
(r'^job$', 'job_all'),
(r'^job/detail', 'job_detail'),
(r'^pod/detail', 'pod_detail'),
(r'^job/stat', 'job_stat'),
(r'^job/event', 'job_event'),
(r'^pod$', 'get_pod'),
(r'^pod/stat', 'pod_stat'),
(r'^pod/event', 'pod_event'),
(r'^pod/task', 'task_event'),
(r'^pod/allevent', 'get_pod_event_by_jobid'),
(r'^query$', 'query'),
(r'^squery$', 'squery'),
(r'^sql$', 'sql'),
(r'^cluster$', 'cluster'),
(r'^status$', 'get_real_time_status'),
(r'^dc$', 'get_total_status'),
)

Loading

0 comments on commit 4aa18ed

Please sign in to comment.