调整数据内容,显示相关
This commit is contained in:
@@ -284,6 +284,8 @@ class StatsDBOperator(BaseDBOperator):
|
|||||||
sql = """
|
sql = """
|
||||||
SELECT user_id,
|
SELECT user_id,
|
||||||
SUM(total_calls) as total_calls,
|
SUM(total_calls) as total_calls,
|
||||||
|
SUM(success_calls) as success_calls,
|
||||||
|
SUM(failed_calls) as failed_calls,
|
||||||
COUNT(DISTINCT plugin_name) as used_plugins
|
COUNT(DISTINCT plugin_name) as used_plugins
|
||||||
FROM t_user_stats
|
FROM t_user_stats
|
||||||
WHERE last_used_at >= DATE_SUB(CURDATE(), INTERVAL %s DAY)
|
WHERE last_used_at >= DATE_SUB(CURDATE(), INTERVAL %s DAY)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<el-table-column prop="total_calls" label="调用次数" sortable></el-table-column>
|
<el-table-column prop="total_calls" label="调用次数" sortable></el-table-column>
|
||||||
<el-table-column prop="unique_users" label="唯一用户数" sortable></el-table-column>
|
<el-table-column prop="unique_users" label="唯一用户数" sortable></el-table-column>
|
||||||
<el-table-column prop="success_calls" label="成功次数" sortable></el-table-column>
|
<el-table-column prop="success_calls" label="成功次数" sortable></el-table-column>
|
||||||
<el-table-column prop="error_calls" label="失败次数" sortable></el-table-column>
|
<el-table-column prop="failed_calls" label="失败次数" sortable></el-table-column>
|
||||||
<el-table-column label="成功率" sortable>
|
<el-table-column label="成功率" sortable>
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
{% raw %} {{ (scope.row.success_calls / scope.row.total_calls * 100).toFixed(2) }}{% endraw %}%
|
{% raw %} {{ (scope.row.success_calls / scope.row.total_calls * 100).toFixed(2) }}{% endraw %}%
|
||||||
|
|||||||
@@ -13,17 +13,29 @@
|
|||||||
</div>
|
</div>
|
||||||
<el-table {% raw %}:data="pluginStats"{% endraw %} style="width: 100%" border>
|
<el-table {% raw %}:data="pluginStats"{% endraw %} style="width: 100%" border>
|
||||||
<el-table-column prop="plugin_name" label="插件名称"></el-table-column>
|
<el-table-column prop="plugin_name" label="插件名称"></el-table-column>
|
||||||
<el-table-column prop="total_calls" label="调用次数" sortable></el-table-column>
|
<el-table-column prop="total_calls" label="调用次数" sortable>
|
||||||
<el-table-column prop="success_calls" label="成功次数" sortable></el-table-column>
|
<template slot-scope="scope">
|
||||||
<el-table-column prop="error_calls" label="失败次数" sortable></el-table-column>
|
{{ parseInt(scope.row.total_calls) || 0 }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column prop="success_calls" label="成功次数" sortable>
|
||||||
|
<template slot-scope="scope">
|
||||||
|
{{ parseInt(scope.row.success_calls) || 0 }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column prop="failed_calls" label="失败次数" sortable>
|
||||||
|
<template slot-scope="scope">
|
||||||
|
{{ parseInt(scope.row.failed_calls) || 0 }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column label="成功率" sortable>
|
<el-table-column label="成功率" sortable>
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
{% raw %}{{ (scope.row.success_calls / scope.row.total_calls * 100).toFixed(2) }}{% endraw %}%
|
{% raw %}{{ parseInt(scope.row.total_calls) > 0 ? ((parseInt(scope.row.success_calls) / parseInt(scope.row.total_calls)) * 100).toFixed(2) : '100.00' }}{% endraw %}%
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="平均响应时间" sortable>
|
<el-table-column label="平均响应时间" sortable>
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
{% raw %}{{ scope.row.avg_response_time.toFixed(2) }}{% endraw %}ms
|
{% raw %}{{ (scope.row.avg_process_time || 0).toFixed(2) }}{% endraw %}ms
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作">
|
<el-table-column label="操作">
|
||||||
@@ -103,27 +115,52 @@
|
|||||||
const ctx = document.getElementById('pluginTrendChart').getContext('2d');
|
const ctx = document.getElementById('pluginTrendChart').getContext('2d');
|
||||||
|
|
||||||
// 销毁旧图表
|
// 销毁旧图表
|
||||||
if (this.charts.pluginTrendChart) {
|
if (this.charts && this.charts.pluginTrendChart) {
|
||||||
this.charts.pluginTrendChart.destroy();
|
this.charts.pluginTrendChart.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 确保charts对象存在
|
||||||
|
if (!this.charts) {
|
||||||
|
this.charts = {};
|
||||||
|
}
|
||||||
|
|
||||||
// 准备数据
|
// 准备数据
|
||||||
const labels = trendData.map(item => item.stat_date);
|
const labels = trendData.map(item => item.date || item.stat_date);
|
||||||
const data = trendData.map(item => item.total_calls);
|
const totalData = trendData.map(item => parseInt(item.total_calls) || 0);
|
||||||
|
const successData = trendData.map(item => parseInt(item.success_calls) || 0);
|
||||||
|
const failedData = trendData.map(item => parseInt(item.failed_calls) || 0);
|
||||||
|
|
||||||
// 创建新图表
|
// 创建新图表
|
||||||
this.charts.pluginTrendChart = new Chart(ctx, {
|
this.charts.pluginTrendChart = new Chart(ctx, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
labels: labels,
|
labels: labels,
|
||||||
datasets: [{
|
datasets: [
|
||||||
label: `${pluginName} 调用次数`,
|
{
|
||||||
data: data,
|
label: `${pluginName} 总调用`,
|
||||||
fill: false,
|
data: totalData,
|
||||||
backgroundColor: 'rgba(153, 102, 255, 0.6)',
|
fill: false,
|
||||||
borderColor: 'rgba(153, 102, 255, 1)',
|
backgroundColor: 'rgba(54, 162, 235, 0.6)',
|
||||||
tension: 0.1
|
borderColor: 'rgba(54, 162, 235, 1)',
|
||||||
}]
|
tension: 0.1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: `${pluginName} 成功调用`,
|
||||||
|
data: successData,
|
||||||
|
fill: false,
|
||||||
|
backgroundColor: 'rgba(75, 192, 192, 0.6)',
|
||||||
|
borderColor: 'rgba(75, 192, 192, 1)',
|
||||||
|
tension: 0.1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: `${pluginName} 失败调用`,
|
||||||
|
data: failedData,
|
||||||
|
fill: false,
|
||||||
|
backgroundColor: 'rgba(255, 99, 132, 0.6)',
|
||||||
|
borderColor: 'rgba(255, 99, 132, 1)',
|
||||||
|
tension: 0.1
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
responsive: true,
|
responsive: true,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<el-table-column prop="user_id" label="用户ID"></el-table-column>
|
<el-table-column prop="user_id" label="用户ID"></el-table-column>
|
||||||
<el-table-column prop="total_calls" label="调用次数" sortable></el-table-column>
|
<el-table-column prop="total_calls" label="调用次数" sortable></el-table-column>
|
||||||
<el-table-column prop="success_calls" label="成功次数" sortable></el-table-column>
|
<el-table-column prop="success_calls" label="成功次数" sortable></el-table-column>
|
||||||
<el-table-column prop="error_calls" label="失败次数" sortable></el-table-column>
|
<el-table-column prop="failed_calls" label="失败次数" sortable></el-table-column>
|
||||||
<el-table-column label="成功率" sortable>
|
<el-table-column label="成功率" sortable>
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
{% raw %}{{ (scope.row.success_calls / scope.row.total_calls * 100).toFixed(2) }}{% endraw %}%
|
{% raw %}{{ (scope.row.success_calls / scope.row.total_calls * 100).toFixed(2) }}{% endraw %}%
|
||||||
|
|||||||
Reference in New Issue
Block a user