From 16f99735025e476092f9324952faaa37b88cd7cb Mon Sep 17 00:00:00 2001 From: Daniel Ding Date: Mon, 20 Jan 2025 10:47:29 +0800 Subject: [PATCH] fea: ceci: show total bytes. --- pkg/proxy/http.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/proxy/http.go b/pkg/proxy/http.go index 7b0014d..4726f8b 100755 --- a/pkg/proxy/http.go +++ b/pkg/proxy/http.go @@ -380,8 +380,10 @@ func (t *HttpProxy) doRecord(r *http.Request, bytes int64) { record, ok := t.requests[r.URL.Host] if !ok { - record = &HttpRecord{} - t.requests[r.URL.Host] = record + record = &HttpRecord{ + Domain: r.URL.Host, + } + t.requests[record.Domain] = record } record.Update(bytes) } @@ -505,6 +507,9 @@ var httpTmpl = map[string]string{ Total:{{ .Total }} + + Bytes:{{ .Bytes }} + Configuration:display @@ -545,19 +550,15 @@ func (t *HttpProxy) GetStats(w http.ResponseWriter, r *http.Request) { data := &struct { StartAt string Total int + Bytes int64 Requests []*HttpRecord }{ Total: len(t.requests), StartAt: t.startat.Local().String(), } - for name, record := range t.requests { - data.Requests = append(data.Requests, &HttpRecord{ - Domain: name, - Count: record.Count, - LastAt: record.LastAt, - CreateAt: record.CreateAt, - Bytes: record.Bytes, - }) + for _, record := range t.requests { + data.Requests = append(data.Requests, record) + data.Bytes += record.Bytes } t.lock.RUnlock()