wood chen 040b01f4a4 feat(metrics): integrate comprehensive metrics tracking across handlers
- Enhanced metrics collection in ProxyHandler, MirrorProxyHandler, and FixedPathProxyMiddleware.
- Introduced a centralized metrics collector to streamline request tracking and statistics reporting.
- Updated MetricsHandler to utilize new metrics structure, including total bytes, requests per second, and error rates.
- Improved documentation in readme.md to reflect new features and usage instructions.
- Added support for metrics monitoring at `/metrics/ui` for better visibility into proxy performance.
2024-11-30 22:26:11 +08:00

34 lines
712 B
Go

package metrics
import (
"sync/atomic"
"time"
)
// RequestLog 记录单个请求的信息
type RequestLog struct {
Time time.Time
Path string
Status int
Latency time.Duration
BytesSent int64
ClientIP string
}
// PathStats 记录路径统计信息
type PathStats struct {
requests atomic.Int64
errors atomic.Int64
bytes atomic.Int64
latencySum atomic.Int64
}
// PathMetrics 用于API返回的路径统计信息
type PathMetrics struct {
Path string `json:"path"`
RequestCount int64 `json:"request_count"`
ErrorCount int64 `json:"error_count"`
AvgLatency string `json:"avg_latency"`
BytesTransferred int64 `json:"bytes_transferred"`
}