mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-17 22:30:25 +08:00
Dashboard增加指标图表
This commit is contained in:
@@ -143,7 +143,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
// 指标
|
// 指标
|
||||||
{
|
{
|
||||||
var chartMaps = []maps.Map{}
|
var chartMaps = []maps.Map{}
|
||||||
for _, chart := range resp.MetricCharts {
|
for _, chart := range resp.MetricDataCharts {
|
||||||
var statMaps = []maps.Map{}
|
var statMaps = []maps.Map{}
|
||||||
for _, stat := range chart.MetricStats {
|
for _, stat := range chart.MetricStats {
|
||||||
statMaps = append(statMaps, maps.Map{
|
statMaps = append(statMaps, maps.Map{
|
||||||
@@ -169,6 +169,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
"period": chart.MetricChart.MetricItem.Period,
|
"period": chart.MetricChart.MetricItem.Period,
|
||||||
"periodUnit": chart.MetricChart.MetricItem.PeriodUnit,
|
"periodUnit": chart.MetricChart.MetricItem.PeriodUnit,
|
||||||
"valueType": serverconfigs.FindMetricValueType(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
"valueType": serverconfigs.FindMetricValueType(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
||||||
|
"valueTypeName": serverconfigs.FindMetricValueName(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
||||||
},
|
},
|
||||||
"stats": statMaps,
|
"stats": statMaps,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
// 指标
|
// 指标
|
||||||
{
|
{
|
||||||
var chartMaps = []maps.Map{}
|
var chartMaps = []maps.Map{}
|
||||||
for _, chart := range resp.MetricCharts {
|
for _, chart := range resp.MetricDataCharts {
|
||||||
var statMaps = []maps.Map{}
|
var statMaps = []maps.Map{}
|
||||||
for _, stat := range chart.MetricStats {
|
for _, stat := range chart.MetricStats {
|
||||||
statMaps = append(statMaps, maps.Map{
|
statMaps = append(statMaps, maps.Map{
|
||||||
@@ -191,6 +191,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
"period": chart.MetricChart.MetricItem.Period,
|
"period": chart.MetricChart.MetricItem.Period,
|
||||||
"periodUnit": chart.MetricChart.MetricItem.PeriodUnit,
|
"periodUnit": chart.MetricChart.MetricItem.PeriodUnit,
|
||||||
"valueType": serverconfigs.FindMetricValueType(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
"valueType": serverconfigs.FindMetricValueType(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
||||||
|
"valueTypeName": serverconfigs.FindMetricValueName(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
||||||
},
|
},
|
||||||
"stats": statMaps,
|
"stats": statMaps,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
@@ -206,5 +207,42 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 指标
|
||||||
|
{
|
||||||
|
var chartMaps = []maps.Map{}
|
||||||
|
for _, chart := range resp.MetricDataCharts {
|
||||||
|
var statMaps = []maps.Map{}
|
||||||
|
for _, stat := range chart.MetricStats {
|
||||||
|
statMaps = append(statMaps, maps.Map{
|
||||||
|
"keys": stat.Keys,
|
||||||
|
"time": stat.Time,
|
||||||
|
"value": stat.Value,
|
||||||
|
"count": stat.SumCount,
|
||||||
|
"total": stat.SumTotal,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
chartMaps = append(chartMaps, maps.Map{
|
||||||
|
"chart": maps.Map{
|
||||||
|
"id": chart.MetricChart.Id,
|
||||||
|
"name": chart.MetricChart.Name,
|
||||||
|
"widthDiv": chart.MetricChart.WidthDiv,
|
||||||
|
"isOn": chart.MetricChart.IsOn,
|
||||||
|
"maxItems": chart.MetricChart.MaxItems,
|
||||||
|
"type": chart.MetricChart.Type,
|
||||||
|
},
|
||||||
|
"item": maps.Map{
|
||||||
|
"id": chart.MetricChart.MetricItem.Id,
|
||||||
|
"name": chart.MetricChart.MetricItem.Name,
|
||||||
|
"period": chart.MetricChart.MetricItem.Period,
|
||||||
|
"periodUnit": chart.MetricChart.MetricItem.PeriodUnit,
|
||||||
|
"valueType": serverconfigs.FindMetricValueType(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
||||||
|
"valueTypeName": serverconfigs.FindMetricValueName(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
||||||
|
},
|
||||||
|
"stats": statMaps,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["metricCharts"] = chartMaps
|
||||||
|
}
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
@@ -167,5 +168,42 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 指标
|
||||||
|
{
|
||||||
|
var chartMaps = []maps.Map{}
|
||||||
|
for _, chart := range resp.MetricDataCharts {
|
||||||
|
var statMaps = []maps.Map{}
|
||||||
|
for _, stat := range chart.MetricStats {
|
||||||
|
statMaps = append(statMaps, maps.Map{
|
||||||
|
"keys": stat.Keys,
|
||||||
|
"time": stat.Time,
|
||||||
|
"value": stat.Value,
|
||||||
|
"count": stat.SumCount,
|
||||||
|
"total": stat.SumTotal,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
chartMaps = append(chartMaps, maps.Map{
|
||||||
|
"chart": maps.Map{
|
||||||
|
"id": chart.MetricChart.Id,
|
||||||
|
"name": chart.MetricChart.Name,
|
||||||
|
"widthDiv": chart.MetricChart.WidthDiv,
|
||||||
|
"isOn": chart.MetricChart.IsOn,
|
||||||
|
"maxItems": chart.MetricChart.MaxItems,
|
||||||
|
"type": chart.MetricChart.Type,
|
||||||
|
},
|
||||||
|
"item": maps.Map{
|
||||||
|
"id": chart.MetricChart.MetricItem.Id,
|
||||||
|
"name": chart.MetricChart.MetricItem.Name,
|
||||||
|
"period": chart.MetricChart.MetricItem.Period,
|
||||||
|
"periodUnit": chart.MetricChart.MetricItem.PeriodUnit,
|
||||||
|
"valueType": serverconfigs.FindMetricValueType(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
||||||
|
"valueTypeName": serverconfigs.FindMetricValueName(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
||||||
|
},
|
||||||
|
"stats": statMaps,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["metricCharts"] = chartMaps
|
||||||
|
}
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/metrics/charts/chartutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/metrics/charts/chartutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/metrics/metricutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/metrics/metricutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ChartAction struct {
|
type ChartAction struct {
|
||||||
@@ -31,5 +33,8 @@ func (this *ChartAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var itemMap = this.Data["item"].(maps.Map)
|
||||||
|
itemMap["valueTypeName"] = serverconfigs.FindMetricValueName(itemMap.GetString("category"), itemMap.GetString("value"))
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
// 指标
|
// 指标
|
||||||
{
|
{
|
||||||
var chartMaps = []maps.Map{}
|
var chartMaps = []maps.Map{}
|
||||||
for _, chart := range resp.MetricCharts {
|
for _, chart := range resp.MetricDataCharts {
|
||||||
var statMaps = []maps.Map{}
|
var statMaps = []maps.Map{}
|
||||||
for _, stat := range chart.MetricStats {
|
for _, stat := range chart.MetricStats {
|
||||||
statMaps = append(statMaps, maps.Map{
|
statMaps = append(statMaps, maps.Map{
|
||||||
@@ -143,6 +143,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
"period": chart.MetricChart.MetricItem.Period,
|
"period": chart.MetricChart.MetricItem.Period,
|
||||||
"periodUnit": chart.MetricChart.MetricItem.PeriodUnit,
|
"periodUnit": chart.MetricChart.MetricItem.PeriodUnit,
|
||||||
"valueType": serverconfigs.FindMetricValueType(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
"valueType": serverconfigs.FindMetricValueType(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
||||||
|
"valueTypeName": serverconfigs.FindMetricValueName(chart.MetricChart.MetricItem.Category, chart.MetricChart.MetricItem.Value),
|
||||||
},
|
},
|
||||||
"stats": statMaps,
|
"stats": statMaps,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// 指标图表
|
// 指标图表
|
||||||
Vue.component("metric-chart", {
|
Vue.component("metric-chart", {
|
||||||
props: ["v-chart", "v-stats", "v-period-unit", "v-value-type"],
|
props: ["v-chart", "v-stats", "v-item"],
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
this.load()
|
this.load()
|
||||||
},
|
},
|
||||||
@@ -38,8 +38,10 @@ Vue.component("metric-chart", {
|
|||||||
return {
|
return {
|
||||||
chart: this.vChart,
|
chart: this.vChart,
|
||||||
stats: stats,
|
stats: stats,
|
||||||
|
item: this.vItem,
|
||||||
width: widthPercent + "%",
|
width: widthPercent + "%",
|
||||||
chartId: "metric-chart-" + this.vChart.id
|
chartId: "metric-chart-" + this.vChart.id,
|
||||||
|
valueTypeName: (this.vItem != null && this.vItem.valueTypeName != null && this.vItem.valueTypeName.length > 0) ? this.vItem.valueTypeName : ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -97,7 +99,8 @@ Vue.component("metric-chart", {
|
|||||||
name: name,
|
name: name,
|
||||||
type: "pie",
|
type: "pie",
|
||||||
data: values,
|
data: values,
|
||||||
areaStyle: {}
|
areaStyle: {},
|
||||||
|
color: ["#9DD3E8", "#B2DB9E", "#F39494", "#FBD88A", "#879BD7"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
@@ -111,7 +114,7 @@ Vue.component("metric-chart", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
let axis = {unit: "", divider: 1}
|
let axis = {unit: "", divider: 1}
|
||||||
switch (this.vValueType) {
|
switch (this.item.valueType) {
|
||||||
case "count":
|
case "count":
|
||||||
axis = teaweb.countAxis(values, function (v) {
|
axis = teaweb.countAxis(values, function (v) {
|
||||||
return v
|
return v
|
||||||
@@ -177,7 +180,7 @@ Vue.component("metric-chart", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
let axis = {unit: "", divider: 1}
|
let axis = {unit: "", divider: 1}
|
||||||
switch (this.vValueType) {
|
switch (this.item.valueType) {
|
||||||
case "count":
|
case "count":
|
||||||
axis = teaweb.countAxis(values, function (v) {
|
axis = teaweb.countAxis(values, function (v) {
|
||||||
return v
|
return v
|
||||||
@@ -238,7 +241,7 @@ Vue.component("metric-chart", {
|
|||||||
return v.value
|
return v.value
|
||||||
})
|
})
|
||||||
let axis = {unit: "", divider: 1}
|
let axis = {unit: "", divider: 1}
|
||||||
switch (this.vValueType) {
|
switch (this.item.valueType) {
|
||||||
case "count":
|
case "count":
|
||||||
axis = teaweb.countAxis(values, function (v) {
|
axis = teaweb.countAxis(values, function (v) {
|
||||||
return v
|
return v
|
||||||
@@ -328,7 +331,7 @@ Vue.component("metric-chart", {
|
|||||||
if (time == null) {
|
if (time == null) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
switch (this.vPeriodUnit) {
|
switch (this.item.periodUnit) {
|
||||||
case "month":
|
case "month":
|
||||||
return time.substring(0, 4) + "-" + time.substring(4, 6)
|
return time.substring(0, 4) + "-" + time.substring(4, 6)
|
||||||
case "week":
|
case "week":
|
||||||
@@ -344,7 +347,7 @@ Vue.component("metric-chart", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
template: `<div style="float: left" :style="{'width': width}">
|
template: `<div style="float: left" :style="{'width': width}">
|
||||||
<h4>{{chart.name}} <span>(指标)</span></h4>
|
<h4>{{chart.name}} <span>({{valueTypeName}})</span></h4>
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
<div style="height: 20em; padding-bottom: 1em; " :id="chartId" :class="{'scroll-box': chart.type == 'table'}"></div>
|
<div style="height: 20em; padding-bottom: 1em; " :id="chartId" :class="{'scroll-box': chart.type == 'table'}"></div>
|
||||||
</div>`
|
</div>`
|
||||||
|
|||||||
@@ -71,5 +71,10 @@
|
|||||||
<!-- 指标 -->
|
<!-- 指标 -->
|
||||||
<div class="ui divider" v-if="metricCharts.length > 0"></div>
|
<div class="ui divider" v-if="metricCharts.length > 0"></div>
|
||||||
<metric-board>
|
<metric-board>
|
||||||
<metric-chart v-for="chart in metricCharts" :key="chart.id" :v-chart="chart.chart" :v-stats="chart.stats" :v-period="chart.item.period" :v-period-unit="chart.item.periodUnit" :v-value-type="chart.item.valueType"></metric-chart>
|
<metric-chart v-for="chart in metricCharts"
|
||||||
|
:key="chart.id"
|
||||||
|
:v-chart="chart.chart"
|
||||||
|
:v-stats="chart.stats"
|
||||||
|
:v-item="chart.item">
|
||||||
|
</metric-chart>
|
||||||
</metric-board>
|
</metric-board>
|
||||||
@@ -110,5 +110,10 @@
|
|||||||
<!-- 指标 -->
|
<!-- 指标 -->
|
||||||
<div class="ui divider" v-if="metricCharts.length > 0"></div>
|
<div class="ui divider" v-if="metricCharts.length > 0"></div>
|
||||||
<metric-board>
|
<metric-board>
|
||||||
<metric-chart v-for="chart in metricCharts" :key="chart.id" :v-chart="chart.chart" :v-stats="chart.stats" :v-period="chart.item.period" :v-period-unit="chart.item.periodUnit" :v-value-type="chart.item.valueType"></metric-chart>
|
<metric-chart v-for="chart in metricCharts"
|
||||||
|
:key="chart.id"
|
||||||
|
:v-chart="chart.chart"
|
||||||
|
:v-stats="chart.stats"
|
||||||
|
:v-item="chart.item">
|
||||||
|
</metric-chart>
|
||||||
</metric-board>
|
</metric-board>
|
||||||
@@ -96,3 +96,14 @@
|
|||||||
<!-- 节点排行 -->
|
<!-- 节点排行 -->
|
||||||
<h4>节点访问排行 <span>(24小时)</span></h4>
|
<h4>节点访问排行 <span>(24小时)</span></h4>
|
||||||
<div class="chart-box" id="top-nodes-chart"></div>
|
<div class="chart-box" id="top-nodes-chart"></div>
|
||||||
|
|
||||||
|
<!-- 指标 -->
|
||||||
|
<div class="ui divider" v-if="metricCharts.length > 0"></div>
|
||||||
|
<metric-board>
|
||||||
|
<metric-chart v-for="chart in metricCharts"
|
||||||
|
:key="chart.id"
|
||||||
|
:v-chart="chart.chart"
|
||||||
|
:v-stats="chart.stats"
|
||||||
|
:v-item="chart.item">
|
||||||
|
</metric-chart>
|
||||||
|
</metric-board>
|
||||||
@@ -56,3 +56,14 @@
|
|||||||
|
|
||||||
<!-- 按日统计 -->
|
<!-- 按日统计 -->
|
||||||
<div class="chart-box" id="daily-traffic-chart-box" v-show="trafficTab == 'daily'"></div>
|
<div class="chart-box" id="daily-traffic-chart-box" v-show="trafficTab == 'daily'"></div>
|
||||||
|
|
||||||
|
<!-- 指标 -->
|
||||||
|
<div class="ui divider" v-if="metricCharts.length > 0"></div>
|
||||||
|
<metric-board>
|
||||||
|
<metric-chart v-for="chart in metricCharts"
|
||||||
|
:key="chart.id"
|
||||||
|
:v-chart="chart.chart"
|
||||||
|
:v-stats="chart.stats"
|
||||||
|
:v-item="chart.item">
|
||||||
|
</metric-chart>
|
||||||
|
</metric-board>
|
||||||
5
web/views/@default/servers/metrics/charts/chart.css
Normal file
5
web/views/@default/servers/metrics/charts/chart.css
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
h4 span {
|
||||||
|
font-size: 0.8em;
|
||||||
|
color: grey;
|
||||||
|
}
|
||||||
|
/*# sourceMappingURL=chart.css.map */
|
||||||
1
web/views/@default/servers/metrics/charts/chart.css.map
Normal file
1
web/views/@default/servers/metrics/charts/chart.css.map
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["chart.less"],"names":[],"mappings":"AAAA,EACC;EACC,gBAAA;EACA,WAAA","file":"chart.css"}
|
||||||
@@ -41,5 +41,5 @@
|
|||||||
<h4>图表示例</h4>
|
<h4>图表示例</h4>
|
||||||
<p class="comment"><span class="red">图中数据均为测试数据。</span></p>
|
<p class="comment"><span class="red">图中数据均为测试数据。</span></p>
|
||||||
<metric-board>
|
<metric-board>
|
||||||
<metric-chart :v-chart="chart" :v-stats="testingStats" :v-period-unit="item.periodUnit"></metric-chart>
|
<metric-chart :v-chart="chart" :v-stats="testingStats" :v-item="item"></metric-chart>
|
||||||
</metric-board>
|
</metric-board>
|
||||||
6
web/views/@default/servers/metrics/charts/chart.less
Normal file
6
web/views/@default/servers/metrics/charts/chart.less
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
h4 {
|
||||||
|
span {
|
||||||
|
font-size: 0.8em;
|
||||||
|
color: grey;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,5 +41,10 @@
|
|||||||
<!-- 指标 -->
|
<!-- 指标 -->
|
||||||
<div class="ui divider" v-if="metricCharts.length > 0"></div>
|
<div class="ui divider" v-if="metricCharts.length > 0"></div>
|
||||||
<metric-board>
|
<metric-board>
|
||||||
<metric-chart v-for="chart in metricCharts" :key="chart.id" :v-chart="chart.chart" :v-stats="chart.stats" :v-period="chart.item.period" :v-period-unit="chart.item.periodUnit" :v-value-type="chart.item.valueType"></metric-chart>
|
<metric-chart v-for="chart in metricCharts"
|
||||||
|
:key="chart.id"
|
||||||
|
:v-chart="chart.chart"
|
||||||
|
:v-stats="chart.stats"
|
||||||
|
:v-item="chart.item">
|
||||||
|
</metric-chart>
|
||||||
</metric-board>
|
</metric-board>
|
||||||
Reference in New Issue
Block a user