Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
实现App探针广场
Browse files Browse the repository at this point in the history
  • Loading branch information
iwind committed Dec 18, 2018
1 parent afb3219 commit 80b920c
Show file tree
Hide file tree
Showing 14 changed files with 330 additions and 15 deletions.
197 changes: 197 additions & 0 deletions src/main/plugins/jsapps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
var ENGINE = {
"version": 0,
"probes": [function () {
var probe = new ProcessProbe();
probe.id = "tea_1545120945542156984";
probe.name = "ElasticSearch";
probe.site = "https://www.elastic.co";
probe.docSite = "https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html";
probe.developer = "Elasticsearch B.V.";
probe.commandName = "java";
probe.commandPatterns = [ "Elasticsearch" ];
probe.commandVersion = "${commandFile} --version";
probe.onProcess(function (p) {
var args = parseArgs(p.cmdline);
var homeDir = "";
for (var i = 0; i < args.length; i ++) {
var arg = args[i];
var index = arg.indexOf("-Des.path.home=");
if (index < 0) {
continue;
}
homeDir = arg.substring("-Des.path.home=".length);
}
if (homeDir.length > 0) {
p.dir = homeDir;
p.file = homeDir + "/bin/elasticsearch";
}
return true;
});
probe.onParseVersion(function (v) {
return v;
});
probe.run();
},
function () {
var probe = new ProcessProbe(); // 构造对象
probe.author = ""; // 探针作者
probe.id = "tea_1545120945562156984"; // 探针ID,
probe.name = "Apache Http Server"; // App名称
probe.site = "http://httpd.apache.org/"; // App官方网站
probe.docSite = "http://httpd.apache.org/docs/current/"; // 官方文档网址
probe.developer = "The Apache Software Foundation"; // App开发者公司、团队或者个人名称
probe.commandName = "httpd"; // App启动的命令名称
probe.commandPatterns = []; // 进程匹配规则
probe.commandVersion = "${commandFile} -v"; // 获取版本信息的命令

// 进程筛选
probe.onProcess(function (p) {
return true;
});

// 版本信息分析
probe.onParseVersion(function (v) {
return v;
});

// 运行探针
probe.run();
},
function () {
var probe = new ProcessProbe(); // 构造对象
probe.author = ""; // 探针作者
probe.id = "tea_1545123256877858190"; // 探针ID,
probe.name = "PHP-FPM"; // App名称
probe.site = "http://php.net/"; // App官方网站
probe.docSite = "http://php.net/docs.php"; // 官方文档网址
probe.developer = "The PHP Group"; // App开发者公司、团队或者个人名称
probe.commandName = "php-fpm"; // App启动的命令名称
probe.commandPatterns = []; // 进程匹配规则
probe.commandVersion = "${commandFile} -v"; // 获取版本信息的命令

// 进程筛选
probe.onProcess(function (p) {
return true;
});

// 版本信息分析
probe.onParseVersion(function (v) {
var match = v.match(/PHP \d+\.\d+\.\d+/);
if (match) {
return match[0];
}
return v;
});

// 运行探针
probe.run();
},
function () {
var probe = new ProcessProbe(); // 构造对象
probe.author = ""; // 探针作者
probe.id = "tea_1545123416213326756"; // 探针ID,
probe.name = "Redis"; // App名称
probe.site = "https://redis.io/"; // App官方网站
probe.docSite = "https://redis.io/documentation"; // 官方文档网址
probe.developer = "redislabs"; // App开发者公司、团队或者个人名称
probe.commandName = "redis-server"; // App启动的命令名称
probe.commandPatterns = [""]; // 进程匹配规则
probe.commandVersion = "{commandFile} -v"; // 获取版本信息的命令

// 进程筛选
probe.onProcess(function (p) {
return true;
});

// 版本信息分析
probe.onParseVersion(function (v) {
return v;
});

// 运行探针
probe.run();
},
function () {
var probe = new ProcessProbe(); // 构造对象
probe.author = ""; // 探针作者
probe.id = "tea_1545123531232625878"; // 探针ID,
probe.name = "MongoDB"; // App名称
probe.site = "https://www.mongodb.com/"; // App官方网站
probe.docSite = "https://docs.mongodb.com/"; // 官方文档网址
probe.developer = "MongoDB, Inc"; // App开发者公司、团队或者个人名称
probe.commandName = "mongod"; // App启动的命令名称
probe.commandPatterns = ["/mongod"]; // 进程匹配规则
probe.commandVersion = "${commandFile} --version"; // 获取版本信息的命令

// 进程筛选
probe.onProcess(function (p) {
return true;
});

// 版本信息分析
probe.onParseVersion(function (v) {
var match = v.match(/version (v\S+)/);
if (match) {
return match[1];
}
return v;
});

// 运行探针
probe.run();
},
function () {
var probe = new ProcessProbe(); // 构造对象
probe.author = ""; // 探针作者
probe.id = "tea_1545123651698862290"; // 探针ID,
probe.name = "nginx"; // App名称
probe.site = "http://nginx.org/"; // App官方网站
probe.docSite = "http://nginx.org/en/docs/"; // 官方文档网址
probe.developer = "nginx.org"; // App开发者公司、团队或者个人名称
probe.commandName = "nginx"; // App启动的命令名称
probe.commandPatterns = []; // 进程匹配规则
probe.commandVersion = "${commandFile} -v"; // 获取版本信息的命令

// 进程筛选
probe.onProcess(function (p) {
return true;
});

// 版本信息分析
probe.onParseVersion(function (v) {
var index = v.indexOf("nginx version:");
if (index > -1) {
return v.substring("nginx version:".length);
}
return v;
});

// 运行探针
probe.run();
},
function () {
var probe = new ProcessProbe(); // 构造对象
probe.author = ""; // 探针作者
probe.id = "tea_1545123805152211975"; // 探针ID,
probe.name = "MySQL"; // App名称
probe.site = "https://www.mysql.com/"; // App官方网站
probe.docSite = "https://dev.mysql.com/doc/"; // 官方文档网址
probe.developer = "Oracle Corporation"; // App开发者公司、团队或者个人名称
probe.commandName = "mysqld_safe"; // App启动的命令名称
probe.commandPatterns = ["mysqld_safe$"]; // 进程匹配规则
probe.commandVersion = "${commandDir}/mysqld -V"; // 获取版本信息的命令

// 进程筛选
probe.onProcess(function (p) {
return true;
});

// 版本信息分析
probe.onParseVersion(function (v) {
return v;
});

// 运行探针
probe.run();
}]
};
4 changes: 4 additions & 0 deletions src/main/pluginsjsapps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var ENGINE = {
"version": 0,
"probes": []
};
1 change: 0 additions & 1 deletion src/main/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ function build() {

# build main & plugin
go build -o ${TARGET}/bin/teaweb${EXT} ${GOPATH}/src/github.com/TeaWeb/code/main/main.go
go build -o ${TARGET}/plugins/apps.tea${EXT} ${GOPATH}/src/github.com/TeaWeb/plugin/main/apps_plugin.go

if [ -d ${GOPATH}/src/github.com/TeaWeb/jsapps ]
then
Expand Down
12 changes: 10 additions & 2 deletions src/main/views/@default/apps/addProbe.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<div class="ui menu text blue top-menu">
<a href="/apps/probes" class="item">已添加探针</a>
<!--<a href="/apps/square" class="item">探针广场</a>-->
<a href="/apps/square" class="item">探针广场</a>
<a href="/apps/addProbe" class="item active">制作探针</a>
</div>

<div>
<p>在这里可以制作自定义的App服务探测规则,下面表单中标星(*)的为必填项。</p>
<p>在这里可以制作自定义的App服务探针,下面表单中标星(*)的为必填项。</p>

<div class="ui grid one column">
<div class="column">
Expand Down Expand Up @@ -124,6 +124,14 @@
<span v-if="app.version.length > 0">{{app.version}}</span>
</td>
</tr>
<tr>
<td>命令文件</td>
<td>{{app.file}}</td>
</tr>
<tr>
<td>命令目录</td>
<td>{{app.dir}}</td>
</tr>
<tr>
<td>进程</td>
<td>
Expand Down
6 changes: 3 additions & 3 deletions src/main/views/@default/apps/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<p class="ui message error" v-for="message in messages" v-html="message"></p>

<p class="ui message warning" v-if="apps.length == 0">暂时还没有检测到服务。</p>
<p class="ui message warning" v-if="apps.length == 0">暂时还没有检测到服务<a v-if="countProbes == 0" href="/apps/square">去添加服务探针</a></p>

<!-- 已关注的 -->
<div v-if="hasFavoredApps">
Expand All @@ -12,9 +12,9 @@ <h3>已关注</h3>
<table class="ui table selectable" :class="{loading:refreshingAppId == app.id}">
<thead>
<tr>
<th colspan="2">
<th colspan="2" nowrap="">
<i class="icon gem outline" :class="{grey:!app.isRunning, green:app.isRunning}"></i>
{{app.name}} &nbsp;
{{app.name}} &nbsp;
&nbsp;<a href="" title="更多信息" v-on:click.prevent="showApp(app.id)"><i class="ui icon info circle small grey"></i></a>
<a :href="app.site" v-if="app.site.length > 0" target="_blank" title="打开官方网站"><i class="ui icon external small grey"></i> </a>
<a :href="app.docSite" v-if="app.docSite.length > 0" target="_blank" title="打开文档网站"><i class="ui icon book small grey"></i> </a>
Expand Down
1 change: 1 addition & 0 deletions src/main/views/@default/apps/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Tea.context(function () {
.success(function (resp) {
if (resp.data.isChanged) {
this.apps = resp.data.apps;
this.$find(".top.menu .item.active span").html("(" + (this.apps.length) + ")");
}
})
.done(function () {
Expand Down
3 changes: 1 addition & 2 deletions src/main/views/@default/apps/index.html
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
{$layout}

{$layout}
19 changes: 16 additions & 3 deletions src/main/views/@default/apps/probeScript.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@
{$end}

<div class="ui menu text blue top-menu">
<a href="/apps/probes" class="item active">已添加探针</a>
<!--<a href="/apps/square" class="item">探针广场</a>-->
<a href="/apps/probes" class="item" :class="{active:isLocal || fromList}">已添加探针</a>
<a href="/apps/square" class="item" :class="{active:!isLocal && !fromList}">探针广场</a>
<a href="/apps/addProbe" class="item">制作探针</a>
</div>

<p class="comment">下面脚本使用Javascript语言,可以在<a href="https://github.com/TeaWeb/build/blob/master/docs/apps/Probe.md" target="_blank">这里查看API说明文档</a></p>

<div class="editor-box">
<div id="editor"></div>
<div class="buttons-box">
<div class="buttons-box" v-if="isLocal">
<button class="ui button primary" type="button" @click.prevent="save()">保存</button> &nbsp;
<a href="" @click.prevent="test()">试运行</a>
</div>
<div class="buttons-box" v-if="!isLocal">
<span class="comment" v-if="isAdded">正在使用此探针</span>
<button class="ui button" type="button" v-if="!isAdded" @click="addProbe(probeId)">使用这个探针</button> &nbsp;
<a href="" @click.prevent="test()">试运行</a>
</div>
</div>

<!-- 试运行结果 -->
Expand Down Expand Up @@ -63,6 +68,14 @@
<span v-if="app.version.length > 0">{{app.version}}</span>
</td>
</tr>
<tr>
<td>命令文件</td>
<td>{{app.file}}</td>
</tr>
<tr>
<td>命令目录</td>
<td>{{app.dir}}</td>
</tr>
<tr>
<td>进程</td>
<td>
Expand Down
11 changes: 11 additions & 0 deletions src/main/views/@default/apps/probeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,15 @@ Tea.context(function () {
window.location = "/apps/probes";
});
};

this.addProbe = function (probeId) {
this.$post(".copyProbe")
.params({
"probeId": probeId
})
.success(function () {
alert("添加成功");
this.isAdded = true;
});
};
});
11 changes: 11 additions & 0 deletions src/main/views/@default/apps/probes.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
.top-menu {
margin-top: -1em!important;
margin-bottom: 0!important;
}

table tr td span.label {
display: block;
font-size: 0.6em!important;
color: grey;
margin-left: 0.8em!important;
}

table tr td span.label.my {
background: #ccc!important;
}
11 changes: 7 additions & 4 deletions src/main/views/@default/apps/probes.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<div class="ui menu text blue top-menu">
<a href="/apps/probes" class="item active">已添加探针</a>
<!--<a href="/apps/square" class="item">探针广场</a>-->
<a href="/apps/square" class="item">探针广场</a>
<a href="/apps/addProbe" class="item">制作探针</a>
</div>

<div class="ui message error" style="margin-top:0" v-if="error.length > 0">{{error}}</div>
<div class="ui message" style="margin-top:0" v-if="error.length == 0 && probes.length == 0">暂时还没有添加探针。</div>
<div class="ui message" style="margin-top:0" v-if="error.length == 0 && probes.length == 0">暂时还没有添加探针<a href="/apps/square">现在去添加</a></div>

<div v-if="probes.length > 0">
<table class="ui table selectable">
Expand All @@ -22,7 +22,10 @@
</tr>
</thead>
<tr v-for="(probe, index) in probes">
<td><strong>{{probe.name}}</strong></td>
<td><strong>{{probe.name}}</strong>
<span class="ui label tiny my" v-if="probe.isLocal">自定义</span>
<span class="ui label tiny" v-if="!probe.isLocal">官方</span>
</td>
<td>{{probe.commandName}}</td>
<td>
<span v-if="probe.developer.length > 0">{{probe.developer}}</span>
Expand All @@ -37,7 +40,7 @@
<span v-if="probe.docSite.length == 0">-</span>
</td>
<td>
<a :href="'/apps/probeScript?probeId=' + probe.id">脚本</a> &nbsp;
<a :href="'/apps/probeScript?fromList=1&probeId=' + probe.id">脚本</a> &nbsp;
<!--<a href="" @click.prevent="">分享</a> &nbsp;-->
<a href="" @click.prevent="deleteProbe(probe.id)">删除</a>
</td>
Expand Down
Loading

0 comments on commit 80b920c

Please sign in to comment.