diff --git a/db/stats_db.py b/db/stats_db.py
index 9d17703..7e049d6 100644
--- a/db/stats_db.py
+++ b/db/stats_db.py
@@ -284,6 +284,8 @@ class StatsDBOperator(BaseDBOperator):
sql = """
SELECT user_id,
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
FROM t_user_stats
WHERE last_used_at >= DATE_SUB(CURDATE(), INTERVAL %s DAY)
diff --git a/plugins/stats_dashboard/templates/groups.html b/plugins/stats_dashboard/templates/groups.html
index 8cc072a..e2179a5 100644
--- a/plugins/stats_dashboard/templates/groups.html
+++ b/plugins/stats_dashboard/templates/groups.html
@@ -16,7 +16,7 @@
-
+
{% raw %} {{ (scope.row.success_calls / scope.row.total_calls * 100).toFixed(2) }}{% endraw %}%
diff --git a/plugins/stats_dashboard/templates/plugins.html b/plugins/stats_dashboard/templates/plugins.html
index 72ba628..bb9b497 100644
--- a/plugins/stats_dashboard/templates/plugins.html
+++ b/plugins/stats_dashboard/templates/plugins.html
@@ -13,17 +13,29 @@
-
-
-
+
+
+ {{ parseInt(scope.row.total_calls) || 0 }}
+
+
+
+
+ {{ parseInt(scope.row.success_calls) || 0 }}
+
+
+
+
+ {{ parseInt(scope.row.failed_calls) || 0 }}
+
+
- {% 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 %}%
- {% raw %}{{ scope.row.avg_response_time.toFixed(2) }}{% endraw %}ms
+ {% raw %}{{ (scope.row.avg_process_time || 0).toFixed(2) }}{% endraw %}ms
@@ -103,27 +115,52 @@
const ctx = document.getElementById('pluginTrendChart').getContext('2d');
// 销毁旧图表
- if (this.charts.pluginTrendChart) {
+ if (this.charts && this.charts.pluginTrendChart) {
this.charts.pluginTrendChart.destroy();
}
+ // 确保charts对象存在
+ if (!this.charts) {
+ this.charts = {};
+ }
+
// 准备数据
- const labels = trendData.map(item => item.stat_date);
- const data = trendData.map(item => item.total_calls);
+ const labels = trendData.map(item => item.date || item.stat_date);
+ 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, {
type: 'line',
data: {
labels: labels,
- datasets: [{
- label: `${pluginName} 调用次数`,
- data: data,
- fill: false,
- backgroundColor: 'rgba(153, 102, 255, 0.6)',
- borderColor: 'rgba(153, 102, 255, 1)',
- tension: 0.1
- }]
+ datasets: [
+ {
+ label: `${pluginName} 总调用`,
+ data: totalData,
+ fill: false,
+ backgroundColor: 'rgba(54, 162, 235, 0.6)',
+ 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: {
responsive: true,
diff --git a/plugins/stats_dashboard/templates/users.html b/plugins/stats_dashboard/templates/users.html
index 53db531..9b9d4dc 100644
--- a/plugins/stats_dashboard/templates/users.html
+++ b/plugins/stats_dashboard/templates/users.html
@@ -15,7 +15,7 @@
-
+
{% raw %}{{ (scope.row.success_calls / scope.row.total_calls * 100).toFixed(2) }}{% endraw %}%