mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 15:26:36 +08:00
feat(dashboard): 首页请求趋势拆分状态码并合并容量到业务流量
- 24 小时请求趋势拆分展示请求总量与 200/400/500 状态码请求量,独占一行; 时间桶聚合新增 status_200/400/500_count(CH countIf、PG FILTER), 请求趋势改为基于原始桶聚合(小时 rollup 无状态码口径) - 首页移除宿主机磁盘指标,容量趋势(CPU/内存)并入业务流量卡片展示 - 压缩协议 traffic_24h 扩展为 7 元组,前端归一化同步更新
This commit is contained in:
@@ -46,6 +46,9 @@ SELECT
|
||||
countIf(status_code < 400) AS success_count,
|
||||
countIf(status_code >= 400 AND status_code < 500) AS client_error_count,
|
||||
countIf(status_code >= 500) AS server_error_count,
|
||||
countIf(status_code >= 200 AND status_code < 300) AS status_2xx_count,
|
||||
countIf(status_code >= 400 AND status_code < 500) AS status_4xx_count,
|
||||
countIf(status_code >= 500) AS status_5xx_count,
|
||||
uniqExactIf(remote_addr, remote_addr != '') AS unique_ip_count,
|
||||
uniqExactIf(host, host != '') AS unique_host_count,
|
||||
sum(bytes_sent) AS bytes_sent,
|
||||
@@ -70,10 +73,10 @@ ORDER BY %s`, bucketExpr, tableName, clause, nodeAccessLogBucketOrderClause(filt
|
||||
var result []NodeAccessLogBucketAggregate
|
||||
for rows.Next() {
|
||||
var (
|
||||
bucketEpoch int64
|
||||
requestCount, successCount, clientErrorCount, serverErrorCount, uniqueIPCount, uniqueHostCount, bytesSent, requestLength uint64
|
||||
bucketEpoch int64
|
||||
requestCount, successCount, clientErrorCount, serverErrorCount, status2xxCount, status4xxCount, status5xxCount, uniqueIPCount, uniqueHostCount, bytesSent, requestLength uint64
|
||||
)
|
||||
if err := rows.Scan(&bucketEpoch, &requestCount, &successCount, &clientErrorCount, &serverErrorCount, &uniqueIPCount, &uniqueHostCount, &bytesSent, &requestLength); err != nil {
|
||||
if err := rows.Scan(&bucketEpoch, &requestCount, &successCount, &clientErrorCount, &serverErrorCount, &status2xxCount, &status4xxCount, &status5xxCount, &uniqueIPCount, &uniqueHostCount, &bytesSent, &requestLength); err != nil {
|
||||
return nil, fmt.Errorf("scan bucket aggregate row: %w", err)
|
||||
}
|
||||
result = append(result, NodeAccessLogBucketAggregate{
|
||||
@@ -82,6 +85,9 @@ ORDER BY %s`, bucketExpr, tableName, clause, nodeAccessLogBucketOrderClause(filt
|
||||
SuccessCount: safeInt64Count(successCount),
|
||||
ClientErrorCount: safeInt64Count(clientErrorCount),
|
||||
ServerErrorCount: safeInt64Count(serverErrorCount),
|
||||
Status2xxCount: safeInt64Count(status2xxCount),
|
||||
Status4xxCount: safeInt64Count(status4xxCount),
|
||||
Status5xxCount: safeInt64Count(status5xxCount),
|
||||
UniqueIPCount: safeInt64Count(uniqueIPCount),
|
||||
UniqueHostCount: safeInt64Count(uniqueHostCount),
|
||||
BytesSent: safeInt64Count(bytesSent),
|
||||
|
||||
@@ -307,6 +307,9 @@ func (s *gormLogStore) BucketAggregates(ctx context.Context, query model.OpenFla
|
||||
SuccessCount int64
|
||||
ClientErrorCount int64
|
||||
ServerErrorCount int64
|
||||
Status2xxCount int64 `gorm:"column:status_2xx_count"`
|
||||
Status4xxCount int64 `gorm:"column:status_4xx_count"`
|
||||
Status5xxCount int64 `gorm:"column:status_5xx_count"`
|
||||
UniqueIPCount int64
|
||||
UniqueHostCount int64
|
||||
BytesSent int64
|
||||
@@ -322,6 +325,9 @@ func (s *gormLogStore) BucketAggregates(ctx context.Context, query model.OpenFla
|
||||
"COUNT(*) FILTER (WHERE status_code < 400) AS success_count, " +
|
||||
"COUNT(*) FILTER (WHERE status_code >= 400 AND status_code < 500) AS client_error_count, " +
|
||||
"COUNT(*) FILTER (WHERE status_code >= 500) AS server_error_count, " +
|
||||
"COUNT(*) FILTER (WHERE status_code >= 200 AND status_code < 300) AS status_2xx_count, " +
|
||||
"COUNT(*) FILTER (WHERE status_code >= 400 AND status_code < 500) AS status_4xx_count, " +
|
||||
"COUNT(*) FILTER (WHERE status_code >= 500) AS status_5xx_count, " +
|
||||
distinctNonEmptyCountSQL(s.db, "remote_addr") + " AS unique_ip_count, " +
|
||||
distinctNonEmptyCountSQL(s.db, "host") + " AS unique_host_count, " +
|
||||
"COALESCE(SUM(bytes_sent),0) AS bytes_sent, " +
|
||||
@@ -338,6 +344,9 @@ func (s *gormLogStore) BucketAggregates(ctx context.Context, query model.OpenFla
|
||||
SuccessCount: r.SuccessCount,
|
||||
ClientErrorCount: r.ClientErrorCount,
|
||||
ServerErrorCount: r.ServerErrorCount,
|
||||
Status2xxCount: r.Status2xxCount,
|
||||
Status4xxCount: r.Status4xxCount,
|
||||
Status5xxCount: r.Status5xxCount,
|
||||
UniqueIPCount: r.UniqueIPCount,
|
||||
UniqueHostCount: r.UniqueHostCount,
|
||||
BytesSent: r.BytesSent,
|
||||
|
||||
@@ -709,9 +709,9 @@ func TestGormBucketAggregatesFullFieldSet(t *testing.T) {
|
||||
rows := []analyticsmodel.NodeAccessLog{
|
||||
{ID: 1, NodeID: "n1", LoggedAt: base, RemoteAddr: "1.1.1.1", Host: "a.example.com", StatusCode: 200, BytesSent: 100, RequestLength: 10},
|
||||
{ID: 2, NodeID: "n1", LoggedAt: base.Add(time.Minute), RemoteAddr: "1.1.1.1", Host: "a.example.com", StatusCode: 301, BytesSent: 200, RequestLength: 20},
|
||||
{ID: 3, NodeID: "n1", LoggedAt: base.Add(2 * time.Minute), RemoteAddr: "2.2.2.2", Host: "b.example.com", StatusCode: 404, BytesSent: 300, RequestLength: 30},
|
||||
{ID: 3, NodeID: "n1", LoggedAt: base.Add(2 * time.Minute), RemoteAddr: "2.2.2.2", Host: "b.example.com", StatusCode: 400, BytesSent: 300, RequestLength: 30},
|
||||
{ID: 4, NodeID: "n1", LoggedAt: base.Add(3 * time.Minute), RemoteAddr: "", Host: "b.example.com", StatusCode: 500, BytesSent: 400, RequestLength: 40},
|
||||
{ID: 5, NodeID: "n1", LoggedAt: base.Add(4 * time.Minute), RemoteAddr: "3.3.3.3", Host: "c.example.com", StatusCode: 502, BytesSent: 500, RequestLength: 50},
|
||||
{ID: 5, NodeID: "n1", LoggedAt: base.Add(4 * time.Minute), RemoteAddr: "3.3.3.3", Host: "c.example.com", StatusCode: 500, BytesSent: 500, RequestLength: 50},
|
||||
{ID: 6, NodeID: "n2", LoggedAt: base.Add(time.Hour), RemoteAddr: "9.9.9.9", Host: "d.example.com", StatusCode: 200, BytesSent: 999, RequestLength: 99},
|
||||
}
|
||||
if err := s.BatchInsertNodeAccessLogs(ctx, rows); err != nil {
|
||||
@@ -741,6 +741,10 @@ func TestGormBucketAggregatesFullFieldSet(t *testing.T) {
|
||||
if b.ServerErrorCount != 2 {
|
||||
t.Errorf("server_error_count = %d, want 2", b.ServerErrorCount)
|
||||
}
|
||||
if b.Status2xxCount != 1 || b.Status4xxCount != 1 || b.Status5xxCount != 2 {
|
||||
t.Errorf("status class counts = 2xx:%d 4xx:%d 5xx:%d, want 1/1/2 (200/301/400/500/500)",
|
||||
b.Status2xxCount, b.Status4xxCount, b.Status5xxCount)
|
||||
}
|
||||
if b.UniqueIPCount != 3 {
|
||||
t.Errorf("unique_ip_count = %d, want 3 (empty remote_addr excluded)", b.UniqueIPCount)
|
||||
}
|
||||
|
||||
@@ -258,6 +258,9 @@ func buildOpenFlareAccessLogBucketRows(ctx context.Context, query model.OpenFlar
|
||||
SuccessCount: partial.SuccessCount,
|
||||
ClientErrorCount: partial.ClientErrorCount,
|
||||
ServerErrorCount: partial.ServerErrorCount,
|
||||
Status2xxCount: partial.Status2xxCount,
|
||||
Status4xxCount: partial.Status4xxCount,
|
||||
Status5xxCount: partial.Status5xxCount,
|
||||
BytesSent: partial.BytesSent,
|
||||
RequestLength: partial.RequestLength,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user