mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 16:41:54 +08:00
fix(metrics): update SQL query to use localtime for accurate metrics retrieval
- Modified the SQL query in GetRecentMetrics to utilize the 'localtime' modifier for timestamp handling, ensuring that metrics are retrieved based on the local time zone. - This change enhances the accuracy of the metrics data by aligning the time calculations with local time, improving the reliability of performance monitoring.
This commit is contained in:
parent
60b115438a
commit
59358cbe8a
@ -240,16 +240,17 @@ func (db *MetricsDB) GetRecentMetrics(hours int) ([]HistoricalMetrics, error) {
|
|||||||
interval = "%Y-%m-%d 00:00:00"
|
interval = "%Y-%m-%d 00:00:00"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修改查询,使用 localtime 修饰符
|
||||||
rows, err := db.DB.Query(`
|
rows, err := db.DB.Query(`
|
||||||
WITH grouped_metrics AS (
|
WITH grouped_metrics AS (
|
||||||
SELECT
|
SELECT
|
||||||
strftime(?1, timestamp) as group_time,
|
strftime(?1, timestamp, 'localtime') as group_time,
|
||||||
SUM(total_requests) as total_requests,
|
SUM(total_requests) as total_requests,
|
||||||
SUM(total_errors) as total_errors,
|
SUM(total_errors) as total_errors,
|
||||||
SUM(total_bytes) as total_bytes,
|
SUM(total_bytes) as total_bytes,
|
||||||
CAST(AVG(CAST(avg_latency AS FLOAT)) AS FLOAT) as avg_latency
|
CAST(AVG(CAST(avg_latency AS FLOAT)) AS FLOAT) as avg_latency
|
||||||
FROM metrics_history
|
FROM metrics_history
|
||||||
WHERE timestamp >= datetime('now', '-' || ?2 || ' hours')
|
WHERE timestamp >= datetime('now', '-' || ?2 || ' hours', 'localtime')
|
||||||
GROUP BY group_time
|
GROUP BY group_time
|
||||||
ORDER BY group_time DESC
|
ORDER BY group_time DESC
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user