Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
xOS committed Feb 8, 2024
1 parent 5eb6d80 commit cb31579
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/dashboard/controller/member_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/xos/serverstatus/pkg/mygin"
"github.com/xos/serverstatus/pkg/utils"
"github.com/xos/serverstatus/proto"
"github.com/xos/serverstatus/resource"
"github.com/xos/serverstatus/service/singleton"
)

Expand All @@ -37,6 +38,7 @@ func (ma *memberAPI) serve() {
mr.GET("/search-server", ma.searchServer)
mr.GET("/search-tasks", ma.searchTask)
mr.POST("/server", ma.addOrEditServer)
mr.POST("/monitor", ma.addOrEditMonitor)
mr.POST("/traffic", ma.addOrEditAlertRule)
mr.POST("/cron", ma.addOrEditCron)
mr.GET("/cron/:id/manual", ma.manualTrigger)
Expand Down
8 changes: 8 additions & 0 deletions cmd/dashboard/controller/member_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (mp *memberPage) serve() {
Redirect: "/login",
}))
mr.GET("/server", mp.server)
mr.GET("/monitor", mp.monitor)
mr.GET("/cron", mp.cron)
mr.GET("/notification", mp.notification)
mr.GET("/setting", mp.setting)
Expand All @@ -48,6 +49,13 @@ func (mp *memberPage) server(c *gin.Context) {
}))
}

func (mp *memberPage) monitor(c *gin.Context) {
c.HTML(http.StatusOK, "dashboard-"+singleton.Conf.Site.DashboardTheme+"/monitor", mygin.CommonEnvironment(c, gin.H{
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "ServicesManagement"}),
"Monitors": singleton.ServiceSentinelShared.Monitors(),
}))
}

func (mp *memberPage) cron(c *gin.Context) {
var crons []model.Cron
singleton.DB.Find(&crons)
Expand Down
6 changes: 6 additions & 0 deletions resource/l10n/en-US.toml
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ other = "To"
[NextCheck]
other = "Next check"

[TrafficTotal]
other = "Total Flow"

[CurrentUsage]
other = "Current Usage"

Expand Down Expand Up @@ -633,3 +636,6 @@ other = "No display to visitors"

[Detail]
other = "Detail"

[NetworkStatus]
other = "Network Fluctuation"
10 changes: 8 additions & 2 deletions resource/l10n/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,20 @@ other = "平均延迟"
other = "流量统计"

[From]
other = ""
other = "起始"

[To]
other = ""
other = "结束"

[NextCheck]
other = "下次检查"

[CurrentUsage]
other = "当前用量"

[TrafficTotal]
other = "总流量"

[VerifyPassword]
other = "验证查看密码"

Expand Down Expand Up @@ -633,3 +636,6 @@ other = "仅管理可见"

[Detail]
other = "配置"

[NetworkStatus]
other = "网络波动"
1 change: 1 addition & 0 deletions resource/template/common/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</a>
{{else}}
<a class="item" href="http://status.nange.cn/" target="_blank"><i class="server icon"></i>{{tr "Services"}}</a>
<a class='item{{if eq .MatchedPath "/network"}} active{{end}}' href="/network"><i class="bi bi-hdd-network icon"></i>{{tr "NetworkStatus"}}</a>
{{end}}
<div class="right menu">
<div class="item">
Expand Down
233 changes: 233 additions & 0 deletions resource/template/common/network.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
{{define "common/network"}}{{template "common/header" .}} {{if ts .CustomCode}} {{.CustomCode|safe}} {{end}}{{template "common/menu" .}}
<div id="network" class="nb-container">
<div class="ui container">
<div class="service-status">
<div class="ui icon button"
v-for='server in servers'
:id="server.ID"
style="margin-top: 3px"
@click="redirectNetwork(server.ID)">
@#server.Name#@<i :class="server.Host.CountryCode + ' flag'"></i>&nbsp;<i
v-if='server.Host.Platform == "darwin"' class="apple icon"></i><i
v-else-if='isWindowsPlatform(server.Host.Platform)' class="windows icon"></i><i
v-else :class="'fl-' + getFontLogoClass(server.Host.Platform)"></i>
</div>
<div ref="chartDom" style="border-radius: 28px; margin-top: 15px;height: 520px;max-width: 1400px;overflow: hidden"></div>
</div>
</div>
</div>

{{template "theme-custom/footer" .}}
<script>
const monitorInfo = JSON.parse('{{.MonitorInfos}}');
const initData = JSON.parse('{{.Servers}}').servers;
// 基于准备好的dom,初始化echarts实例
// var myChart = echarts.init(document.getElementById('monitor-info-container'));
// 使用刚指定的配置项和数据显示图表。
var statusCards = new Vue({
el: '#network',
delimiters: ['@#', '#@'],
data: {
servers: initData,
cache: [],
option: {
tooltip: {
trigger: 'axis',
position: function (pt) {
return [pt[0], '10%'];
},
formatter: function(params){
let result = params[0].axisValueLabel + "<br />";
params.forEach(function(item){
result += item.marker + item.seriesName + ": " + item.value[1].toFixed(2) + " ms<br />";
})
return result;
},
confine: true,
transitionDuration: 0
},
title: {
left: 'center',
text: "",
textStyle: {}
},
legend: {
top: '5%',
data: [],
textStyle: {
fontSize: 14
}
},
backgroundColor: 'rgba(255, 255, 255, 0.8)',
toolbox: {
feature: {
dataZoom: {
yAxisIndex: 'none'
},
restore: {},
saveAsImage: {}
}
},
dataZoom: [
{
start: 94,
end: 100
}
],
xAxis: {
type: 'time',
boundaryGap: false
},
yAxis: {
type: 'value',
boundaryGap: [0, '100%']
},
series: [],
},
isHover: false,
chartOnOff: true
},
mounted() {
this.renderChart();
this.parseMonitorInfo(monitorInfo);
this.myChart.on('legendselectchanged', function(obj) {
var selected = obj.selected;
var legend = obj.name;
// 使用 legendToggleSelect Action 会重新触发 legendselectchanged Event,导致本函数重复运行
// 使得 无 selected 对象
var vm = network.__vue__;
if (selected != undefined && vm.isFirstUnSelect(selected) && vm.chartOnOff) {
vm.triggerAction('legendToggleSelect', selected);
vm.chartOnOff = false;
}
});
},
methods: {
redirectNetwork(id) {
this.getMonitorHistory(id)
.then(function(monitorInfo) {
var vm = network.__vue__;
vm.parseMonitorInfo(monitorInfo);
})
.catch(function(error){
window.location.href = "/404";
})
},
getMonitorHistory(id) {
return $.ajax({
url: "/api/v1/monitor/"+id,
method: "GET"
});
},
parseMonitorInfo(monitorInfo) {
let tSeries = [];
let tLegendData = [];
for (let i = 0; i < monitorInfo.result.length; i++) {
let data = [];
for (let j = 0; j < monitorInfo.result[i].created_at.length; j++) {
data.push([monitorInfo.result[i].created_at[j],monitorInfo.result[i].avg_delay[j]]);
}
tLegendData.push(monitorInfo.result[i].monitor_name);
tSeries.push({
name: monitorInfo.result[i].monitor_name,
type: 'line',
smooth: true,
symbol: 'none',
data: data
});
}
this.option.title.text = monitorInfo.result[0].server_name;
this.option.series = tSeries;
this.option.legend.data = tLegendData;
this.myChart.clear();
this.myChart.setOption(this.option);
},
isWindowsPlatform(str) {
return str.includes('Windows')
},
getFontLogoClass(str) {
if (["almalinux",
"alpine",
"aosc",
"apple",
"archlinux",
"archlabs",
"artix",
"budgie",
"centos",
"coreos",
"debian",
"deepin",
"devuan",
"docker",
"elementary",
"fedora",
"ferris",
"flathub",
"freebsd",
"gentoo",
"gnu-guix",
"illumos",
"kali-linux",
"linuxmint",
"mageia",
"mandriva",
"manjaro",
"nixos",
"openbsd",
"opensuse",
"pop-os",
"raspberry-pi",
"redhat",
"rocky-linux",
"sabayon",
"slackware",
"snappy",
"solus",
"tux",
"ubuntu",
"void",
"zorin"].indexOf(str)
> -1) {
return str;
}
},
renderChart() {
this.myChart = echarts.init(this.$refs.chartDom);
this.myChart.setOption(this.option);
},
triggerAction(action, selected) {
legend = [];
for (name in selected) {
if (selected.hasOwnProperty(name)) {
legend.push({
name: name
});
}
}

this.myChart.dispatchAction({
type: action,
batch: legend
});
},
isFirstUnSelect(selected) {
var unSelectedCount = 0;
for (name in selected) {
if (!selected.hasOwnProperty(name)) {
continue;
}
if (selected[name] == false) {
unSelectedCount++;
}
}
return unSelectedCount == 1;
},
},
beforeDestroy() {
this.myChart.dispose();
this.myChart = null;
},
});
</script>
{{end}}

0 comments on commit cb31579

Please sign in to comment.